In this blog, we will explore how to make an Arduino based Ultrasonic Obstacle Avoider robot purchased from roboelements.com
Components Required :
|Ultrasonic Sensor Module|
|Arduino UNO R3 programmed|
|Motor Driver Shield|
|Jumper Wires F-F|
|Nut, Bolt, Spacer & motor clamps|
|USB A-B Programming Cable|
Arduino UNO R3
Arduino UNO R3 board is used as the controller, which is interfaced with Ultrasonic Sensor to get the distance of the object and drive the two DC motors through L293D Motor Driver Shield.
Ultrasonic Sensor HC-SR04
The Sensor used in the bot is the cheap and popular HC-SR04 Ultrasonic Sensor. It has four pins for interfacing namely, Vcc, TRIG, ECHO & GND.
DC supply voltage to be given to power pins Vcc and GND which is usually 5V.
TRIGGER is an INPUT pin which is kept high for 10us to generate an ultrasonic pulse wave of 40kHz from sensor.
ECHO is an OUTPUT pin that goes high when the ultrasonic pulse wave is received back after getting bounced off from an object.
The time taken by the pulse wave, considered to be traveling at 340m/s (speed of sound at room temp.), is utilized to calculate the distance of an object in the straight line from the sensor.
To easily mount the Sensor onto chassis board a breakout module is provided with the kit, which makes all the pins of Ultrasonic sensor available through berg connectors.
L293D Arduino Shield
Arduino Motor Driver Shield comprises of L293D motor driver Ics which enable us to drive four DC motors or 2 Stepper Motors and 2 Servo motors simultaneously through Arduino.
It has screw connector headers for connecting 4 DC motors M1, M2, M3 & M4 or 2 nos 5-wires unipolar stepper motors. There are berg strip male connectors for connecting 2 servo motors Sero1 & Servo2 for 3 pin servo interface Vcc, GND & SIG. Vcc is +5V. Screw connection headers are given for connecting external DC power supply for motors and Arduino.
Always keep the jumper inserted to power Arduino through Motor Driver Shield.
On board voltage regulator provides 5V logic voltage output for Arduino and other components requiring the same. This motor driver shield is designed for Arduino UNO board and makes available all analog pin on Arduino with power pins as male berg connectors. Peripherals requiring +5V can be easily powered by the battery through Shield. Since other pins are already utilized in the shield we will be using these analog and power pins to connect our sensors to Arduino.
We have used the Adafruit motor driver library for running motors through Motor Driver Shield. Download here.
You can also install the same from Arduino IDE. Click on ‘Manage Libraries’ in ‘Tools’ Menu. Search AF Motor. Install the Adafruit Motor Shield Library.
Upload the following source code to Arduino
Please note that there is a battery holder provided with the kit to run bot on four 1.5V Dry Cell Batteries but it is recommended to use our
The kit is tested with the given code on our 7.4V Li-ion Battery. To run this bot you require high power batteries, ordinary Dry Cells and 9V toy batteries won’t work. It might run on DURACELL high power batteries for a very short period if we increase the speed of motors to maximum by making following changes to program.
motor1.setSpeed(255); //motor speed set to max. range:0-255;
If you hear only motor vibration sound and no movement or if the bot is moving very slow, kindly use higher voltage batteries.
If a motor is found to be moving in reverse direction of as intended, swap the wires for that particular motor connected at connectors M3 or M4.
Do let us know of any queries in the comments.