Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
212001698
TABLE OF CONTENT
Introduction..........................................................................................
...........3
Ultrasonic Sensor..............................................................................................................4
Motor Driver Section........................................................................................................4
Components......................................................................................................................4
Block Diagram..................................................................................................................5
Schematic Diagram...........................................................................................................5
Connection Description....................................................................................................6
Arduino Code....................................................................................................................7
LIST OF FIGURES
HC-SR04 ..........................................................................................................................5
BLOCK-DIAGRAM...........................................................................................................6
SCHEMATIC DIAGRAM .................................................................................................6
CIRCUIT CONNECTION 1...............................................................................................6
Ultrasonic Sensor
HC-SR04
the object.
Components
The Components required for building the Wall follower Robot are:
Embedded Application Board (ARDUINO)
Motor Driver Board (containing L293D)
DC Motors (2 nos)
Chassis
Connectors(Jumpers)
9V battery
Wheels
Walls
Block Diagram
Block level representation of the different blocks of the Wall follower Robot.
BLOCK DIAGRAM 1
Schematic Diagram
The Schematic diagram illustrates the circuit connections for designing the application.
SCHEMATIC DIAGRAM 1
Connection Description
In this project I used 2 Ultrasonic Sensor modules as wall detectors. They are placed in
the Right and Front corner of the robot. These modules have 4-pins each, as GND, VCC,
TRIG and ECHO . The GND and VCC pins are connected to the GND and VCC pins of
the Arduino. The DATA pins (trig and echo) of the sensors are connected to pins A2, A3,
A4 AND A5 of the arduino. The inputs to the motor driver are from Pins 3, 5, 6 and 9 of
the arduino, all these pins are able to output a PWM signal. These pins are responsible for
controlling the robot and they are connected to the IN1, IN2, IN3 and IN4 pins of the
Motor Driver board, respectively. Both the Motor Driver Board and the Arduino are
CIRCUIT CONNECTION 2
Arduino Code
#define motor_l 10
#define motor_r 11
#define l1 3
#define l2 5
#define r1 6
#define r2 9
int trigger_f = A4;
int echo_f = A5;
int trigger_l = A2;
int echo_l = A3;
int trigger_r = A0;
int echo_r = A1;
void setup()
{
pinMode(trigger_f, OUTPUT);
pinMode(echo_f, INPUT);
pinMode(trigger_l, OUTPUT);
pinMode(echo_l, INPUT);
pinMode(trigger_r, OUTPUT);
pinMode(echo_r, INPUT);
pinMode(motor_l, OUTPUT);
pinMode(motor_r, OUTPUT);
pinMode(l1, OUTPUT);
pinMode(l2, OUTPUT);
pinMode(r1, OUTPUT);
pinMode(r2, OUTPUT);
delay(5000);
}
void loop()
{
long duration_f, duration_l, duration_r, right, left, front;
digitalWrite(trigger_f, LOW);
delayMicroseconds(2);
digitalWrite(trigger_f, HIGH);
delayMicroseconds(5);
digitalWrite(trigger_f, LOW);
duration_f = pulseIn(echo_f, HIGH);
front = duration_f/29/2;
digitalWrite(trigger_l, LOW);
delayMicroseconds(2);
digitalWrite(trigger_l, HIGH);
delayMicroseconds(5);
digitalWrite(trigger_l, LOW);
duration_l = pulseIn(echo_l, HIGH);
left = duration_l/29/2;
digitalWrite(trigger_r, LOW);
delayMicroseconds(2);
digitalWrite(trigger_r, HIGH);
delayMicroseconds(5);
digitalWrite(trigger_r, LOW);
duration_r = pulseIn(echo_r, HIGH);
right = duration_r/29/2;
analogWrite(motor_l, 0); //
analogWrite(motor_r, 0); //
analogWrite(l1, 0);
//
analogWrite(l2, 0);
//
analogWrite(r1, 0);
//
analogWrite(r2, 0);
//
if(front >8)
{
if(right >7 && right< 13)
{
analogWrite(motor_l, 120);
analogWrite(motor_r, 150);
analogWrite(l1, 255);
analogWrite(l2, 0);
analogWrite(r1, 0);
analogWrite(r2, 255);
}
if(right >=13)
{
analogWrite(motor_r, 255);
analogWrite(motor_r, 60);
analogWrite(l1, 255);
analogWrite(l2, 0);
analogWrite(r1, 0);
analogWrite(r2, 255);
}
if(right <=7)
{
analogWrite(motor_l, 60);
analogWrite(motor_r, 255);
analogWrite(l1, 255);
analogWrite(l2, 0);
analogWrite(r1, 0);
analogWrite(r2, 255);
}
}
if(left <=20 && right>20 && front <=8) rig();
if(left >20 && right>20 && front <=8) rig();
if(right <=20 && left>20 && front <=8) lef();
if(right<=20 && left<=20 && front<=8) forward();
}
void lef()
{
analogWrite(motor_l, 120);
analogWrite(motor_r, 120);
analogWrite(l1, 0);
analogWrite(l2, 255);
analogWrite(r1, 0);
analogWrite(r2, 255);
delay(700);
}
void rig()
{
analogWrite(motor_l, 120);
analogWrite(motor_r, 120);
analogWrite(l1, 255);
analogWrite(l2, 0);
analogWrite(r1, 255);
analogWrite(r2, 0);
delay(800);
}
void forward()
{
analogWrite(motor_l, 120);
analogWrite(motor_r, 120);
analogWrite(l1, 255);
analogWrite(l2, 0);
analogWrite(r1, 255);
analogWrite(r2, 0);
delay(1200);
}