How to get a temperature reading

The micro:bit has a built-in temperature sensor that can detect the current temperature of the device, in degrees and Celsius. The temperature reading from the device can then be accessed in both MakeCode and Python.

The micro:bit temperature sensor

How to code it

MakeCode


input.onGesture(Gesture.Shake, function () {
	basic.showNumber(input.temperature())
})
		

Read the docs

파이선(Python)


from microbit import *

while True:
    if accelerometer.was_gesture('shake'):
        display.scroll(temperature())
		

Read the docs

How it works

The micro:bit does not have a dedicated temperature sensor. Instead, the temperature provided is actually the temperature of the silicon die on the main CPU. As the processor generally runs cold though (it is a high efficiency ARM core), the temperature is a good approximation of the ambient temperature.

Example projects

  • This idea is programmed in MakeCode
  • This idea is programmed in Python

Design a food temperature probe

In this unit of learning, learners will use the BBC micro:bit to develop a prototype for a food temperature probe that will warn people when their food is too cold.
Visit external link

  • This idea is programmed in MakeCode
  • This idea is programmed in Python

Temperature reading Hackster Make

By the end of this project, you will be able to know how to read temperature using BBC micro:bit.
hackster.io external link

  • This idea is programmed in MakeCode

Code an on-shake temperature sensor

This project uses one of the on-board sensors and a gesture control to display the real world temperature.
Visit external link
Selecting this opens external content from our support system, which adheres to their privacy policy.