Obstacle-avoiding robot car
A small two-wheel robot that drives on its own and turns away from walls using an ultrasonic sensor.
Beginnerโฑ 8โ12 hours๐ช 7 stepsArduinoUltrasonic sensorMotor driver
What you'll learn
- โDistance measurement with HC-SR04
- โDC motor control with a driver (L298N/TB6612)
- โState machines for robot behaviour
What you'll build
- โDrives forward until something is close
- โScans left and right with a servo and picks the clearer side
- โSpeed control with PWM
- โBluetooth manual mode (optional)
Step-by-step guide
- 1
Chassis
2WD chassis kit, Arduino, motor driver, HC-SR04 on an SG90 servo, battery pack (do not power motors from the Arduino 5V pin).
- 2
Motors
Write forward(), backward(), left(), right(), stop() with direction pins and analogWrite for speed.
- 3
Distance
Trigger pulse, pulseIn on echo, distance_cm = duration * 0.0343 / 2; add a timeout.
- 4
State machine
States: FORWARD โ (obstacle < 20 cm) โ STOP โ SCAN โ TURN โ FORWARD.
- 5
Scan
Turn the servo to 30ยฐ and 150ยฐ, measure both, turn towards the larger distance.
- 6
Tune
Adjust speeds and turn times on the floor you will demo on.
- 7
Document
Circuit diagram (Fritzing or KiCad), code on GitHub and a demo video.
๐ Make it stand out
- +Line following with IR sensors
- +Bluetooth control from a phone (HC-05)
- +PID speed control