Annex D: Automated Baby Walker Program For Ultrasonic Sensors and Servo Motors

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Annex D: AUTOMATED BABY WALKER PROGRAM FOR ULTRASONIC SENSORS

AND SERVO MOTORS


distance3 = distance;
#include <Servo.h> Ultrasonic(trigpin4,echopin4);
#define trigpin1 6//set trigpin distance4 = distance;
#define echopin1 7//set echopin
#define trigpin2 8//set trigpin if(((distance1 <= 20 && distance1 >=
#define echopin2 9//set echopin 0)||(distance2 <= 20 && distance2 >=
#define trigpin3 10//set trigpin 0)||(distance3 <= 20 && distance3 >=
#define echopin3 11//set echopin 0)||(distance4 >= 7[0 )) || (doonce == 0)
#define trigpin4 12//set trigpin )// if ultrasonic sensors detect an
#define echopin4 13//set echopin obstacle less than 20cm in 90 degree
angle.
Servo myservo1,myservo2;// declare {
servo name type servo myservo1.write(90); //servo rotates at
double full speed to the right
distance,duration,distance1,distance2,di myservo2.write(90); //servo rotates at
stance3,distance4; full speed to the right
int doonce = 0; doonce = 1;
delay(1000);
void setup() { }
Serial.begin(115200); else //if(( distance1 > 20 )||( distance2 >
pinMode(trigpin1, OUTPUT); 20 )||( distance3 > 20 )||( distance4 < 20
pinMode(echopin1, INPUT); ))
pinMode(trigpin2, OUTPUT); {
pinMode(echopin2, INPUT); myservo1.write(0);// else servo stays at
pinMode(trigpin3, OUTPUT); 90 degree angle.
pinMode(echopin3, INPUT); myservo2.write(0); //servo rotates at
pinMode(trigpin4, OUTPUT); full speed to the right
pinMode(echopin4, INPUT); doonce = 1;
myservo1.attach(3);// attach your delay(1000);
servo1 }
myservo2.attach(5);// attach your Serial.print(distance1); //print distance1
servo2 unit cm
myservo1.write(0); Serial.print(" cm ");//distance1
myservo2.write(0); Serial.print(distance2); //print distance2
// put your setup code here, to run unit cm
once: Serial.print(" cm ");//distance2
} Serial.print(distance3); //print distance3
void loop() { unit cm
//ultrasonic code Serial.print(" cm ");//distance3
Ultrasonic(trigpin1,echopin1); Serial.print(distance4); //print distance4
distance1 = distance; unit cm
Ultrasonic(trigpin2,echopin2); Serial.println(" cm ");//distance4
distance2 = distance; }
Ultrasonic(trigpin3,echopin3); void Ultrasonic(int trigpin, int echopin)

25
{
digitalWrite(trigpin,LOW);
delayMicroseconds(2);
digitalWrite(trigpin,HIGH);
delayMicroseconds(10);
digitalWrite(trigpin,LOW);
duration = pulseIn(echopin,HIGH);
distance = (duration/2)/29.1;
}

26
27

You might also like