LOGIN
Shrey Fadia
4
Collaborator
Instrumentation Engineering student -- Hardware and coding Expert (Project Leader)
 · AhmedabadIndia
Share
Report
Get Link
TASK
Open
Reward › Contribution Review

Obstacle avoidance using Ultrasonic sensor

People Needed: 3-4

Estimated Time Commitment: 30 minutes

Tools Being Used: Google Hangouts, Collaborizm Discussion, Collaborizm Team Chat

Start Date: Aiming for Thursday at 11 EST. 5.4.17.

Reward: Collaborizm Resume Review written for each user participating

Users Participating: Shrey Fadia,

I need to have 2 ultrasonic sensors attached to the WheelChair. One on the front side of the chair and another just downside it at some angle. The other sensor is used to detect the slope or staircase so that the Wheelchair stops automatically once it detects it. The one ultrasonic sensor is already in use along with gesture mechanism. Let me know if anyone can do programming for multiple ultrasonic sensors in Arduino, which is 2 in our case.
This would be another milestone.
John Rodrigues Suraj Parasuram

Arduino
Robotics
Sensors
Arduino Uno
Arduino Mega
6 likes 
Like
Award Contribution
Load 12 previous comments
North eugene
6
Collaborator
Designer special solution && automation , Software engneering student , Robotics developer
Share
Report
Get Link
// type your code here

//redefining wheelchair program

#define trigPin 10
#define echoPin 13
#include <Servo.h>

Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0; // variable to store the servo position

// all variables should be global as there is a merge of many programs
// 1 sonar
// 2 servo
// 3.Motor driver
//
double duration, distance;
void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
myservo.attach(9);
}
// four divisions of 180 degrees converted into independent functions////////////////

