3. Case 03: Temperature-controlled Fans

3.1. Introduction

  • In a room with high temperature and dry air, our noses and throats are prone to dryness, congestion, pain, and sometimes nosebleeds. Also, people could become irritable, inattentive, poor accuracy and coordination with slower reaction speed in such a enviroment. What’s more, the body temperature regulation mechanism temporarily could become obstructed, and heat accumulation in the body occurs, which could lead to heat stroke easily, thus, a temperature-controlled fan could help a lot.

3.2. Function

  • Detect the temperature with the DHT11 sensor and display the value on the OLED screen, if the temperature is over the threshold, program to turn on the fan.

3.4. Picture


3.5. Hardware Connection

Connect the DHT11 sensor to P1, the motor fan to P2 and the OLED to IIC on sensor:bit.


3.6. Software Programming

Click “Advanced” in the MakeCode to see more choices.


For programming, we need to add a package: click “Extensions” at the bottom of the MakeCode drawer and search with “smarthome” in the dialogue box to download it.


Notice: If you met a tip indicating that some codebases would be deleted due to incompatibility, you may continue as the tips say or create a new project in the menu.

3.7. Program

Initialize the OLED display.

../../_images/microbit-Smart-Health-Kit-case-03-07.png Save the returned value as the variable “i” and display it on OLED screen.

../../_images/microbit-Smart-Health-Kit-case-03-08.png Judge the value of the variable “i”, if it’s over 29, program to turn on the fan; or to turn off. ../../_images/microbit-Smart-Health-Kit-case-03-09.png

Link: https://makecode.microbit.org/_7WLC6kVYXh9z

3.8. Result

  • Display the current temperature on the OLED, if the temperature is over 29℃, program to turn on the fan.