Lesson 5 of 7
Building a Simple Robot
Plan robot behaviour with flowcharts, pseudocode and simple control logic.
Learn it
A robot is a physical computer that can sense, decide and act on its own.
Most simple robots use a loop: read sensors, make a decision, move actuators, repeat.
Line-followers and obstacle-avoiders are classic beginner robot projects.
Key terms
- Control Loop
- A repeating cycle in which a robot senses, decides and acts.
- Line Follower
- A robot that follows a path using light or colour sensors.
- Obstacle Avoidance
- Robot behaviour that detects and steers around objects in its path.
- Pseudocode
- A plain-language description of a program's logic, not tied to a specific language.
Robot Decision Tree
A simple obstacle-avoidance flow.
- 1Start: Power on and begin the main loop.
- 2Sense: Measure distance to the nearest object ahead.
- 3Decide: If the distance is small, prepare to turn. Otherwise, drive forward.
- 4Act: Move motors for a short time, then repeat from Sense.
Line-Follower Pseudocode
pythonwhile True:
left = read_left_sensor()
right = read_right_sensor()
if left sees_line and not right sees_line:
turn_left()
elif right sees_line and not left sees_line:
turn_right()
else:
drive_forward()
sleep(50)The robot continuously checks two light sensors. It steers toward the side that sees the line, keeping it centred.
Try it
What will this robot do next?
pythondistance = read_distance()
if distance < 10:
backup()
turn_right()
else:
drive_forward()Challenge
Design pseudocode for a robot that drives around the edge of a room clockwise. It should follow the wall on its right side and turn corners smoothly.
Pick whichever way suits you — every mode earns the same bonus XP.
Write at least 40 more characters to submit.
Mark your own work
Guided walkthrough — 0/5 clues revealed
- Clue 1 locked — reveal it only if you get stuck.
- Clue 2 locked — reveal it only if you get stuck.
- Clue 3 locked — reveal it only if you get stuck.
- Clue 4 locked — reveal it only if you get stuck.
- Clue 5 locked — reveal it only if you get stuck.
Each clue costs 4 XP (never below 19 XP). You'd earn 38 XP right now.
Extension: What would go wrong if the robot's distance sensor was mounted on the left side instead of the right?