0% found this document useful (0 votes)
31 views10 pages

Obstacle 31 40

Robot obstacle

Uploaded by

JANANI C V
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views10 pages

Obstacle 31 40

Robot obstacle

Uploaded by

JANANI C V
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

3.2.

5 L293D Motor Driver Shield

Figure 3.7 L293D Motor Driver Shield (Adapted from Lelong, 2020)

3.2.5.1 L293D Motor Driver Shield Overview


The L293D is a high voltage, high current Integrated circuit which is used to drive DC motors with a
power supply of up to 36V. This chip is able to supple a maximum of 600mA per channel. This chip
is also known as a type of H-Bridge as it enables a voltage to be applied across a load in either direction
to an output, e.g. a motor [26], [27], [28].

3.2.5.2 Features of the L293D Motor Driver Shield


 It has to connections to allow for 5V servos to be connected to the Arduino’s high-resolution
dedicated timer
 It has up to 4 bi-directional DC motors with individual 8-bit speed selection
 It has up to 2 stepper motors with single coil, double coil, interleaved or micro-stepping.
 It has 4 H-Bridges

19
 It has Pull down resistors to disable motors during power up
 The Arduino reset button is brought to the top
 It is compatible with Mega, UNO & Duemilanove
 Its dimensions are: 69mm x 53mm x 14.3mm

3.2.5.3 Applications of the L293D Motor Driver Shield


 It is utilized in robots that require a stepper motor interface
 It is used in multiple DIY projects

3.3 Methodology
3.3.1 Robot Construction
3.3.1.1 Robot Working Principle
The robot uses the Ultrasonic sensor to measure the distance in front of it then it moves. As the distance
reduces, the robot interprets it as the presence of an obstacle. As soon as the robot detects the obstacle,
it stops and moves back a few cm then looks left and right before moving to a free path.

3.3.1.2 Hardware Components


 1x Arduino UNO R3
 1x 4 Wheel Robot Car Chassis(Includes Motors)
 1x HC-SR04 Ultrasonic sensor
 1x HC-SR04 Ultrasonic sensor holder
 1x L293D Motor Driver Shield
 1x SG90 Servo Motor
 2x 9V Battery
 1x 9V Battery clip without DC jack
 1x 9V Battery clip with DC jack
 1x Power Switch
 Jumper wires

20
Figure 3.8 Block diagram showing the Hardware Implementation of the project

3.3.1.3 Necessary Tools and Machines


 1x Soldering Iron
 Solder
 Glue
 Screw drivers
 Arduino IDE

21
3.3.1.4 Constructing the Robot car

Figure 3.9 Robot Chassis Components.

 Step 1. Connect the motor and wheels to the chassis by soldering the thick red and black wires to
the positive and negative terminals of the motors then attach them to the chassis [32].

Figure 3.10Wheels and Motors Attached to the Chassis

 Step 2. Attach the switch, battery clip, SG90 Servo Motor and Arduino UNO to the chassis. After
this, mount the L293D Motor Driver shield on the Arduino UNO R3 and the HC-SR04 to the
Servo motor.
22
Figure 3.11 Components attached to the chassis

 Step 3. Wire up components as shown in figure 4-17 below.

Figure 3.12 Robot Car Schematic. (Adapted from Arduino, 2014)

23
3.3.2 Programming the Robot
The Arduino microcontroller communicates with the PC via the USB connection. Data is transferred
between the board and the PC bit by bit. An adaptor is used for power supply to the board and a USB
programmer is used to burn the hardware program (written in Arduino IDE) into the board.

24
3.3.2.1 Flowchart of the program

Figure 3.13 Flow chart for the program


25
3.3.2.2 Arduino Coding
The code requires the use of three libraries and two of them must be downloaded for the program to
be able to compile. The first library is the motor shield driver library and the second one is the
NewPing library for the supersonic distance sensor.
Step 1. Firstly we need to include all the libraries in the code.
 Motor Shield library
 Servo Motor library
 Ultrasonic Sensor library
#include <AFMotor.h> //add Adafruit Motor Shield library
#include <Servo.h> //add Servo Motor library
#include <NewPing.h> //add Ultrasonic sensor library

Step 2. We declare the pins that are connected to the ultrasonic sensor. We also declare variables
which will be used to store info in this code:
#define TRIG_PIN A0 /* Pin A0 on the Motor Drive Shield soldered to the ultrasonic sensor*/
#define ECHO_PIN A1 /* Pin A1 on the Motor Drive Shield soldered to the ultrasonic sensor*/
#define MAX_DISTANCE 300 /* sets maximum useable sensor measuring distance to 300cm*/
#define MAX_SPEED 160 /* sets speed of DC traction motors to 150/250 or about 70% of full speed
- to get power drain down.*/
#define MAX_SPEED_OFFSET 40 /* this sets offset to allow for differences between the two DC
traction motors*/
#define COLL_DIST 30 /* sets distance at which robot stops and reverses to 30cm*/
#define TURN_DIST COLL_DIST+20 /* sets distance at which robot veers away from object*/
NewPing sonar(TRIG_PIN, ECHO_PIN, MAX_DISTANCE); /* sets up sensor library to use the
correct pins to measure distance.*/

Step 3. We initialize the servo motor by creating an object of the servo library. Also we initialize the
Motors to which the wheels are connected using the AF library:
AF_DCMotor leftMotor1(1, MOTOR12_1KHZ); /* create motor #1 using M1 output on Motor Drive
Shield, set to 1kHz PWM frequency*/

26
AF_DCMotor leftMotor2(2, MOTOR12_1KHZ); /* create motor #2, using M2 output, set to 1kHz
PWM frequency*/
AF_DCMotor rightMotor1(3, MOTOR34_1KHZ);/* create motor #3, using M3 output, set to 1kHz
PWM frequency*/
AF_DCMotor rightMotor2(4, MOTOR34_1KHZ);/* create motor #4, using M4 output, set to 1kHz
PWM frequency*/
Servo myservo; // create servo object to control a servo

Step 4. We define/initialize variables to be used


int leftDistance, rightDistance; //distances on either side
int curDist = 0;
String motorSet = "";
int speedSet = 0;

Step 5. We go into the void setup () function where we initialize the servo motor and set it to look
straight using a 90 degrees angle.
void setup() {
myservo.attach(10); /* attaches the servo on pin 10 (SERVO_1 on the Motor Drive Shield to the
servo object */
myservo.write(90); // tells the servo to position at 90-degrees ie. facing forward.
delay(1000); // delay for one seconds
}

Step 6. We go into the loop function and measure the distance and set it to change direction if the
forward path is blocked
void loop() {
myservo.write(90); // move eyes forward
delay(90);
curDist = readPing(); // read distance
if (curDist < COLL_DIST) {changePath();} /* if forward is blocked change direction*/

moveForward(); // move forward

27
delay(500);
}
Step 6. We instruct it on how it is to change path.
First the void changePath () function instructs it to stop forward movement, then check and store right
distance(by turning the servo motor 36 degrees), check and store left distance(by turning the servo
motor 144 degrees) and then return sensor to the centre position.
After this, we go into the void compareDistance () function and instruct it to follow the longer distance.
void changePath() {
moveStop(); // stop forward movement
myservo.write(36); // check distance to the right
delay(500);
rightDistance = readPing(); //set right distance
delay(500);
myservo.write(144); // check distace to the left
delay(700);
leftDistance = readPing(); //set left distance
delay(500);
myservo.write(90); //return to center
delay(100);
compareDistance();
}

void compareDistance() // find the longest distance


{
if (leftDistance>rightDistance) //if left is less obstructed
{
turnLeft();
}
else if (rightDistance>leftDistance) //if right is less obstructed
{
turnRight();

28

You might also like