Skip to content

Activity

Thermometer

Beginner | MakeCode, Python | Buttons, LED display, Temperature sensor | Input/output, Sensors, Temperature, Weather & climate

Step 1: Make it

What is it?

Show how hot or cold your micro:bit is using the built-in temperature sensor.

micro:bit showing number 9 next to a thermometer icon

How it works

  • This program shows how hot or cold your micro:bit is by taking a reading from the temperature sensor in its processor or CPU (central processing unit).
  • The processor’s temperature is a fairly good approximation of the temperature around you in °C (Celsius).
  • In this program, when you press input button A, the micro:bit displays the processor’s current temperature on its LED display output.
  • Take the micro:bit into warmer and colder places and see how the temperature readings change.

What you need

  • micro:bit (or MakeCode simulator)
  • MakeCode or Python editor
  • battery pack (optional)
  • a source of heat or cooling, like a fan, if you want to see the temperature change quickly (optional)

Step 2: Code it

1from microbit import *
2
3while True:
4    if button_a.was_pressed():
5        display.scroll(temperature())
6

Step 3: Improve it

  • Compare the reading with another thermometer. How accurate is the micro:bit? Do you need to modify the micro:bit reading to get the air temperature?
  • Convert the temperature to Fahrenheit or Kelvin.
  • Use radio to make a remote sensor sending temperature readings to another micro:bit, for example from outside to inside. You could make an indoor / outdoor thermometer this way.