Step 1: Make it
What is it?
Track highest and lowest temperatures by leaving this program running on a micro:bit.
How it works
- Like the Thermometer project, this uses the temperature sensor inside the micro:bit’s CPU (central processing unit) to measure the temperature in °C (Celsius).
- This program keeps track of the lowest and highest temperatures recorded by using 3 variables: currentTemp is the current temperature reading, max is the maximum and min is the minimum.
- At the start of the program they are all set to the same value; an infinite (forever) loop ensures that every two seconds it takes a reading, and the program compares the current temperature with the max and min variables.
- If the current temperature is less than (<) than the value stored in the min variable, it changes the min variable to be the same as the current temperature.
- If the current temperature is greater than (>) the max variable’s value, it changes the max variable to be the same as the current temperature.
- The program also flashes a dot on the LED display every time the infinite loop runs so that you know it’s working.
- Press button A to show the minimum and button B to show the maximum temperatures recorded.
- You could leave the micro:bit running for 24 hours, record the maximum and minimum temperatures and plot on a chart at the same time every day and then reset.
What you need
- micro:bit (or MakeCode simulator)
- MakeCode or Python editor
- battery pack (optional)
- a source of heat or cooling, like a fan, if you want to see the temperature change quickly – or take the micro:bit outside
- graph paper if you want to keep a chart of temperatures over time
Step 2: Code it
Step 3: Improve it
- Compare the reading with another thermometer. How accurate is the micro:bit? Do you need to modify the micro:bit reading to get the air temperature? How could you do that?
- Convert the temperature to Fahrenheit.
- Use radio to send temperature readings to another micro:bit.
This content is published under a Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) licence.