Lets Create Obstacle Avoiding Car using Arduino

This is a complete tutorial on both hardware and software code for Arduino based obstacle avoidance car using Servo Motor, DC Motor and Ultrasound Sensor

Lets begin at the end and see the demo

GIF of Final Obstacle Avoiding Car in Action !

Yes, cut as many points in the looks department but its surely makes it up in the feel department, as it runs like a beast, avoids collision turns around with a swag :-)

Top view of the car
Top view of the car
Top view of car
Front view of the car
Front view of the car
Front view of Car

You need these Components

Car’s Engine — Microcontroller and Shield

  1. 1 — Motor Driver Shield L293D

Car’s Brain — Software Component

Car Chassis

Locomotion — Motors

  1. 1 — Servo Motor SG90 with attachments
  2. 1 — Caster Wheel

Eyes — Ultrasonic Sensors

Wiring Support

  1. 1 — Mini Bread Board for ease of connection for motor and batteries
  2. Couple of Male/Male, Male/Female Connector Wires
  3. GPIO pins — Optional

Powering Up — Battery and family !

  1. 6 — AA 1.5 V Chargeable Battery
  2. 1 DC power jack
  3. 1 — 9 Volt Battery
  4. 1 — 9V Chargeable Li-Ion Battery for Powering up Motor Shield
  5. 1 — 9V battery clip

Tinkering Weapons

  1. Soldering Iron

Lets do it step wise

Step 1 : Preparing the Chassis Box, putting DC and Servo motors

Here we are using the cardboard box and fixing the caster wheel, DC motor wheel and the Servo motor

Step 2 : Wiring the motor shield power line and motor channels

If you are aware of how L293D, it is great otherwise you can as well refer to this tutorial

We are using channel M3 and M4 of Motor Shield (We could have as well used M1, M2 — it was just an arbitrary choice)

Location of M3, M4 channel on Motor Shield

Important point to note is that you should remove the power jumper on shield

Power supply for Motor Shield and place where jumper has to be removed

Step 3: About Battery Power setup and a few tricks

The above video talks about merits of using chargeable battery for power hungry DC motor circuits like above.

Battery Pack of 6 for 9V and Single 9V battery and DC power jack

Techniques for soldering the jumper pin shared as a practical tip

Step 4: Scaffold for mounting Ultrasound Sensor on Servo and attaching shield to Arduino

In this step, we shared how to attach the servo blade with Ultrasonic Sensor so that, servo can move the sensor is various direction.

Also Motor shield was connected to Arduino

First level of bringing together all engines on the car body

Step 5: Integrating the motors, sensors and motherboard all together

This step showed how to electronically connect Servo motors, Ultrasound sensor and Motors to the mother board.

Some of the key points where as follows

  1. Servo pins have to be put properly in the motor driver Servo channel 1, which is attached to Uno’s digital pin 10
  2. Ultrasound Sensor, making use of unused Servo channel 2, pin which is connected to Uno’s digital pin 10

3. Emphasized use of Screw shield for ease of use of unused pins, to avoid soldering pin 13 on shield

4. Breadboard is optional but helps correct the rotation of motor

Step 6: Transferring the sketch to Arduino and make the car run

End Note : The Joy of creating an obstacle avoiding car ?

There could be many reasons for creating OAC, it can be one of the reason

  1. You want to Learn about IoT or Arduino and want to make use of sensors (Ultrasound sensor) and get your hand dirty with Servo and DC motor
  2. You are crazy about AI powered Autonomous car and this is like a super super first step, making a car that is intelligent enough to avoid obstacle
  3. Tinkering, it something you love and you can engage with your friends, family or kids and partner with them as you construct this.

I personally had a great time with my 6 year old kid, as he was fully my client, suggesting what to do further !

Hope you enjoy rigging up the OAC and post back if you face any challenge following the steps above. Reach out at prasoon at stratbeans.com

Technologist for 20+ Years. CTO of product Company. IIT Kanpur, India Alumnus