Smart Home Temperature Control System With Micro:bit

In this project, learners explore how smart homes use technology to improve comfort and save energy using a Micro:bit and temperature sensors. They monitor room conditions and control devices like fans or air conditioners, connecting coding, robotics, and electronics to real-life environments. We have included extra challenges that encourage learners to experiment with different settings, making learning fun and interactive. Through this hands-on experience, learners develop creativity, problem-solving skills, and decision-making abilities. The project also introduces AI ideas, showing how smart systems can learn temperature patterns, predict comfort needs, and optimize energy use efficiently.

ItemPurpose
Micro:bitThe brain of your smart home system.
DHT11 SensorMeasures the temperature and sends data to the micro:bit.
3V Relay ModuleActs as a switch that turns the fan or air conditioner ON/OFF safely.
Fan or Air ConditionerProvides cooling when the temperature gets high.
Red LEDLights up when the temperature is too high.
Green LEDLights up when the temperature is normal.
Jumper WiresUsed to connect all components.
Breadboard (optional)Helps organize and connect components neatly.
USB CableFor connecting the micro:bit to your computer.

Let’s look at how each part connects:

DHT11 Sensor

  • VCC → connects to 3V on Microbit
  • GND → connects to GND on Microbit
  • Data → connects to Pin 8 on Microbit

Red LED

  • Long leg → connects to Pin 1 on Microbit
  • Short leg → connects to GND on Microbit

Green LED

  • Long leg → connects to Pin 2 on Microbit

  • Short leg → connects to GND on Microbit

3V Relay Module

  • VCC  → connects to 3V on Microbit
  • GND → connects to  GND on Microbit
  • IN → connects to  Pin 0 on Microbit

On the relay output side (the high-current side):

  • The COM terminal connects to the positive terminal of the external battery.
  • The NO (Normally Open) terminal connects to the positive wire of the fan/AC.
  • The fan’s negative wire connects directly to the negative terminal of the external battery.

AC/ Fan

  • Positive (+) terminal → connect to the NO (Normally Open) pin on the relay module
  • Negative (–) terminal → connect to negative (–) terminal of external the battery

Follow these steps carefully to open and explore the project in Microsoft MakeCode for Micro:bit:

Plug in your Micro:bit to your computer using a USB cable, then follow the steps in the video to upload your code and bring your project to life!

Code BlockWhat It Does
set temperature to 0Creates a variable called temperature and sets its starting value to 0.
foreverRepeats all the blocks inside continuously to monitor temperature all the time.
set temperature to temperature (°C)Reads the built-in temperature sensor on the micro:bit and stores the value in the temperature variable.
show number temperatureDisplays the current temperature value on the LED screen.
pause 1000 msWaits 1 second before checking the temperature condition.
if temperature > 30 thenChecks if the temperature is higher than 30°C, meaning it is too hot.
digital write pin P0 to 1Turns ON the fan or relay connected to pin P0.
digital write pin P1 to 1Turns ON the red LED to show high temperature.
digital write pin P2 to 0Turns OFF the green LED.
elseRuns when the temperature is 30°C or below (normal temperature).
digital write pin P0 to 0Turns OFF the fan or relay.
digital write pin P1 to 0Turns OFF the red LED.
digital write pin P2 to 1Turns ON the green LED to show safe temperature.
pause 2000 msWaits 2 seconds before repeating the temperature check.

  • If the fan doesn’t start, check the relay’s input pin connection.

  • If both LEDs are OFF, make sure the logic and pin assignments are correct.

  • Adjust the temperature threshold (20°C - 30°C) to suit your environment.

  • How to use a DHT11 sensor with the BBC micro:bit.
  • How to control a relay module to switch ON/OFF real devices.
  • How to automate temperature control in a smart home.
  • How to code logic for real-world automation.

  • Try adding a buzzer to beep when the temperature gets too high!
  • Display the temperature reading on the micro:bit LED screen.
  • Replace the Relay module with L298N Motor Driver and control the speed of the fan or AC

Use either Micro:bit's CreateAI or Edge Impulse to build, train, and deploy machine learning (ML) models to make the smart home system think ahead. The AI can learn from temperature changes and predict what will happen next.

For Example:

  • Comfort Predictor: The Micro:bit observes how the room temperature changes during the day and predicts when it will become too hot or too cold.

  • Smart Fan Helper: Before the room gets too warm, the AI turns on the fan or AC automatically.

  • Happy Home Lights: LEDs change color to show the AI’s prediction  red for “getting hot,” and green for “just right.”

  • Fun Test Game: Students guess the temperature change and see if the AI was right.