The Classroom Heat Trend Display

JSS 1 MakeCode micro:bit Simulation first Temperature Comparator
Simulation lab
Board: BBC micro:bit
Open MakeCode ↗
Simulator preview
☀️ 80

Change the slider level and observe the 5x5 LED display.

📁 Tools ▴
  • Web browser (Chrome, Edge, Firefox)
  • Internet connection
  • MakeCode (micro:bit) online editor

🔧 Build Your Heat Trend Display

1 Sample ambient classroom temperature every 3 seconds using the micro:bit silicon sensor.
2 Calculate rate of change: 'delta = current_temp - previous_temp'.
3 Incorporate a 0.5°C noise deadband to prevent trend jitter during minor fluctuations.
4 Display an Up Arrow for warming, a Down Arrow for cooling, and a Steady Square for stable conditions!
🧩 Block plan / Starter code ▴
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 / ActionExpected Result
Touch sensor with warm fingersTemp increases > 0.5°C -> Displays Up Arrow (North)
Blow gentle cool air on boardTemp decreases < -0.5°C -> Displays Down Arrow (South)
Ambient room temperature steadyDelta within ±0.5°C -> Displays Steady Square
⚑ Try a challenge

Connect an alert buzzer that sounds when the warming trend persists for three consecutive sample intervals!

❓ Quick check
How does the BBC micro:bit measure ambient room temperature without an external thermometer attached?

📖 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 / ActionExpected Result
Touch sensor with warm fingersTemp increases > 0.5°C -> Displays Up Arrow (North)
Blow gentle cool air on boardTemp decreases < -0.5°C -> Displays Down Arrow (South)
Ambient room temperature steadyDelta within ±0.5°C -> Displays Steady Square

⚑ Extension Challenges & Blueprints

⚑ Extension Challenges
  • 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.

❓ Check Your Understanding

Question 1: How does the BBC micro:bit measure ambient room temperature without an external thermometer attached?

Question 2: What is the purpose of storing 'previous_temp' alongside 'current_temp' in our program?

Question 3: Why is a 'Deadband' (e.g., ignoring tiny fluctuations of less than 1°C) important in environmental monitoring?

Question 4: What icon should the micro:bit display if current_temp is significantly greater than previous_temp?

Feedback appears after you check your answer.