Introduction: Fully - Operational Obstacle Avoidance Car
I built an obstacle-avoiding robot car as a way to learn more about robotics and help others get started with simple autonomous systems. This Instructable explains how I put it together and how you can recreate or customize the design for your own projects.
Supplies
Popsicle Sticks - https://shorturl.at/BOPhv
Hot Glue Gun - https://shorturl.at/iX2e4
ELEGOO UNO R3 x2 - https://shorturl.at/h0VXX
Breadboard Starter Pack - https://shorturl.at/qg6IH
Portable Charger - https://rb.gy/l7tc36
Gearbox Motor/ Motor Wheel - https://h7.cl/1fDz3
Swivel Castor - https://h7.cl/1fDzp
Ultrasonic Sensor - https://h7.cl/1kuDV
4 AA Battery Holder - https://h7.cl/1fDzx
4x AA Battery - https://h7.cl/1fDzF
Attachments
Step 1: Gather All the Components
Before starting, collect all the parts you’ll need so the build goes smoothly. For this project, you’ll need popsicle sticks, a hot glue gun, an ELEGOO UNO R3 boards, a breadboard starter pack, a portable charger, a gearbox motor with motor wheels, a swivel castor, an ultrasonic sensor, a 4x AA battery holder, and four AA batteries. Having everything laid out in front of you will help you visualize the final build and avoid last-minute delays.
Step 2: Assemble the Car Chassis
Start by building the frame of your robot using popsicle sticks. Lay out the sticks to form a sturdy base and glue them together with the hot glue gun. Once the base is solid, attach the gearbox motor with motor wheels to the underside using glue or screws. Make sure the motors are aligned straight so the car drives forward smoothly. Add the swivel castor to the opposite end of the chassis so the robot can roll and turn easily.
Step 3: Mount the Ultrasonic Sensor
Attach the ultrasonic sensor to the front of the popsicle-stick chassis. You can glue it directly or build a small raised platform out of popsicle sticks so the sensor faces forward and stays stable. Make sure both sensor “eyes” are perfectly clear and pointing straight ahead for accurate distance readings.
Step 4: Wire the Electronics
Place the breadboard on the top of your chassis and mount your ELEGOO UNO R3 board nearby. Use jumper wires from your breadboard starter pack to connect everything:
- Connect the gearbox motor wires to the breadboard and arduino.
- Wire the ultrasonic sensor to the Arduino pins (Trig, Echo, 5V, GND).
- Connect power: your portable charger will power the Arduino boards through USB, while the 4x AA battery holder will power the motors separately.
- Keep all wires routed neatly so they don’t interfere with the wheels.
You may look at the attached visual aid for further assistance.
Step 5: Upload the Code
Connect each ELEGOO UNO R3 to your computer using USB cables. Open the Arduino IDE and upload your obstacle-avoidance code. Make sure the sensor pins in your code match the pins you actually wired. After uploading, keep everything connected so you can test the logic before running it on the ground.
I have attached below an example of what your code should look like or you can just copy it.
To edit the speed of the wheels you can use analogWrite instead of digitalWrite and put a umber between 1 and 225 to edit speed. As often both motor wheels won't have the same speed.
const int trigPin = 9;
const int echoPin = 10;
const int leftMotor = 3;
const int rightMotor = 5;
float duration, distance;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(leftMotor, OUTPUT);
pinMode(rightMotor, OUTPUT);
Serial.begin(9600);
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration*.0343)/2;
Serial.print("Distance: ");
Serial.println(distance);
delay(100);
digitalWrite(leftMotor, HIGH);
digitalWrite(rightMotor, HIGH);
if( distance < 40){
digitalWrite(leftMotor, LOW);
delay(2000);
}
}
Step 6: Test the Sensor and Motors
Before placing the robot down, lift it slightly so the wheels can spin freely. Power the Arduino using the portable charger, and power the motors using the AA batteries. Move your hand in front of the ultrasonic sensor to verify the car responds correctly—slowing, stopping, or turning depending on the distance. This confirms both your wiring and logic are correct.
Step 7: Troubleshoot and Adjust
If the car spins in circles, one side of the gearbox motor is likely wired backwards. If the sensor constantly reads wrong distance values, check if it's tilted or loose on the popsicle-stick mount. Re-check all wires on the breadboard, make sure the AA batteries are fresh, and ensure the portable charger is delivering power properly to the Arduino.
Step 8: Final Assembly and Cable Management
Use popsicle sticks and hot glue to secure the UNO boards, breadboard, and cables so nothing shakes loose while the robot moves. Keep wires tucked along the frame so they don’t touch the spinning wheels. A clean layout not only looks better but also prevents short circuits or accidental disconnects.
Step 9: Run the Car!
Place the robot on a flat surface, turn on the battery pack and portable charger, and watch it navigate! The ultrasonic sensor will scan for obstacles, and the rest of the system will steer the robot around objects automatically. Test it in different environments to see how well your design performs.


