micro:bit Pocket Thermometer
The board measures the temperature with its built-in sensor and shows it as a rising column: each row is 5 degrees. Press button A and the temperature scrolls as a number. temperature reads the value. No extra parts are needed.

Video
Circuit Diagram

Source Code
1# ─────────────────────────────────────────
2# BlueGrays · bluegrays.com
3# micro:bit Pocket Thermometer
4# ─────────────────────────────────────────
5# The board measures the temperature with its built-in sensor and shows it
6# as a rising column: each row is 5 degrees. Press button A and the
7# temperature scrolls as a number. No extra parts are needed.
8#
9# Pins:
10# LED -> Onboard 5x5 LED display
11# P5 -> Onboard button A
12
13from microbit import *
14
15# ============ SETTINGS ============
16BASE_TEMP = 10 # Temperature of the bottom row (C)
17STEP_TEMP = 5 # Degrees per row
18CHECK_MS = 500 # Wait between readings (ms)
19
20
21# Lights 1 to 5 rows from the bottom up, depending on the temperature.
22def show_column(temp):
23 rows = (temp - BASE_TEMP) // STEP_TEMP + 1
24 rows = max(1, min(5, rows))
25 display.clear()
26 for row in range(rows):
27 display.set_pixel(2, 4 - row, 9)
28
29
30while True:
31 temp = temperature()
32 if button_a.was_pressed():
33 display.scroll(str(temp) + "C")
34 show_column(temp)
35 sleep(CHECK_MS)
36FAQ
Why is the temperature higher than the room's?
temperature reads a sensor inside the board's processor. The processor warms up a little while it runs, so the value can be a few degrees above room temperature. After the board has run for a while, compare it with a room thermometer and subtract the difference from the reading in the code.
Which temperatures does the column show?
The bottom row means 10 to 14 degrees and each row adds 5 degrees: two rows are 15 to 19, three rows 20 to 24, four rows 25 to 29 and five rows 30 and above. Below 10 degrees one row is still lit. You change the range with BASE_TEMP and STEP_TEMP.
How do I put this code on the micro:bit?
The code is MicroPython. Open the micro:bit Python Editor (python.microbit.org) on a computer, delete the code that is there and paste this one. Connect the board with a USB cable and press Send to micro:bit. If that button does not work, use Save to download the .hex file and copy it to the drive called MICROBIT. You can rebuild the same project with blocks in MakeCode, but this code cannot be pasted there.
Does it work on the older micro:bit (V1) too?
The code is written for the micro:bit V2. Projects that only use the LED display, buttons A and B and the accelerometer also run on a V1. The speaker, the microphone and the touch logo exist only on the V2, so code that uses them gives an error on a V1. If your board has a speaker on the back and a gold logo on the front, it is a V2.
