SMART TURNING MECHANISM1
SMART TURNING MECHANISM1
1st Sem
ABDULLAH JAFAR (24-ME-73)
HUZAIFA ALI (24-ME-156)
M.IBRAHIM (24-ME-164)
JUNAID FARID (24-ME-152)
WORKSHOP PRACTICAL PROJECT
AITIZAZ ARIF (24-ME-128)
SMART TURNING MECHANIS
M (OBSTACLE AVOIDENCE C
AR)
At the core of this project is the car's ability to scan its surroundings using ultra
sonic sensors, which provide the necessary data to assess potential hazards. U
pon detecting an obstacle, the car can either turn to avoid the object or halt its
movement, depending on the situation. This decision-making process is swift a
nd based on precise measurements, ensuring that the car can respond effectiv
ely to sudden changes in its environment.
The primary objective of this project is to enable the car to navigate autonomo
usly through various terrains and environments without human intervention. It
adapts to real-time changes, continuously assessing the space around it and ad
justing its movement accordingly. This dynamic adaptability is essential for safe
and reliable autonomous driving, especially in environments where obstacles
may appear unexpectedly.
METHODOLOGY
COMPONENTS:
ARDUINO UNO: Arduino Uno is a versatile, user-friendly microcontroller boa
rd designed for a wide range of electronic projects. At its heart, it features the
ATmega328P chip, which operates on a 5V power supply, providing enough pr
ocessing power for small to medium-sized applications. Arduino Uno is progra
mmed using the Arduino Integrated Development Environment (IDE), allowing
users to write and upload code with ease.
Its popularity is attributed to its simple design and large supportive community,
which makes it an excellent choice for both beginners and experts. Whether y
ou're building robots, creating smart devices, or experimenting with home aut
omation, the Arduino Uno can handle a variety of tasks, from controlling senso
rs to driving motors.
The board is equipped with a variety of ports to enhance its functionality. It inc
ludes:
Power Pins: For providing the necessary voltage to power the Arduino
or external components.
Digital I/O Pins: These pins allow you to interface with devices such as
switches, LEDs, and relays. They can read or send HIGH or LOW signals,
making them essential for simple on/off operations.
Analog Pins: Used for reading analog sensors like temperature sensors
or potentiometers, providing a range of values instead of just HIGH or LO
W.
USB Port: For easy programming and power supply, allowing the user t
o connect the board to a computer for code upload and debugging.
TX/RX Pins: These are used for serial communication with other device
s, such as sensors, modules, or even other microcontrollers.
Reset Button: A key feature that enables you to restart the program on
the Arduino, useful for troubleshooting or re-running the code without r
e-plugging the board.
In addition to its built-in capabilities, the Arduino Uno benefits from an extensi
ve library of code, tutorials, and shields (add-on boards) that extend its functio
nality. The open-source nature of Arduino also means that there is a vast range
of resources available online, making it easier for users to troubleshoot issues
and share their projects with the global Arduino community.
Servo motors can be easily controlled using an Arduino Uno. With the help of t
he Arduino’s PWM (Pulse Width Modulation) signals, you can easily program t
he motor to move to any angle within its range. The Arduino Uno’s simplicity a
nd the availability of the Servo library make it beginner-friendly, allowing you t
o easily integrate servo motors into projects for tasks like positioning, rotation,
and control. This makes the Arduino Uno and servo motor combination an idea
l choice for both simple and complex motion-control projects.
DC motors are simple, efficient, and widely used due to their ability to run dire
ctly on batteries or DC power sources. They are easy to control, especially in te
rms of speed and direction, by adjusting the voltage or polarity. DC motors are
commonly found in devices like toys, electric vehicles, robotics, and small appli
ances, where reliable, adjustable motion is needed. Their compact size and abil
ity to provide smooth, continuous motion make them versatile for various mec
hanical systems.
WHEELS: Robotic car wheels are specially designed wheels used in remo
te-controlled cars to provide movement and stability. They are typically
made of rubber for better grip and are attached to motors that allow the
car to move in different directions.
Distance=Time×Speed of Sound/2
The division by 2 accounts for the fact that the sound waves travel to the objec
t and back, effectively doubling the distance.
Lithium-ion technology is also known for its longer lifespan compared to other
rechargeable batteries. They maintain a stable voltage output throughout their
discharge cycle, offering consistent and reliable power. This stability, along wit
h the ability to recharge many times, makes the 9V lithium-ion battery a more
efficient and durable option for powering various devices.
JUMP WIRES: Jump wires are used to make connections between co
mponents and the Arduino board.These wires are very convenient to use
as they don’t require any soldering,
WORKING
The robotic car utilizes an Arduino Uno as its central controller, which coordin
ates the functions of various components to enable autonomous movement an
d obstacle avoidance. The DC motors provide the power to drive the wheels, a
nd a motor driver regulates their speed and direction, allowing the car to mov
e forward, backward, or turn.
To change the direction of the car, the speed of the diagonal wheels is adjuste
d. This differential drive system allows the car to move in any direction, includi
ng straight, turning left or right, and even rotating in place. The precise control
of motor speed enables smooth and accurate navigation.
For obstacle detection, the car is equipped with an ultrasonic sensor, which e
mits sound waves and measures the time it takes for the waves to reflect back
after hitting an object. The Arduino Uno calculates the distance to obstacles ba
sed on the echo time, allowing the car to avoid collisions. The sensor is mounte
d on a servo motor, enabling it to rotate 90° to both the left and right. This mo
vement allows the car to scan its surroundings and detect obstacles over a wid
er area, making it more aware of its environment.
The chassis provides the structural foundation and supports all the component
s, ensuring everything is securely mounted and aligned for smooth operation. T
he battery box, which houses the 9V lithium-ion batteries, powers the entire s
ystem, providing sufficient energy for the motors, sensors, and the Arduino bo
ard. These batteries are rechargeable, offering long-lasting power and efficienc
y.
Jumper wires are used to connect the various components to the Arduino Uno,
facilitating communication and control. These wires create the electrical conn
ections needed for the motors, sensors, and other devices to function together
in unison.
In operation, the Arduino Uno continuously processes input from the ultrasoni
c sensor, adjusts motor speeds through the motor driver, and uses the servo m
otor to scan for obstacles. The combination of these components enables the c
ar to move autonomously, detect obstacles, and navigate its environment with
increasing accuracy. The integration of these parts results in a fully functional r
obotic car capable of performing tasks such as autonomous navigation, collisio
n avoidance, and responsive movement.
CODE EMBEDDED IN
ARDUINO
#include <AFMotor.h>
#include <NewPing.h>
#include <Servo.h>
#define TRIG_PIN A0
#define ECHO_PIN A1
#define MAX_SPEED_OFFSET 20
int in1 = 5;
int in2 = 6;
int in3 = 7;
int in4 = 8;
int ena = 3;
Servo myservo;
boolean goesForward=false;
void setup() {
pinMode(in1,OUTPUT);
pinMode(in2,OUTPUT);
pinMode(in3,OUTPUT);
pinMode(in4,OUTPUT);
pinMode(ena,OUTPUT);
pinMode(enb,OUTPUT);
analogWrite(ena,100);
analogWrite(enb,100);
myservo.attach(10);
myservo.write(115);
delay(2000);
distance = readPing();
delay(100);
distance = readPing();
delay(100);
distance = readPing();
delay(100);
distance = readPing();
delay(100);
}
void loop() {
int distanceR = 0;
int distanceL = 0;
delay(40);
if(distance<= 25)
moveStop();
delay(100);
moveBackward();
delay(300);
moveStop();
delay(200);
distanceR = lookRight();
delay(200);
distanceL = lookLeft();
delay(200);
if(distanceR>=distanceL)
turnRight();
delay(250);
moveStop();
}else
{
turnLeft();
delay(250);
moveStop();
}else
moveForward();
distance = readPing();
int lookRight()
myservo.write(50);
delay(500);
delay(100);
myservo.write(115);
return distance;
int lookLeft()
myservo.write(170);
delay(500);
delay(100);
myservo.write(115);
return distance;
delay(100);
int readPing() {
delay(70);
int cm = sonar.ping_cm();
if(cm==0)
cm = 250;
return cm;
void moveStop() {
digitalWrite(in1,LOW);
digitalWrite(in2,LOW);
digitalWrite(in3,LOW);
digitalWrite(in4,LOW);
}
void moveForward() {
digitalWrite(in1,HIGH);
digitalWrite(in2,LOW);
digitalWrite(in3,HIGH);
digitalWrite(in4,LOW);
void moveBackward() {
digitalWrite(in1,LOW);
digitalWrite(in2,HIGH);
digitalWrite(in3,LOW);
digitalWrite(in4,HIGH);
void turnRight() {
digitalWrite(in1,LOW);
digitalWrite(in2,HIGH);
digitalWrite(in3,HIGH);
digitalWrite(in4,LOW);
void turnLeft() {
digitalWrite(in1,HIGH);
digitalWrite(in2,LOW);
digitalWrite(in3,LOW);
digitalWrite(in4,HIGH);
CODE ANALYSIS
The code controls a robotic car using an Arduino. It uses an ultrasonic sensor, s
ervo motor, and DC motors to enable the car to move, avoid obstacles, and na
vigate autonomously. Below is a breakdown of the code structure and its functi
onality:
Libraries Used:
1. AFMotor.h: This library controls DC motors using the Adafruit Motor Shie
ld.
2. NewPing.h: Used for interfacing the ultrasonic sensor, providing function
s for pinging and calculating distance.
3. Servo.h: Manages the servo motor for rotating the ultrasonic sensor to l
ook left and right.
Definitions:
TRIG_PIN and ECHO_PIN: These define the pins for the ultrasonic senso
r's trigger and echo.
MAX_DISTANCE: Maximum distance to measure using the ultrasonic sen
sor (in cm).
MAX_SPEED and MAX_SPEED_OFFSET: These values set the maximum sp
eed of the DC motors and an additional speed adjustment.
Global Variables:
goesForward: A boolean variable to determine the movement direction
(not used actively in the code).
distance: Stores the distance measured by the ultrasonic sensor.
speedSet: Controls motor speed (not used in the code).
Setup Function:
In the setup() function:
The pins for the motors and the servo are initialized as outputs.
The motor speeds are set using analogWrite on the enable pins (ena and
enb).
The servo is attached to pin 10, and an initial position of 115° is set (poin
ting forward).
The program reads the distance from the ultrasonic sensor multiple time
s for initialization, storing the results in distance.
Loop Function:
In the loop() function:
2. If the distance is greater than 25 cm, the robot moves forward using mov
eForward().
The distance is updated after every movement by calling the readPing() functio
n.
Helper Functions:
1.
lookRight():
2.
o Rotates the servo to 50° to check the right side, waits for the dista
nce measurement, then rotates the servo back to 115° (forward) a
nd returns the measured distance.
3.
lookLeft():
4.
5.
readPing():
6.
o Sends a pulse from the ultrasonic sensor, measures the echo time,
and returns the distance in centimeters.
o If no object is detected (distance 0), it defaults to a maximum valu
e (250 cm) to avoid erroneous readings.
7.
Movement Functions:
8.
Summary of Behavior:
The robotic car continuously checks for obstacles in front of it using the u
ltrasonic sensor.
If an obstacle is detected within 25 cm, the robot stops, moves backward,
and then scans to determine which direction (left or right) has more spa
ce.
Based on the comparison, the robot turns towards the direction with mo
re space and continues moving forward.
If there are no obstacles, the robot keeps moving forward.
PICTURES
PROJECTIONS
CONCLUSION
The Smart Turning Mechanism for Obstacle Avoidance Car project exemplifies
the successful integration of both hardware and software to develop an intellig
ent, autonomous robotic system capable of efficiently navigating various envir
onments. At the heart of this project is the Arduino Uno, acting as the central c
ontroller that coordinates the operation of the system’s various components. T
his includes advanced sensors, such as the ultrasonic sensor, and precise moti
on control via servo motors and DC motors, enabling the car to autonomously
detect obstacles and make real-time decisions to avoid collisions.
This project not only highlights the potential of affordable technology to build s
mart, autonomous systems but also offers a scalable solution applicable to a wi
de range of use cases. The adaptability of the design makes it suitable for a vari
ety of environments, from educational robotics platforms to the development
of more sophisticated autonomous systems in fields such as logistics, robotics,
and even real-world vehicle navigation.
Looking ahead, there are numerous avenues for future enhancements and exp
ansions. One promising direction involves integrating more advanced sensors,
such as infrared sensors or LIDAR systems, to improve the car’s ability to detec
t obstacles and map its surroundings with greater precision. Additionally, imple
menting machine learning algorithms could enhance the decision-making proc
ess, allowing the car to learn from its experiences and optimize its pathfinding
capabilities over time. These algorithms could allow the car to adapt its naviga
tion strategies based on previous encounters, improving both its efficiency and
safety. Furthermore, enhancing the energy management system through the u
se of more efficient power sources or solar cells could extend the car’s operati
onal time, making it more sustainable for prolonged use.
This project serves as an important stepping stone in the broader field of auto
nomous technologies. It provides a solid foundation for exploring advanced co
ncepts in robotics, from the integration of sophisticated sensors to machine lea
rning and autonomous decision-making. The design’s simplicity yet effectivene
ss demonstrates how even basic components, when combined thoughtfully, ca
n lead to impactful innovations. By showcasing the practical potential of smart
navigation systems, this project contributes to the future of autonomous vehic
les, opening doors to safer, smarter, and more efficient transportation solution
s.
In summary, the Smart Turning Mechanism for Obstacle Avoidance Car stands
as a testament to the power of simple, thoughtful design and its potential to dr
ive advancements in autonomous technology. Through its blend of real-time o
bstacle detection, decision-making, and motion control, this project highlights t
he future of smart navigation systems, paving the way for a safer and more int
elligent approach to both robotics and autonomous vehicle development.