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
This is how the final car is seen avoiding obstacle and calibrating when to move forward / backward and when to turn
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 :-)
You need these Components
Car’s Engine — Microcontroller and Shield
- 1 — Arduino UNO Microcontroller
- 1 — Motor Driver Shield L293D
Car’s Brain — Software Component
- Sketch .ino file for obstacle avoidance car : https://github.com/stratbeans/sketch_arduino_obstacle_avoidance_car/blob/master/sketch_arduino_obstacle_avoidance_car.ino
Car Chassis
- 1 — Rectangular Cardboard Box — to form the chassis
Locomotion — Motors
- 2 — DC Motors (BO — 150 RPM) with Dual Shaft Casing and Yellow/Black Wheels
- 1 — Servo Motor SG90 with attachments
- 1 — Caster Wheel
Eyes — Ultrasonic Sensors
- 1 — Ultrasonic Sensor HC-SR04
Wiring Support
- 1 — Screw Shields Terminal Expansion Board — Optional, it helps in avoiding soldering on Motor Shield
- 1 — Mini Bread Board for ease of connection for motor and batteries
- Couple of Male/Male, Male/Female Connector Wires
- GPIO pins — Optional
Powering Up — Battery and family !
- 1 — Battery Holder 6 Cell AA (For powering up Arduino UNO on 9V)
- 6 — AA 1.5 V Chargeable Battery
- 1 DC power jack
- 1 — 9 Volt Battery
- 1 — 9V Chargeable Li-Ion Battery for Powering up Motor Shield
- 1 — 9V battery clip
Tinkering Weapons
- Glue Gun
- 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)
Important point to note is that you should remove the power jumper on shield
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.
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
- Servo pins have to be put properly in the motor driver Servo channel 1, which is attached to Uno’s digital pin 10
- 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 ?
Writing the word ‘Obstacle Avoidance Car’ is quite cumbersome, allow me to call it OAC.
There could be many reasons for creating OAC, it can be one of the reason
- 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
- 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
- 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