Welcome to Building:bit Superkit repository
2.5 Infrared detection broadcast
Infrared detection broadcast
Infrared detection broadcast1. Learning objectives2. Sensor wiring3. Code analysis4. Write and download the program5. Experimental phenomenon
1. Learning objectives
In this course, we mainly learn how to display infrared detection broadcast through python programming.
2. Sensor wiring
The infrared module is connected to the P5P11 interface. 
3. Code analysis
For the program of this course, please see the Infrared-detection-broadcast.py file.
from microbit import *import WOM_Sensor_Kitimport musicFirst, import the libraries needed for this lesson from microbit: WOM_Sensor_Kit library is used for sensors; music library is used to play music.
xxxxxxxxxxwhile True:if WOM_Sensor_Kit.WOM_ir(pin5) == 0:display.show(1)music.play(music.JUMP_UP)else:display.show(0)Read the state of the infrared sensor connected to pin5 in an infinite loop and give corresponding feedback: when an infrared signal is detected (value is 0), the number 1 is displayed and a "jump" sound effect JUMP_UP is played; if no infrared signal is detected (value is 1), the number 0 is displayed and no sound effect is played.
4. Write and download the program
- Open the Mu software and enter the code in the editing window. Note! All English and symbols should be entered in English mode, use the Tab key (tab key) for indentation, and the last line ends with a blank program.
- Click the thumb 'Check' button to check if there are any errors in our code. If a cursor or underline appears on a line, it means a syntax error. Please check and modify it. If there is no error, the lower left corner will prompt that there is no problem with the detection.

- Click the 'REPL' button to check whether the Superbit library has been downloaded. If not, please refer to [Preparation before class] --> [2.4 Python Programming Guide].

- After the program is written, connect the computer and the microbit mainboard with a microUSB data cable. Please click the 'Flash' button to download the program to the micro:bit mainboard. (You need to click the 'REPL' button again to turn off the import library file function before you can download the program normally).

- If the download fails, please confirm whether the microbit is properly connected to the computer via the microUSB data cable and the Superbit Python library has been imported.
5. Experimental phenomenon
After the program runs successfully, when an obstacle is detected, the microbit dot matrix displays 1 and plays the jump up music, otherwise it displays 0.