Obstacle detection
At the front of the JoyCar, two infrared obstacle sensors are installed. These sensors emit an infrared signal to the front, which, if it hits an obstacle, is reflected by it and recognized by the infrared receiver built into the sensor. Thereby the sensor sends a high signal (1) back to the micro:bit.
If there is no obstacle in front of the sensor, the IR signal is not reflected and the sensor returns a low signal (0). This allows the JoyCar to detect obstacles and avoid them automatically.
In this example program exactly this function is used.
If one of the obstacle sensors detects an obstacle, the motors of the JoyCar will be stopped, the JoyCar will reverse a little bit in a small curve and can then pass the obstacle in forwarding gear.
The obstacle detection can be switched on and off in this program, with button A.