In this microbit tutorial we will learn how to obtain temperature measurements using the Micro:Bit board.
Introduction
In this microbit 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.
print(microbit.temperature())
The final code can be seen below.
import microbit
print(microbit.temperature())
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.
https://techtutorialsx.com/2019/01/06/microbit-micropython-getting-temperature/