Lesson 11: Building Your First Autonomous Robot

Course: Robotics & Arduino Lesson 11 of 12

Combine motors, ultrasonic sensor and decision logic for autonomous obstacle avoidance.


Learning Objectives

By the end of this lesson you will be able to:


Hardware Required

See the Kit List on the course overview page for the full component list. For this lesson you will specifically need the components mentioned in the steps below.


Step-by-Step Guide

  1. Review the complete chassis wiring: motors, L298N, HC-SR04, Arduino and battery.
  2. Write the getDistance() helper function that returns distance in cm.
  3. Write forward(), backward(), turnLeft(), turnRight(), stopAll() motor functions.
  4. Main loop: int d = getDistance(); if(d > 20) { forward(); } else { avoidObstacle(); }
  5. Write avoidObstacle(): stop → back up 300ms → stop → turn right 500ms → check distance → repeat if needed.
  6. Upload and test in an open area. Does the robot navigate without hitting walls?
  7. Tune the distance threshold (20cm) and turn duration (500ms) for your environment.
  8. Add a mount for the ultrasonic sensor — tilt it slightly downward to detect low obstacles.
  9. Test on a maze: create a simple cardboard maze and time how long to escape.
  10. Add an LED status indicator: green = clear, red = obstacle detected.

Extension Challenges


Review Questions

  1. Explain in your own words what this lesson’s main component does.
  2. What would happen if you changed one key parameter in your sketch?
  3. How does this lesson’s content connect to the final robot build in Lesson 12?

Troubleshooting Tips


Back to Course Next: Lesson 12