Take your maze solving to the next level. In this intermediate challenge you’ll use both IR sensors alongside the ultrasonic sensor to make smarter decisions at intersections and handle more complex maze layouts.

A more complex maze setup with T-intersections
Setup
Construct mazes with narrower pathways than in Maze I. Aim for 5–10 cm clearance on each side of the Rover. Include T-intersections and dead ends to force the Rover to make more complex decisions.
Building On Maze I
In Maze I we used the ultrasonic sensor to check ahead and one IR sensor to decide which way to turn. This worked for simple mazes but falls apart when the maze has more complex intersections. Now we’ll use both IR sensors to check left and right before deciding where to turn.
Stage 1: Check All Directions
Create variables for the wall distance on each side. Read both the left and right IR sensors as well as the ultrasonic sensor at each step. This gives the Rover a complete picture of its surroundings.
WALL = 10 # cm, distance below this counts as a wall
while True:
front = Ultrasonic.read()
left = IR.readLeft()
right = IR.readRight()Stage 2: Smarter Turning
With data from all three distance sensors, the Rover can make better decisions at intersections. Instead of always preferring left or right, prioritise based on which direction has more open space. Use nested IF / ELSE IF / ELSE blocks to handle the different combinations.
if front > WALL:
# No wall ahead, keep moving forward
Motors.write(20)
else:
Motors.write(0)
if left > right:
Motors.turnDegrees(-90) # left has more space
else:
Motors.turnDegrees(90) # right has more spaceStage 3: Add the Colour Sensor
Use the colour sensor to detect a coloured finish line at the end of the maze. When the Rover detects the finish colour, it should stop and celebrate with LEDs or a buzzer sound.
# Stop on green finish line
if Colour.readSensor(option=Colour.CS.HUE, sensor=1) > 80 and \
Colour.readSensor(option=Colour.CS.HUE, sensor=1) < 160:
Motors.write(0)
LEDs.setAll(0, 255, 0)
Sounds.play(Sounds.TUNES.UP)
break
