Obstacle Avoiding Car

by 689515 in Circuits > Arduino

412 Views, 0 Favorites, 0 Comments

Obstacle Avoiding Car

20220620_124511.jpg

In this project, I am going to explain how to make an obstacle avoiding car with an Arduino.

Function of the Circuit

When the Arduino loads the code, it will be waiting for the user to press the pushbutton to make the car start moving. Once the button is pressed, the motors will start moving which will allow the car to move forward. While the car is moving, the distance sensor will constantly measuring the distance between the car and any obstacle in front of it. When the distance is less than 30 cm, the red LED will turn on and the car will turn in its spot and continue moving forward. If the user wants to stop the car, they simply have to press the pushbutton again.

Understanding Components:

LEDs: Anode (power/positive) and cathode (ground/negative) are the two sides of an LED. In this circuit, the anode is connected to the Arduino. A 330 Ω resistor is connected to the cathode of the LED. If there is no resistor, the LED would burn out.

Pushbutton: When a pushbutton is pressed, a small metal spring within contacts two wires, letting electricity to flow. When the switch is not pressed, the spring goes back, contact is disrupted, and current cannot flow through it.

Ultrasonic Distance Sensor: An electronic device that measures the distance of a target object by emitting ultrasonic sound waves, and converts the reflected sound into an electrical signal.

DC Motor: A direct current (DC) motor is a type of electric machine that converts electrical energy into mechanical energy. DC motors take electrical power through direct current, and convert this energy into mechanical rotation.

H-Bridge: An H-bridge is used to drive a load, such as a brushed DC motor, in both directions. And it controls the flow of current to a load.

Make the Circuit on Tinkercad

materials.png

To make it easier to figure out wiring, lets make the circuit on Tinkercad first.

Gather Materials:

*Links to the products have been attached (as of June 17th 2022). Prices and availability might change.*

Connect the Components

Start by grabbing the Arduino and connect the 5V pin to the bottom power rail. Then connect the GND (ground) pin to the bottom ground rail. Connect the top ground rail with the bottom ground rail with a black wire. Next, place the H-Bridge on the breadboard. Connect the "Enable 1&2" pin to pin 6 on the Arduino. Then connect the "Input 1" pin to pin 4 on the Arduino. Connect the two "Ground" pins to the negative rail on the breadboard. Grab 1 DC motor and connect the negative side to the "Output 1" pin. Connect the positive side to the "Output 2" pin. Then connect the "Input 2" pin to pin 7 on the Arduino. Connect the "Power 2" pin to the top power rail. Moving onto the other side of the H-Bridge, connect the "Power 1" pin to the bottom power rail. Then connect the "Input 4" pin to pin 13 on the Arduino. Again, connect both "Ground" pins to the negative rail on the breadboard. Grab the second DC motor and connect the negative side to the "Output 4" pin. Connect the positive side to the "Output 3" pin. Then connect the "Input 3" pin to pin 12 on the Arduino. Lastly, connect the "Enable 3&4" pin to pin 11 on the Arduino.

Next take the distance sensor and place it on the breadboard. connect the "VCC" pin to the bottom power rail. Connect the "GND" pin to the negative rail on the breadboard. Next, connect the "TRIG" pin to pin 8 on the Arduino. Then, connect the "ECHO" pin to pin 9 on the Arduino. Now, place the pushbutton on the breadboard. Connect terminal 1a to the bottom power rail. Connect terminal 2b to the ground rail through a 10kΩ resistor. Then connect terminal 2a to pin 5 on the Arduino. Place the potentiometer on the breadboard. Connect Terminal 1 to the bottom power rail. Connect terminal 2 to the ground rail. Then connect the "Wiper" pin to pin A0 on the Arduino. Lastly, place the LED on the breadboard. Connect the cathode to the ground rail through a 330Ω resistor. Then connect the anode to pin 10 on the Arduino.

Copy This Circuit in Real Life

20220620_124500.jpg

After testing on Tinkercad with the code below, create the circuit in real life! Grab the same materials and connect the components the same way from the last step. To power the Arduino, use a power bank. Tape down the components on the car chassis to avoid things from moving around.

Code

Copy the code into the "code" section on Tinkercad when you make the circuit on Tinkercad. Then copy this code to an Arduino file when making the circuit in real life. Read the comments to understand what each line means.

Final Product

20220620_124508.jpg

I hope this helped you make an obstacle avoiding car! You can always modify the code and add/take away components as you wish. Have fun building!