void loop45() {for (pos = 5; pos <= 45; pos += 1) { myservo.write(pos);delay(15);Dloop();
if(pos>5 &&pos<45&& distance>50){ do this }
else if(pos>5 &&pos<45&& distance<50&& distance>20){ do this }
else if(pos>5 &&pos<45&& distance<20){ do this }
else{}
// in the above senerio the condition states that angle has to be 5 to 45 , and the distance if above 50 or below 50 or less tahn 20
// more conditions can be added
// goes the same for all

} // this function will measure one degree/loop and will read distanc to
//this distance and angle of the servo will determine // weather to shift right/left or keep going it will be functional till 0 to 45 degrees

void loop90() {for (pos = 45; pos <= 90; pos += 1) { myservo.write(pos);delay(15);Dloop();}// same as above from 45 to 90
void loop135() {for (pos = 0; pos <= 45; pos += 1) { myservo.write(pos);delay(15);Dloop();}// same as above from 90 to 135
void loop175() {for (pos = 0; pos <= 45; pos += 1) { myservo.write(pos);delay(15);Dloop();}//same as above from 135 to 175

// from here the servo will start back 175 to 0
void Negloop175(){for (pos = 175; pos >=135; pos -= 1) { myservo.write(pos);delay(15);Dloop(); }
void Negloop135(){for (pos = 135; pos >=90; pos -= 1) { myservo.write(pos);delay(15);Dloop(); }
void Negloop90(){for (pos = 90; pos >=45; pos -= 1) { myservo.write(pos);delay(15);Dloop(); }
void Negloop45(){for (pos = 45; pos >=5; pos -= 1) { myservo.write(pos);delay(15);Dloop(); }

// using this as a distance function of the sonnar but not the loop function
// this will be used to output distance at runtime while the sonar is traveling in angular motion
//""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
// start of sonar distance function//////////////////////////
/////////////////////////////////////////////////////////////
// wheel run functions
void rightturn(){}// motor function left wheels running //right wheels slow down
void left turn(){}//
void reverse{}
void front(){}
void aboutTurn(){}
// sonar distance function
void Dloop() {}

digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration / 2) * 0.0344;
Serial.print(“Distance = “);
Serial.print(distance);
Serial.println(” cm”);
delay(50);
}

}
///////////////////////////////////End of sonar distance function////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////

void loop()
{
//function call for running the wheelchair
loop45();
loop90();
loop135();
loop175();
void Negloop175()
void Negloop135()
void Negloop90()
void Negloop45()

}

Like
2 likes 
Award Contribution
North eugene
6
Collaborator
Designer special solution && automation , Software engneering student , Robotics developer
Share
Report
Get Link

test this out there may be a few syntax errors ,
But the last obsticle avoiding self nav little bot I made was with these codes.
How ever I will send you multi sensor codes but without defined interupts
As i define my own interrupts with sequential algorithm .
I dont know what functions are you using for the mnoters so I have wr9itten DO THIS
you have to use the functions you are using Or let me know which driver are you using.
You were talking about the motors.
Go to the car junkyard , ask for Wiper machine motors. they are 12 volt 20 amps and have a reduction gear box 21 : 1 or close. but the hobby moters will not carry a 70 kg person and while turning it will cause problems.
I will suggest have it on two original big wheels as it will be easy to handle two motor drives and piviot turningor round about will be very smooth
and the 4 wheel resistances will cause a power shortage or structural twist .
just a suggestion , to make things easy
Any help about the software design Or mechanical share it and Home build solution will be at your serviece

Like
1 like 
Award Contribution
Shrey Fadia
4
Collaborator
Instrumentation Engineering student -- Hardware and coding Expert (Project Leader)
 · AhmedabadIndia
Share
Report
Get Link

Thanks North Eugene Will try out this code and Check it.

Like
1 like 
Award Contribution
North eugene
6
Collaborator
Designer special solution && automation , Software engneering student , Robotics developer
Share
Report
Get Link
// type your code here
``` /*HC-SR04 Sensor
  https://www.dealextreme.com/p/hc-sr04-ultrasonic-sensor-distance-measuring-module-133696
 
  This sketch reads a HC-SR04 ultrasonic rangefinder and returns the
  distance to the closest object in range. To do this, it sends a pulse
  to the sensor to initiate a reading, then listens for a pulse 
  to return.  The length of the returning pulse is proportional to 
  the distance of the object from the sensor.
    
  The circuit:
 * VCC connection of the sensor attached to +5V
 * GND connection of the sensor attached to ground
 * TRIG connection of the sensor attached to digital pin 2
 * ECHO connection of the sensor attached to digital pin 4
  Original code for Ping))) example was created by David A. Mellis
  Adapted for HC-SR04 by Tautvidas Sipavicius
  This example code is in the public domain.

  This sketch has been altered to use more than One  ultrasound module, How ever it is not an elegant One as inturupts have not been used and two functions have been used
  all the credit of this code set is and belongs to dealextreme
  Modification By Ahmed [email protected]
  Incase any furthermodification is done In specific If interupts were used Or the array , please email your written codes on the adress as above.
  two sonars are used in complex devices , Please test the program rigriously In case it is for some security system Or a carry rover to avoid any damage to men Or machine
  I do not take any responsibility and Like from the origen claim no ownership of this program It belongs to the Origen dealExtreme
  dated May 17 2017
*/


const int trigPin = 2;
const int echoPin = 4;
const int trigPin1 = 6;
const int echoPin1 = 7;

//varable for ultrasound 1
long duration, inches, cm;
//variable for ultrasound 2
long duration1, inches1, cm1;

void setup() {
 // initialize serial communication:
 Serial.begin(9600);
}

void ultrasound1()
{
 // establish variables for duration of the ping, 
 // and the distance result in inches and centimeters:
 

 // The sensor is triggered by a HIGH pulse of 10 or more microseconds.
 // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
 pinMode(trigPin, OUTPUT);
 digitalWrite(trigPin, LOW);
 delayMicroseconds(2);
 digitalWrite(trigPin, HIGH);
 delayMicroseconds(10);
 digitalWrite(trigPin, LOW);

 // Read the signal from the sensor: a HIGH pulse whose
 // duration is the time (in microseconds) from the sending
 // of the ping to the reception of its echo off of an object.
 pinMode(echoPin, INPUT);
 duration = pulseIn(echoPin, HIGH);

 // convert the time into a distance
 inches = microsecondsToInches(duration);
 cm = microsecondsToCentimeters(duration);
 
 Serial.print(inches);
 Serial.print("in, ");
 Serial.print(cm);
 Serial.print("cm");
 Serial.println();
 
 delay(100);
}

long microsecondsToInches(long microseconds)
{
 // According to Parallax's datasheet for the PING))), there are
 // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
 // second).  This gives the distance travelled by the ping, outbound
 // and return, so we divide by 2 to get the distance of the obstacle.
 // See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
 return microseconds / 74 / 2;
}

long microsecondsToCentimeters(long microseconds)
{
 // The speed of sound is 340 m/s or 29 microseconds per centimeter.
 // The ping travels out and back, so to find the distance of the
 // object we take half of the distance travelled.
 return microseconds / 29 / 2;
}
void ultrasound2()
{
 // establish variables for duration of the ping, 
 // and the distance result in inches and centimeters:


 // The sensor is triggered by a HIGH pulse of 10 or more microseconds.
 // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
 pinMode(trigPin1, OUTPUT);
 digitalWrite(trigPin1, LOW);
 delayMicroseconds(2);
 digitalWrite(trigPin1, HIGH);
 delayMicroseconds(10);
 digitalWrite(trigPin1, LOW);

 // Read the signal from the sensor: a HIGH pulse whose
 // duration is the time (in microseconds) from the sending
 // of the ping to the reception of its echo off of an object.
 pinMode(echoPin1, INPUT);
 duration1 = pulseIn(echoPin1, HIGH);

 // convert the time into a distance
 inches1 = microsecondsToInches1(duration1);
 cm1 = microsecondsToCentimeters1(duration1);
 
 Serial.print(inches1);
 Serial.print("in, ");
 Serial.print(cm1);
 Serial.print("cm");
 Serial.println();
 
 delay(100);
}

long microsecondsToInches1(long microseconds1)
{
 // According to Parallax's datasheet for the PING))), there are
 // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
 // second).  This gives the distance travelled by the ping, outbound
 // and return, so we divide by 2 to get the distance of the obstacle.
 // See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
 return microseconds1 / 74 / 2;
}

long microsecondsToCentimeters1(long microseconds1)
{
 // The speed of sound is 340 m/s or 29 microseconds per centimeter.
 // The ping travels out and back, so to find the distance of the
 // object we take half of the distance travelled.
 return microseconds1 / 29 / 2;
}
void loop()
{
 ultrasound1();
 delay(20);
 ultrasound2();
 
}
Like
0 like 
Award Contribution
North eugene
6
Collaborator
Designer special solution && automation , Software engneering student , Robotics developer
Share
Report
Get Link

Code set for more than One Sensor module

Like
0 like 
Award Contribution
North eugene
6
Collaborator
Designer special solution && automation , Software engneering student , Robotics developer
Share
Report
Get Link

Please share your code set , that may be an elegant solution , It will be knowledgeable to know how codes can be written , how ever , as ardunio runs in a loop cycle , and each loop takes time according the delay set , while two sets are running the aggregate delay will show in real time. in that case
the delay has to be reduced efficiently On the end of each sensor code, so that the data remains
accurate and Shift from code 1 set to code 2 set has a very little delay

Like
0 like 
Award Contribution
APPLY
LEAVE A REPLY
DISCOVER
CHAT
ALERTS
DISCUSSIONS
FEED