Professional Documents
Culture Documents
EE351 Expt 35
EE351 Expt 35
R3
Andino
Uno
Vec Owt out 2
LNI
T6 5V D2 IN2
Fand ENABLEI
Gnnd ENABLE 2
INI
Uut 3 out4 GnND
Ao
ulthaDoni A2 (3)
Senso A4
As
Moto
Servo
Noto
BLDCKDIAGRAM
Snput Contholer
Output
Uthasonic An dino
Shvo Motor +
Senso. wiu dueide Dc Moto
Reaoo the is tan ce
wht to d
btw bt Dbstalle aceo nding to diotaned ithl
Servo 2 De both
howCHART
(START Iriaisig
Reacding distanee
nom. he Senson
Mo No
islante
torwad
YES
Stop the
motos
Jurn snsor gh
4 head disace
J n sunbor to
nonal positton
YES Distance
Rinht uost. Jwnn lalt
4t
blay soD ms bulay s0om
DBSERVATION S
Jhe bot wota even on giving sv to he.
moto dhive,but the speed o motors
blowr
ompard to when l2 v was given. Aso,
1Ohen neounted with moviry obbtacle , it
not b able to mavig
avoid it as it oould h
may
Come voy an to the obstacle by the tim it
takeo a t n thetoe wil collide
ANSWERs To &vEs TI DN S
the block
diagamit
implumntt d hen. tue myou have
LooP sysern?
Jnput Contnolw Ouput
masone (Anduino) Senvo Mo ton ano
Sendo De Moto
#include<Servo.h>
1 Servo
Servo servo;
const int servoPin = 3;
1/ HC-sRO4
const int triggerPin = 13;
const int echoPin = 12;
1/Moto A
const int motorPin1 = 5; // Pin 14 of L293
const int motorPin2 = 6; 1/ Pin 10 of L293
1/Motor B
const int motorPin3 = 10; 1/ Pin 7 of L293
const int motorPin4 = 9; 1/ Pin 2 of L293
void setup () {
/Ultrasonic sensor
pinMode (triggerPin, OUTPUT);
pinMode (echoPin, INPUT) ;
Serial.begin (9600) ;
& Motor B:
1/Motor Control - Motor A: notorPinl , notorpin2
notorpin3, motorpin4
pinMode (motorPinl, OUTPUT);
pinMode (motorPin2, OUTPUT) :
pinMode (motorPin3, OUTPUT);
pinMode(motorPin4, OUTPUT) ;
void forwa rd () {
digitalWrite (motorPinl, HIGH) ;
digitalWrite (motorPin2, LOW) ;
digitalWrite (motorPin3, HIGH) :
digitalWrite (motorPìnd, Lo);
Retuns tEe if
bool checkRight () no obstacle at ight
Riaht turn and check
servo.Write (47-30):
delay (200) :
double dR = checkDist () ;
eSt turh and
check
servo.Write
delay(200):
(47+30):
double dL checkDist ();
Nornal pos&tion
servo.Write (47) ;
delay(200):
if (dR> dL)
else return false
return true;
void turnRight () (
digitalWrite (motorPinl, HIGH) ;
digitalWrite (motorPin2, LOW) ;
digitalWrite (motorPin3, LOW):
digitalWrite
delay (500);
(motor Pin4, HIGH) ;
void turnLeft () {
digitalWrite (motorPinl, LOW) :
digitalWrite (motorPin2, HIGH) ;
digitalWrite(motorPin3, HIGH) :
digitalWrite (motorPin4, LOW) :
delay (5 00) ;
double checkDist () {
digitalWrite (triggerPin, LOW) ;
delayMicroseconds (5) ;
digitalWrite (triggerPin, HIGH) ;
delayMicroseconds (10);
digitalWrite (triggerPin, LOW) :
int duration = pulseIn (echoPin, HIGH);
double dist = (duration / 2) / 29.1;
return dist;
void loop () {
double distance = checkDist () ;
bool isObstacle = distance < 15;
if (is Obstacle) {
checkRight
The Motor stops and will check left and right with
function
digitalWrite (notor Pinl, LOW) :
digitalWrite (motorPin2, LOW);
digitalWrite (moto rPin3, LOW) ;
digitalWrite (motorPin4, LOW) ;
if (checkRight () ) turnRight ):
else turnLe ft () ;
) else forward() ;