๐ŸŽ™ Free live masterclass ยท Sun, 29 Nov, 7:00 pm IST ยท Java Full Stack roadmap Register free โ†’
Skills101

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. 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. 2

    Motors

    Write forward(), backward(), left(), right(), stop() with direction pins and analogWrite for speed.

  3. 3

    Distance

    Trigger pulse, pulseIn on echo, distance_cm = duration * 0.0343 / 2; add a timeout.

  4. 4

    State machine

    States: FORWARD โ†’ (obstacle < 20 cm) โ†’ STOP โ†’ SCAN โ†’ TURN โ†’ FORWARD.

  5. 5

    Scan

    Turn the servo to 30ยฐ and 150ยฐ, measure both, turn towards the larger distance.

  6. 6

    Tune

    Adjust speeds and turn times on the floor you will demo on.

  7. 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