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.

Micro:bit温度传感器

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

在本学习单元中,学生们将用BBC micro:bit来开发一个食物温度探测仪的原型,提醒人们食物太冷了。
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

这个项目使用一个板载的传感器和一个手势控件来显示现实世界的温度。
Visit external link
Selecting this opens external content from our support system, which adheres to their privacy policy.