Skip to content

Activity

Indoor-outdoor thermometer

Intermediate | MakeCode, Python | Buttons, LED display, Radio, Temperature sensor | Communication, Input/output, Radio waves, Temperature, Variables

Step 1: Make it

What is it?

Use two micro:bits so you can monitor outdoor temperatures remotely.

Introduction

Coding guide

How it works

  • This project uses two different programs, one for the outdoor micro:bit which senses the temperature and transmits it on radio group 23.
  • The outdoor micro:bit uses its temperature sensor to measure how hot or cold it is.
  • It uses radio to send this temperature reading to the indoor micro:bit.
  • When the indoor micro:bit receives a temperature reading from outside, it stores it in a variable called outdoorTemp.
  • When you press input button A on the indoor micro:bit, it shows its own current temperature reading on its LED display output.
  • When you press button B, it shows the temperature reading from outside that it has stored in the outdoorTemp variable.

What you need

  • Two micro:bits
  • MakeCode or Python editor
  • battery pack
  • A waterproof container, such a plastic box

Step 2: Code it

Outdoor sensor and transmitter:

1from microbit import *
2import radio
3radio.config(group=23)
4radio.on()
5
6while True:
7    radio.send(str(temperature()))
8    sleep(5000)
9

Indoor sensor and receiver:

1from microbit import *
2import radio
3radio.config(group=23)
4radio.on()
5outdoorTemp = '-'
6
7while True:
8    message = radio.receive()
9    if message:
10        outdoorTemp = message
11    if button_a.was_pressed():
12        display.scroll(str(temperature()))
13    if button_b.was_pressed():
14        display.scroll(outdoorTemp)
15        

Step 3: Improve it

  • Make the batteries last longer by having the outdoor micro:bit turn its radio off when it’s not in use and sending temperature readings less often.
  • Use variables to track the highest and lowest temperatures recorded.
  • Calibrate the readings against another thermometer to see if you need to adjust the micro:bit’s temperature.