Micro:bit MicroPython: Getting temperature

In this tutorial we will learn how to obtain temperature measurements using the Micro:Bit board.


In this tutorial we will learn how to obtain temperature measurements using the Micro:Bit board.

It’s important to mention that we are not going to need any additional sensor. Instead, we are going to use Micro:bit’s built in temperature measurement capabilities.

Nonetheless, the Micro:bit also doesn’t contain any dedicated temperature sensor. Thus, we will use the temperature sensing feature integrated in the nRF51822¬†chip that the Micro:bit contains.

This feature allows to obtain the chip die temperature [1]. Note however that the values obtained from these measurements are typically higher than the room temperature because they are also affected by the temperature of the electronics [2].

The code

The first thing we are going to do is importing the microbit module. Upon importing this module, we should have access to the function that allows to measure the temperature.

import microbit

Now that we have imported the module, we simply need to call the mentioned function that returns the temperature measurement. This function is called temperature and takes no arguments [3].

As output, the temperature function returns the measured temperature, in degrees Celsius [3]. Thus, we can directly print the output of this function call.


The final code can be seen below.

import microbit


Testing the code

To test the code, simply run the previous script on your Micro:bit board, using a tool of your choice. I’ll be using uPyCraft, a MicroPython IDE. Upon running the code, you should get an output similar to figure 1, which shows the measured temperature.

As already mentioned in the introductory section, we should be careful interpreting this value since it corresponds to the nRF51822 chip die temperature, which is expected to be higher than the room temperature, due to the heating generated by the electronics.

Micro:bit MicroPython getting temperature

Figure 1 – Output of the script, with the temperature measurement.


[1] https://lancaster-university.github.io/microbit-docs/ble/temperature-service/

[2] https://microbit-challenges.readthedocs.io/en/latest/tutorials/thermometer.html

[3] https://microbit-micropython.readthedocs.io/en/latest/microbit.html#microbit.temperature

Leave a Reply

%d bloggers like this: