Arduino Uno Board Based project pof Lover Robot Code with Pin Digram and Details
Youtube Video for Demo
#define echoPin1 3
#define trigPin1 4
#define echoPin2 10
#define trigPin2 11
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
Servo servo5;
int amsl=5;
int amsr=6;
int amkl=7;
int amkr=8;
int head=9;
int aamsl;
int aamsr;
int aamkl;
int aamkr;
int ahead;
int Maximum=200;
int Minimum=0;
long duration1,distance1,duration2,distance2;
void setup()
{
Serial.begin(9600);
servo1.attach(amsl);
servo2.attach(amsr);
servo3.attach(amkl);
servo4.attach(amkr);
servo5.attach(head);
pinMode(trigPin1,OUTPUT);
pinMode(echoPin1,INPUT);
pinMode(trigPin2,OUTPUT);
pinMode(echoPin2,INPUT);
}
void loop()
{
digitalWrite(trigPin1,LOW);
digitalWrite(trigPin2,LOW);
delayMicroseconds(2);
digitalWrite(trigPin1,HIGH);
digitalWrite(trigPin2,HIGH);
delayMicroseconds(10);
digitalWrite(trigPin1,LOW);
digitalWrite(trigPin2,LOW);
duration1=pulseIn(echoPin1,HIGH);
duration2=pulseIn(echoPin2,HIGH);
distance1=duration1/58.2;
distance2=duration2/58.2;
if((duration1<40)&&(duration2<40))
{
for(aamsl=0;aamsl<90;aamsl++)
{
servo1.write(aamsl);
servo2.write(aamsl);
delay(15);
}
for(aamsl=0;aamsl<90;aamsl++)
{
servo3.write(aamsl);
servo4.write(aamsl);
delay(15);
}
delay(10000);
for(aamsl=90;aamsl>0;aamsl--)
{
servo3.write(aamsl);
servo4.write(aamsl);
delay(15);
}
for(aamsl=90;aamsl>0;aamsl--)
{
servo3.write(aamsl);
servo4.write(aamsl);
delay(15);
}
}
}