So I am working a arduino robot. I have a ping))) sensor and an arduino. I am trying to make code that will avoid objects without a servo because I don't have one. The robot is a tank kit. You can find it here: http://www.robotshop.com/dfrobotshop-rover-tracked-robot-basic-kit.html
Basically, the program that I am working on is going to find an object that is 50 cm away then the tank would turn to the right, read the sensor and set that value to integer ping1, then the tank would turn to the left of the object and read the sensor and set that value as integer ping2.
const int ping = 4;
int ping1
int ping2
void setup()
{
digitalWrite(ping, OUTPUT);
}
void loop()
{
long duration, inches, cm;
pinMode(ping,OUTPUT)
digitalWrite(ping, LOW); // Send low pulse
delayMicroseconds(2); // Wait for 2 microseconds
digitalWrite(ping, HIGH); // Send high pulse
delayMicroseconds(5); // Wait for 5 microseconds
digitalWrite(ping, LOW); // Holdoff
pinMode(ping, INPUT); // Switch signalpin to input
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);
//Compare Values
if (ping > 50)
{
int leftspeed = 255; //255 is maximum speed
int rightspeed = 255;
{
{
left (leftspeed,rightspeed);
//send out high/low signals
digitalWrite(ping1, LOW); // Send low pulse
delayMicroseconds(2); // Wait for 2 microseconds
digitalWrite(ping1, HIGH); // Send high pulse
delayMicroseconds(5); // Wait for 5 microseconds
digitalWrite(ping, LOW); // Holdof
pinMode(ping, INPUT); // Switch signalpin to input
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);
}
{
right (leftspeed,rightspeed);
right (leftspeed,rightspeed);
//send out high/low signals
digitalWrite(ping2, LOW); // Send low pulse
delayMicroseconds(2); // Wait for 2 microseconds
digitalWrite(ping2, HIGH); // Send high pulse
delayMicroseconds(5); // Wait for 5 microseconds
digitalWrite(ping, LOW); // Holdof
pinMode(ping, INPUT); // Switch signalpin to input
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);
}
if (ping1 > ping2)
{
right (leftspeed,rightspeed);
}
if (ping2 > ping1)
{
left (leftspeed,rightspeed);
}
}
}
}
I am looking at more posts/tutorials about ping sensors. Sorry, I guess I'm just confused by some of the basics.
Thank you for reading my post and any help, guidance or code will be greatly appreciated.