Navigate your Rover through a maze using the ultrasonic sensor to detect walls ahead and the IR sensor to check for walls to the side. This beginner approach introduces the fundamentals of maze solving with simple branching logic.
Setup
Construct mazes with any solid material that is tall enough for the Rover’s IR and ultrasonic sensors to detect. We use boxes or wooden blocks to create our walls. For this first level, keep pathways wide, at least 15 cm clearance on each side of the Rover to make it easier for students to get started.
Our Approach
This basic approach only uses the ultrasonic sensor and the left IR sensor.
Stage 1: Define the Wall Distance
Create a variable named wall that represents the distance (in cm) from the side of the Rover to the maze wall when the Rover is placed in the middle of a maze path.
Stage 2: Check Forward
With an IF / ELSE IF / ELSE block, first check if the Rover can move forward. If the ultrasonic sensor doesn’t detect anything closer than the wall value, move forward. Otherwise, there’s a wall in the way and it has to decide where to turn.
Stage 3: Turn Left or Right
The ELSE IF branch checks if the left IR sensor detects a wall. If not, the way is clear and the Rover turns left. If it does detect a wall, the ELSE case runs and the Rover turns right. Place the whole IF/ELSE IF/ELSE block in a While True loop so the behaviour repeats indefinitely.

Example code, basic maze-solving algorithm
