Introduction: Obstacle Avoiding Car

An obstacle avoiding robot is an intelligent autonomous vehicle capable of detecting and avoiding object in it's path. Using an ultrasonic sensor and a motor system, the robot continuously scans its surrounding and make real-time decision to change direction whenever an obstacle is detected. This technology form the foundation of modern robotics and self-driving system, where safe and efficient navigation is essential. In this project, I designed and built a compact, reliable obstacle-avoiding robot that can move independently, sense its environment, and react smartly-making it an excellent beginner-friendly yet impactful robotics project.

Supplies

Components:

Hardware-

  1. Arduino Uno
  2. Servo Motor
  3. Ultrasonic Sensor
  4. L298N Motor Driver Module
  5. Li-on Batteries x3
  6. Battery holder
  7. Jumper wires
  8. Gear Motor x2
  9. Wheel x2
  10. Chassis Board

Software-

  1. Arduino IDE

Other needed stuffs:

  1. Double-sided tape
  2. Glue-gun
  3. Acrylic Board
  4. Scissors

Step 1: Introduction of Components

Arduino Uno:

The Arduino Uno is one of the most popular and beginner-friendly microcontroller boards used for electronics and robotics projects. It is built around the ATmega328P microcontroller, which makes it capable of reading inputs from sensors and controlling outputs like motors, LED's and displays.

With 14 digital Input/Output pins, 6 analog inputs, support communication protocols like I2C,SPI, and UART and USB connectivity.

Step 2:

Servo Motor:

A servo motor is a special type of motor designed for precise control of angular position, making it widely used in robotics, automation, and control system, unlike ordinary DC motors that keep rotating continuously, a servo motor rotated only within a fixed angle range (usually 0 degree to 180 degree) and stops exactly where we want it to.

  1. The VCC - Red Wire
  2. GND - Brown Wire
  3. Signal - Yellow


Step 3:

Ultrasonic Sensor:

The ultrasonic sensor is an electronic device that measures distance using sound waves. It works on the principle of echo location, just like bats and dolphins. The senso sends out a high-frequency ultrasonic sound wave that human ears cannot hear. When this wave hits an object, it bounces back to the sensor as an echo. by calculating the time taken for the echo to return, the sensor determines how far the object is.

Ultrasonic sensors are widely used in robotics, automation, security system, smart parking, obstacle detection, and many others application. They are popular because they are inexpensive, reliable, and work well in different lighting conditions, unlike infrared sensors which depends on light.

Step 4:

Motor Driver Module:

A motor driver module is an essential electronic component use to control and operate DC motors, servo motors, or stepper motors in robotics and automation projects. Microcontrollers like Arduino or ESP32 cannot directly drive motors because motors require higher current and voltage than what these boards can safely provide.

A motor driver works as a bridge between the microcontroller and the motors, allowing the controller to manage the motor's speed, direction, and movement safely. Most motor drivers use H-bridge circuit, which enables the motor to rotate forward or backward by changing the direction of current flow.

Motor drivers modules such as L298N, L293D are commonly used in projects like obstacle-avoiding robots, line followers, robotics cars, and home automation system. They are reliable, compact, and make it easy to connect multiple motors with proper power isolation and protection.

Step 5:

3.7V Li-on Battery:

A 3.7V Lithium-ion battery is a rechargeable battery widely used in portable electronics device and embedded system projects. Li-on batteries are preferred because they offer high energy density, light weight, and a longer lifespan compared to traditional batteries. These batteries provide a stable voltage output and can deliver enough current to power devices like robotic cars, IoT gadgets, sensors, and small motors.

Li-on batteries are safe and efficient when used with proper protection circuits and chargers. They recharge quickly and maintain their capacity well over multiple charge-discharge cycles, making them ideal for compact, battery-powered projects.


Battery Holder:

A battery holder is plastic or metal enclosure designed to securely hold batteries and provide a safe electric connection to a circuit. For a 3.7V Li-on cell, a special 18650 battery holder is commonly used. It ensures proper alignment of the battery terminals and makes it east to replace or remove the battery without soldering.

It prevents battery movement, and ensures reliable power delivery to the device. I also protects the battery from physical damage and ensures that the positive and negative ends connect correctly to the circuit.

