please check whether the given code is correct so that I can make my obstacle avoiding robot using arduino duemilanove for my school project.
From,
BIJU class 7.
please check whether the given code is correct so that I can make my obstacle avoiding robot using arduino duemilanove for my school project.
From,
BIJU class 7.
this is the code and the error message.
this is what my robot looks like.
arduino code.txt (1.29 KB)
STOP CROSS-POSTING.
please check whether the given code is correct
The compiler already told you.
This compiles.
#include <Servo.h>
Servo myservo1;
Servo myservo2;
const int pingPin=2;
long duration, distanceCm=0;
long distanceFront=0;
void setup ()
{
myservo1.attach (9);
myservo2.attach (10);
}
void loop ()
{
pinMode(pingPin,OUTPUT);
digitalWrite(pingPin,LOW);
delayMicroseconds(2);
digitalWrite(pingPin,HIGH);
delayMicroseconds(5);
digitalWrite(pingPin,LOW);
pinMode(pingPin,INPUT);
duration=pulseIn(pingPin,HIGH);
//distanceInches=duration/73/2;
distanceCm=duration/28.6/23/2;
//Serial.print(distanceInches);
//Serial.print("in,");
//Serial.print(distanceCm);
//Serial.print("cm");
//Serial.println0;
delay (100);
distanceFront=distanceCm;
if(distanceFront>1){
if(distanceFront>10){
myservo1.write(0);
myservo2.write(180);
delay(100);
}
else{
myservo1.write(0);
myservo2.write(0);
delay(100);
}//else
}//if
}//loop
Please study it, and note the differences between it and your code.
If you have any more questions, post them HERE.
DO NOT START A NEW THREAD.