Use the colour sensors to find and drive through the gap in the box. Rovers start in the middle facing a random direction and must leave through the gap, they cannot drive over the lines.
Setup
Use tape on a table or floor (or a printed arena) to create an outline. It doesn’t matter what colour the tape or surface is, as long as they contrast clearly so the colour sensors can detect them. Make sure the gap you leave in the wall is large enough for the Rover to move through.
The same code should work no matter where the Rover is placed to start. Don’t hard-code distances in your solution.
Our Approach
There are multiple ways to solve this challenge. This starter approach simply moves the Rover forward until it detects the wall. If it detects the wall, it reverses and changes direction. This cycle repeats until the Rover finds the exit. You can add randomness to the turning or some other strategy to find the exit faster.
Stage 1: Detect the Wall
Use an IF statement with a condition that checks if the colour sensor sees the tape (brighter than the floor). If the Rover detects tape underneath, it knows it has hit a wall, use motor blocks to go backwards, then turn.
Stage 2: Move Forward Otherwise
When the Rover doesn’t see the tape, use a motor block in the ELSE branch to move forward slowly.
Stage 3: Loop Forever
Wrap the whole behaviour in a While True loop so the Rover keeps trying until it finds the exit.

Example code, colour-sensor-based prison escape



