Distance Sensing Car
This project is a car that was inspired by our projects using the dc motor and the distance sensor. The circuit is meant to move in a direction at adjustable speeds and go back when it detects an object closer than 10 inches.
Step 1: Parts List
- Breadboard
- Arduino
- Potentiometer
- 2 LED's (Red and Green)
- 2 DC motors
- 9V battery
- H-Bridge
- Ultrasonic Distance Sensor
- 3 Resistors (1Kohm, 1 Kohm, 10 Kohm)
- PushButton
- Jumper Wires
Step 2: Building the Circuit
The circuit is built by connecting all the components to the Arduino and breadboard. The 2 dc motors are connected to the h-bridge. The input pins are connected to the Arduino using the digital pins. The distance sensor, potentiometer, and pushbutton are also connected to the digital pins and power and ground. The digital pins you choose do not matter as long as they align with your code.
Step 3: Building the Code
The code is very simple. You need to state variables at the top and which digital pins you used for each component. I did not need any functions because all of it was done in the loop and setup. There needs to be if statements for when an object is closer than 10 inches. This means when an object is detected, the motors simply go in the opposite direction until the object is out of range. There also needs to be an if statement for which the pushbutton is pressed in order to turn the motors off.
Step 4: Making Sure Everything Works
In this final step, you just need to upload your code to the Arduino and test it out. The motors should only start spinning once the pushbutton is pressed and will switch its direction as soon as the distance sensor detects something closer than 10 inches. The potentiometer should be adjusting the speed of the 2 motors as well. If these do not work, there could either be a problem with the code or the actual circuit. make sure the components are wired correctly and in the correct digital pins.