Step 6:

Gear Motor:

Thee gear motor is a special type of motor that comes with an integrated gearbox to control speed and increase torque. While a regular DC motor spins very fast but with low torque, a gear motor reduces the speed using gears and delivers high torque, making it suitable for application that need strong rotational force.

Gear motors are widely used in robotics cars, obstacle-avoiding robots, automation system, conveyor belts, and mechanical device where controlled movement is required.

Step 7: Circuit Diagram

This is the connection of Arduino with Ultrasonic sensor and Arduino with Servo motor.

Step 8: Pin Connections

Ultrasonic Sensor to Arduino

  1. GND - GND
  2. VCC - 5V
  3. Trigger Pin - Pin 9 (GPIO)
  4. Echo Pin - Pin 8 (GPIO)

Step 9:

Servo Motor to Arduino

  1. Yellow Pin - Pin 10 (GPIO)
  2. Orange Pin - IOREF (Arduino)
  3. Brown Pin - GND (Arduino)

Generally IOREF pin not use while connecting servo motor with Arduino, But here I have used Motor Driver Module and Arduino uno as a Microcontroller.

Whenever we use Motor Drivers Modules/Driver Shields by Arduino, we can use IOREF pin.

But never power servo motor directly from IOREF pin, IOREF is for voltage reference, not a power.

Step 10:

Motor Driver Module to Arduino

The Arduino Pins:

  1. Pin 4
  2. Pin 5
  3. Pin 6
  4. Pin 7
  5. Arduino Vin - Motor Driver Module +12V Pin
  6. Arduino GND - Motor Driver Module GND Pin

The Motor Driver Module:

  1. We have to connect above 4 GPIO pins of Arduino to the 4 pins between ENA to ENB of Motor Driver Module.


Step 11:

Motor Driver Module

  1. ENA: Connect both header pins via single jumper wire.
  2. ENB: Connect both header pins via single jumper wire.

Step 12:

Battery Holder to Motor Driver Module

  1. Red wire - +12V
  2. Black wire - GND

(As those two pins already connected to Arduino's Vin, GND)

Step 13:

Gear Motor to Motor Driver Module

(I have used 2 gear motors in my project, you can use 4/ chassis board)

  1. Black wire - Output 2 (in driver module)
  2. Red Wire - Output 1 (in driver module)
  3. Black Wire - Output 4 (in driver module)
  4. Red Wire - Output 3 (in driver module)

Step 14: Working of Obstacle Avoiding Car

The main components that makes the Obstacle avoiding car work is the HC-SR04 Ultrasonic Sensor. This sensor relies the sound waves to figure out how far away object are in front of it. It's sensor used in many projects that need to quickly and easily measure the distance. Because of it's small body we can put anywhere in the car's body.

As I already mentioned all the components, When we done with all the hardware connections with Arduino, the Servo motor starts turning and checking the distance in three directions left, right, and front. Whichever direction has the more space, the car moves in that direction.

As soon as the car gets close to an obstacle., there's set distance programmed into the Arduino. If the obstacle is closer than this distance, the ultrasonic sensor tells the Arduino gets this signal, it tells the motor driver to stop the motors from turning. Then, the servo motor starts checking distance again in all three direction. Based on what it finds, it signals the motor driver to turn the car either left or right and the car turns accordingly. After that, the car goes forward again until it detect another obstacles. This whole process keeps happening until turn off the power or remove a battery.

Step 15: Project Code

I am sharing with you the full working code for the Arduino Obstacle Avoiding Car.


Step 16:

Step 17: Test Code

I am sharing the test codes of Ultrasonic Sensor and Servo motor. You can upload and run it to check the component working or not.


Step 18: Applications

Here are some applications of Arduino obstacle Detection Car-

  1. Automatic Toy Car
  2. Indoor Navigation Robot
  3. Schools and College Projects
  4. Learning Robotics Basics


Step 19: Conclusion

The Arduino-based obstacle detection car successfully demonstrates autonomous movement using an ultrasonic sensor, servo motor, and motor driver. The robot is able to detect obstacles in its path and change direction automatically, preventing collisions. This project helps in understanding the basics of robotics, sensors, and control, and serves as a strong foundation for more advanced autonomous and smart robotic system.