The Classroom Heat Trend Display
Change the slider level and observe the 5x5 LED display.
- Web browser (Chrome, Edge, Firefox)
- Internet connection
- MakeCode (micro:bit) online editor
🔧 Build Your Heat Trend Display
let prevTemp = input.temperature()
basic.forever(function () {
basic.pause(3000) // Sample interval: 3 seconds
let currentTemp = input.temperature()
let delta = currentTemp - prevTemp
if (delta > 0.5) {
basic.showArrow(ArrowNames.North) // Warming trend
} else if (delta < -0.5) {
basic.showArrow(ArrowNames.South) // Cooling trend
} else {
basic.showIcon(IconNames.Square) // Stable temperature
}
prevTemp = currentTemp
})
A 0.5°C deadband prevents the trend arrow from flipping erratically due to baseline sensor noise.
⚗️ Test your model
| Test Condition / Action | Expected Result |
|---|---|
| Touch sensor with warm fingers | Temp increases > 0.5°C -> Displays Up Arrow (North) |
| Blow gentle cool air on board | Temp decreases < -0.5°C -> Displays Down Arrow (South) |
| Ambient room temperature steady | Delta within ±0.5°C -> Displays Steady Square |
Connect an alert buzzer that sounds when the warming trend persists for three consecutive sample intervals!
📖 Our Story & Concepts
Displaying a static number like "31°C" tells you where you are, but it cannot tell you where you are going. If the classroom was 25°C thirty minutes ago, 31°C indicates an alarming rapid heat spike! If it was 36°C earlier, 31°C indicates great cooling progress.
By subtracting the previous reading from the current reading, microcontrollers compute rate of change (differential analysis). Environmental controllers in server rooms, poultry farms, and grain silos rely on directional trend analysis to activate ventilation fans before heat reaches fatal levels.
</> Full Annotated Code Walkthrough
// Complete Time-Series Thermal Comparator
let prevTemp = input.temperature()
let consecutiveWarming = 0
basic.forever(function () {
basic.pause(2500)
let currentTemp = input.temperature()
let delta = currentTemp - prevTemp
if (delta > 0.5) {
basic.showArrow(ArrowNames.North)
consecutiveWarming += 1
if (consecutiveWarming >= 3) {
music.playTone(440, music.beat(BeatFraction.Whole))
}
} else if (delta < -0.5) {
basic.showArrow(ArrowNames.South)
consecutiveWarming = 0
} else {
basic.showIcon(IconNames.Square)
consecutiveWarming = 0
}
prevTemp = currentTemp
})
A 0.5°C deadband prevents the trend arrow from flipping erratically due to baseline sensor noise.
▷ Expected Results & Troubleshooting
| Test Condition / Action | Expected Result |
|---|---|
| Touch sensor with warm fingers | Temp increases > 0.5°C -> Displays Up Arrow (North) |
| Blow gentle cool air on board | Temp decreases < -0.5°C -> Displays Down Arrow (South) |
| Ambient room temperature steady | Delta within ±0.5°C -> Displays Steady Square |
⚑ Extension Challenges & Blueprints
- Level 1: Press Button A to scroll the exact numeric delta difference across the screen.
- Level 2: Store an array of the last 5 readings to calculate a 15-second moving slope.
- Level 3: Activate a miniature 5V DC cooling fan when warming trend exceeds 2°C per minute.