Welcome to Building:bit Superkit repository
2.7 Temperature and humidity broadcaster
Temperature and humidity reminder
Temperature and humidity reminder1. Learning objectives2. Building blocks3. Sensor wiring4. Code analysis5. Write and download the program6. Experimental phenomenon
1. Learning objectives
In this course, we mainly learn how to implement the temperature and humidity reminder function through Python programming.
2. Building blocks
For the steps of building blocks, please refer to the installation drawings of [Assembly Course]--[Temperature humidity reminder] or the building block installation brochure in the materials.
3. Sensor wiring
The temperature and humidity sensor is connected to the P1P2 interface.

4. Code analysis
For the program of this course, please see the Temperature-and-humidity-broadcaster.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: display.show(Image.HEART) sleep(500) display.scroll(WOM_Sensor_Kit.WOM_dht11(pin1, WOM_Sensor_Kit.WOM_temp_C)) if WOM_Sensor_Kit.WOM_dht11(pin1, WOM_Sensor_Kit.WOM_temp_C) > 25: music.play(music.DADADADUM) display.show(Image.CONFUSED) sleep(500) display.scroll(WOM_Sensor_Kit.WOM_dht11(pin1, WOM_Sensor_Kit.WOM_humidity)) if WOM_Sensor_Kit.WOM_dht11(pin1, WOM_Sensor_Kit.WOM_humidity) > 60: music.play(music.WAWAWAWAA)In an infinite loop, display the heart pattern and wait for 0.5 seconds, scroll the Celsius temperature value obtained by the temperature and humidity sensor (pin1), and if the temperature is greater than 25°C, play the prompt sound DADADADUM; display the puzzled face pattern and wait for 0.5 seconds, scroll the humidity value obtained by the temperature and humidity sensor (pin1), and if the humidity exceeds 60%, play another prompt sound WAWAWAWAA.
5. 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 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 in 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, and 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.
6. Experimental phenomenon
After the program runs successfully, the dot matrix displays a heart, and then displays the current temperature. When the temperature value is higher than 25 degrees, the music dadadum is played. If it is not reached, it will not be played.
Then a puzzled expression is displayed, and then the humidity is displayed. If the humidity value is greater than 60, the music wawawawaa is played. If it is not reached, it will not be played.