Description of The Assignment
Description of The Assignment
Introduction
In this project I demonstrate the basics of building the 4wd obstacle avoidance car. The 4wd (four wheel drive)
obstacle avoidance car can move and respond to its surroundings. I will start by the basics of its mechanical
assembly and give explanation on some of the operations of some of the components of the 4wd robot. On the
software part of the 4wd robot the programming was accomplished using the Arduino IDE. Arduino UNO is used
as a central component to which all other components are interfaced. Arduino UNO is an open source hardware
development board. The board is furnished with a mix of input-output pins, both analog and digital. The pins are
utilized to interface the Arduino board with different shields and circuit boards. The board comprises of 14 digital
pins and 6 analog pins and it is programmable with an intergrated development system called Arduino IDE with the
assistance of a B type USB link. I powered it with two 3.7volts batteries in spite of the fact that it acknowledges
voltages in the scope of 7 to 20 volts. The 4wd robot consists of other major components such as 4 motors
that enable its motion and the ultrasonic, infra red sensors which are essential for the responses it exhibits to its
environment. I chose a four wheeled platform because four wheel drive makes it easier to roam over the rougher
surfaces compared to the two wheel platform.
Objectives
Building a 4wd obstacle avoidance robot car, enabling the robot to see the ground and detect the edge by the use
of IR sensors and measuring the distance of a target object to be able to avoid collision with the object and to
change its direction to avoid these objects.
Mechanical Assembly
The mechanical structure is simple and easy to install. There are mainly four modules:
The installation design was welding free. The components are fixed by copper pillars and screws. The circuit
connection between each module is connected by Du Pont wire, which is simple and and convenient.
1
Hardware Required
• 2× 3.7volts 18650 2500mah lithium batteries
• Ultrasonic bracket
• 17× M3 nuts
• 3× M2 nut
• 4× M1.6 nut
Specifications:
• Power supply: 2 removable 3.7volts lithium batteries
2
Component Description
L298N Module
• Control signal input level: high level: 2.3v to VIN vs low level:-0.3V¡=VIN¡=1.5v
State ENA
Stop 0
Break 1
Forward 1
Back 1
Left 1
Right 1
HC-SR04 Module
3
• Maximum range - 4m
• Output echo signal- Output TTL level signal, proportional to the range.
• Size - 45*20*15
3. Receiver (echo pin): Receives the signal reflected back from it.
The HC-SR04 ultrasonic sensor detects how far ahead obstacle has appeared. If there is an obstacle in your
specified detention range, the car can make corresponding actions. For example, forward, back, turn left or turn
right.
Description Value
Electrical parameters Four channel tracking module
Working voltage DC 3.3V 5V
Working current 1A
Working temperature -10o C 50o C
Mounting aperture M3
Detect distance 1mm 600mm
Size 42×38mm
Output signal TTL level
Arduino Program
Arduino Code
4
Listing 1: Code.ino
/∗
#i n c l u d e <AFMotor . h>
#d e f i n e T r i g 12
#d e f i n e Echo 13
#d e f i n e ENA 5
#d e f i n e ENB 6
#d e f i n e IN1 3
#d e f i n e IN2 4
#d e f i n e IN3 2
#d e f i n e IN4 7
f l o a t cm ; // D i s t a n c e v a r i a b l e
f l o a t temp ; //
void setup () {
S e r i a l . begin (9600);
pinMode ( T r i g , OUTPUT ) ;
pinMode ( Echo , INPUT ) ;
void loop () {
d i g i t a l W r i t e ( Trig , LOW) ;
delayMicroseconds (2);
d i g i t a l W r i t e ( Trig , HIGH ) ;
delayMicroseconds (10);
d i g i t a l W r i t e ( Trig , LOW) ;
i f ( cm < 1 0 )
{
STOP ( ) ;
}
S e r i a l . p r i n t ( ” Echo = ” ) ;
S e r i a l . p r i n t ( temp ) ;
S e r i a l . p r i n t (” | | D i s t a n c e = ” ) ;
5
S e r i a l . p r i n t ( cm ) ;
S e r i a l . p r i n t l n ( ” cm ” ) ;
delay (100);
}
void forward () {
a n a l o g W r i t e (ENA , 2 2 0 ) ;
a n a l o g W r i t e (ENB , 2 2 0 ) ;
d i g i t a l W r i t e ( IN1 , HIGH ) ;
d i g i t a l W r i t e ( IN2 , LOW) ;
d i g i t a l W r i t e ( IN3 , LOW) ;
d i g i t a l W r i t e ( IN4 , HIGH ) ;
S e r i a l . p r i n t l n (” Forward ” ) ;
}
v o i d back ( ) {
a n a l o g W r i t e (ENA , 2 2 0 ) ;
a n a l o g W r i t e (ENB , 2 2 0 ) ;
d i g i t a l W r i t e ( IN1 , LOW) ;
d i g i t a l W r i t e ( IN2 , HIGH ) ;
d i g i t a l W r i t e ( IN3 , HIGH ) ;
d i g i t a l W r i t e ( IN4 , LOW) ;
S e r i a l . p r i n t l n ( ” Back ” ) ;
}
void Left () {
a n a l o g W r i t e (ENA , 2 2 0 ) ;
a n a l o g W r i t e (ENB , 2 2 0 ) ;
d i g i t a l W r i t e ( IN1 , LOW) ;
d i g i t a l W r i t e ( IN2 , HIGH ) ;
d i g i t a l W r i t e ( IN3 , LOW) ;
d i g i t a l W r i t e ( IN4 , HIGH ) ;
S e r i a l . p r i n t l n (” L e f t ” ) ;
}
void Right () {
a n a l o g W r i t e (ENA , 2 2 0 ) ;
a n a l o g W r i t e (ENB , 2 2 0 ) ;
d i g i t a l W r i t e ( IN1 , HIGH ) ;
d i g i t a l W r i t e ( IN2 , LOW) ;
d i g i t a l W r i t e ( IN3 , HIGH ) ;
d i g i t a l W r i t e ( IN4 , LOW) ;
S e r i a l . p r i n t l n (” Righ t ” ) ;
}
v o i d STOP ( ) {
d i g i t a l W r i t e (ENA , LOW) ;
d i g i t a l W r i t e (ENB , LOW) ;
d i g i t a l W r i t e ( IN1 , LOW) ;
d i g i t a l W r i t e ( IN2 , LOW) ;
d i g i t a l W r i t e ( IN3 , LOW) ;
d i g i t a l W r i t e ( IN4 , LOW) ;
S e r i a l . p r i n t l n ( ”STOP ” ) ;
}
}
6
Code Explanation
When the transmitting pin of the ultrasonic module detects an obstacle in front, the reflected pin will receive the
signal and transmit it to the MCU through IO pin. After the SIGNAL is received, the MCU will drive the L298N
module to realize the corresponding action of the motor. For example, if an obstacle is detected in the front range
less than 30cm and larger than 10cm, the MCU will control the car to retreat successively and then turn left; while
in the front range less than 10cm, the car will stop, while in the front range greater than 30cm, the car will move
forward without any obstacle detected.
Conclusion
In this Project, the field of Robotics is investigated and a robotic car which has potential to be equipped with
many functionalities is proposed. The designed model detects any obstacle encountered in front of it. During the
project, complete working of Arduino UNO is and sensors is understood and executed. The project gives profound
knowledge into Arduino IDE and gives good exposure to coding. Below is the circuit diagram and images that were
taken during the assembly of the 4wd robot car.
Circuit Diagram
7
Images
8
9