In this activity, you'll create a simple thermostat program using the micro:bit's temperature sensor. Your program will show different images based on whether it's too hot, too cold, or just right.
BBC micro:bit
New project at https://python.microbit.org/v/3
Create a program that:
Reads the current temperature from the micro:bit
Shows different images based on the temperature:
Down arrow if it's too hot
Up arrow if it's too cold
Smiling face if it's in the right range
Here's the basic structure of your program:
from microbit import *
# Define your temperature thresholds here
while True:
# Get the current temperature
temp = temperature()
# Your code here:
# Show the appropriate image based on the temperature
# Add a delay to prevent too rapid updates
sleep(1000)
The Image class has pre-defined images you can use
Use if, elif, and else statements to check the temperature against your thresholds
You can use display.show() to display an image
Once your basic thermostat is working, try these challenges:
Display the current temperature when a button is pressed
Display temperature or indicators in a different way. E.g. a rising and falling bar
Play a warning tone when the temperature is outside of the right range