Open KidsBlock and connect the board to your computer. Click File –> Load from your computer.
Choose D:\Code\1.Code_kidsuno to open 4.5Temperature detection.sb3 file.
Click to connect to port and then click to upload the code.
Conceive:
Set three thresholds to separate the temperature range: 24, 29, 35, which are adjustable according to needs.
preference temperature: 24°C ~ 29°C
warning temperature: 29°C ~ 35°C
high temperature: over 35°C
Corresponding LED will light up when the ambient temperature is within the related ranges.
Within preference temperature range: the green LED lights up
Within warning temperature range: the yellow LED lights up.
Within high temperature range: the red LED lights up.
Code structure:
Initialization. Set the pins of XHT11 temperature and humidity sensor and the traffic light module.
Loop.
XHT11 sensor reads and outputs the temperature values.
Determine which section the temperature value is in, so then light up corresponding LED.
24°C ≤ temperature < 29°C: the green LED lights up and other LEDs are off.
29°C ≤ temperature < 35°C: the yellow LED lights up and other LEDs are off.
temperature > 35°C: the red LED lights up and other LEDs are off.