Find a way to drive the simulator Rover into the green parking lot. Use the colour or ultrasonic sensor to help find the safe zone. Watch out though, go too far and you’ll fall and get spiked!
Spike Drop in the Robot Simulator
Setup
This activity requires no physical setup, just make sure the Code Editor is connected to the Robot Simulator. If you’re unsure how to set up the Robot Simulator, see the getting started guide.
Our Approach
Solution 1: Ultrasonic Sensor

Example code, ultrasonic-based stop
This solution uses the ultrasonic sensor. Use a Repeat While loop, but instead of leaving it on true, repeat while the ultrasonic sensor detects a number larger than 55. Once the Rover detects the warning wall suspended above the spikes within 55 cm, it’s directly in the safe zone and can stop moving.
Solution 2: Colour Sensor

Example code, colour-based stop
This solution is more dynamic and uses the colour sensor, it works better if you move the Rover and it needs to detect green multiple times within the one program. The program doesn’t end on green; it keeps checking the colour. Use an IF / ELSE statement inside a While True loop, looking for green. Instead of ending the loop, just keep telling the motors to stop moving when green is detected; any other colour keeps the forward movement going.




