← Back to CRAFT PD Series

micro:bit V2 Sensor Guide & NGSS Crosswalk

Every onboard sensor with specs, MakeCode blocks, MicroPython code, classroom activity ideas, and NGSS alignment. All code is tested in both the MakeCode online simulator and on real hardware. In Workshop 3 we pair any of these sensors with the Aggregator Node pattern to build a two-device IoT system — sender on one simulated micro:bit, receiver on a second — with no hardware required.

🌡️ Temperature Sensor V1 + V2
Range-5°C to 50°C
Resolution1°C
LocationCPU die (not ambient!)
⚠️ Calibration note: This sensor reads the CPU temperature, which runs 3-8°C warmer than ambient air. This is a real engineering calibration problem — perfect for the Fortify phase.
MakeCode MicroPython
basic.forever(function () {
    basic.showNumber(input.temperature())
    basic.pause(2000)
})

MakeCode blocks: forever → show number → temperature (°C) → pause 2000ms

from microbit import *

while True:
    display.scroll(temperature())
    sleep(2000)

Activity Ideas

MS-PS3-4Plan an investigation to determine how temperature changes when hot and cold objects are in contact.
MS-ESS2-6Compare micro:bit readings in sun vs shade to explore weather data collection.
💡 Light Sensor V1 + V2
Range0 – 255
TypeLED matrix (reverse-biased)
UnitArbitrary (not lux)
⚠️ Note: The "sensor" is actually the LED display running in reverse — it measures current generated by light hitting the LEDs. Values are relative, not calibrated lux. Good enough for "brighter/dimmer" comparisons.
MakeCode MicroPython
basic.forever(function () {
    led.plotBarGraph(input.lightLevel(), 255)
    basic.pause(500)
})

MakeCode blocks: forever → plot bar graph of → light level → up to 255 → pause 500ms

from microbit import *

while True:
    light = display.read_light_level()
    display.scroll(light)
    sleep(1000)

Activity Ideas

4-PS4-2Develop a model to describe that light reflecting from objects enters the eye. Compare readings from different surfaces.
MS-PS4-2Investigate how light intensity changes with distance (inverse square law exploration).
📐 Accelerometer V1 + V2
Range±2g (default)
AxesX, Y, Z
Gesturesshake, tilt, freefall, face up/down
MakeCode MicroPython
// Show acceleration strength on LED bar
basic.forever(function () {
    let strength = input.acceleration(Dimension.Strength)
    led.plotBarGraph(strength, 2048)
    basic.pause(100)
})
from microbit import *
import math

while True:
    x = accelerometer.get_x()
    y = accelerometer.get_y()
    z = accelerometer.get_z()
    strength = math.sqrt(x**2 + y**2 + z**2)
    display.scroll(int(strength))
    sleep(500)

Activity Ideas

MS-PS2-2Plan an investigation with the accelerometer to show that changing force on an object changes its motion.
HS-PS2-1Analyze accelerometer data from a cart on a ramp to verify F=ma.
🧭 Magnetometer / Compass V1 + V2
Range0° – 360°
SensitivityDetects magnets and magnetic fields
CalibrationRequired on first use (tilt to fill circle)
MakeCode MicroPython
basic.forever(function () {
    let heading = input.compassHeading()
    if (heading < 45 || heading > 315) {
        basic.showString("N")
    } else if (heading < 135) {
        basic.showString("E")
    } else if (heading < 225) {
        basic.showString("S")
    } else {
        basic.showString("W")
    }
})
from microbit import *

compass.calibrate()
while True:
    heading = compass.heading()
    if heading < 45 or heading > 315:
        display.show("N")
    elif heading < 135:
        display.show("E")
    elif heading < 225:
        display.show("S")
    else:
        display.show("W")
    sleep(200)

Activity Ideas

MS-PS2-3Use compass readings to detect magnetic field strength near different magnets.
5-ESS1-2Build a compass and use it for a mapping/navigation challenge.
🎤 Microphone V2 Only
Range0 – 255 (sound level)
Eventsloud, quiet thresholds
LED IndicatorRed dot on front
MakeCode MicroPython
// Sound level meter
basic.forever(function () {
    led.plotBarGraph(input.soundLevel(), 255)
    basic.pause(100)
})
from microbit import *

while True:
    level = microphone.sound_level()
    display.scroll(level)
    sleep(500)

Activity Ideas

MS-PS4-1Use sound level data to model how amplitude relates to energy of a wave.
4-PS4-1Develop a model of waves showing patterns — measure classroom noise at different times.
👆 Touch Logo V2 Only
TypeCapacitive touch
LocationGold logo on front
Eventspressed, released, long press
MakeCode MicroPython
input.onLogoEvent(TouchButtonEvent.Pressed, function () {
    basic.showIcon(IconNames.Heart)
})
input.onLogoEvent(TouchButtonEvent.Released, function () {
    basic.clearScreen()
})
from microbit import *

while True:
    if pin_logo.is_touched():
        display.show(Image.HEART)
    else:
        display.clear()
    sleep(100)
🔘 Buttons A & B V1 + V2

Two physical buttons plus the ability to detect A+B pressed simultaneously. Useful for user input, mode switching, and data logging triggers.

MakeCode MicroPython
// Simple counter
let count = 0
input.onButtonPressed(Button.A, function () {
    count += 1
    basic.showNumber(count)
})
input.onButtonPressed(Button.B, function () {
    count = 0
    basic.showNumber(count)
})
from microbit import *

count = 0
while True:
    if button_a.was_pressed():
        count += 1
        display.scroll(count)
    if button_b.was_pressed():
        count = 0
        display.scroll(count)
    sleep(100)

NGSS Crosswalk: IoT Activities ↔ Standards

ActivitySensorsNGSS StandardGrade BandCTE Pathway
Temperature data logging (sun vs shade)TemperatureMS-ESS2-6: Weather & climate data6-8STEM, Environmental Tech
Light intensity vs distance investigationLightMS-PS4-2: Light wave properties6-8STEM
Shake detector / motion alarmAccelerometerMS-PS2-2: Force and motion6-8Engineering, Manufacturing
Classroom noise monitorMicrophoneMS-PS4-1: Wave amplitude & energy6-8STEM, Health Science
Plant growth light monitorLight + TemperatureMS-LS1-6: Photosynthesis6-8Agriculture, Environmental
Ramp acceleration experimentAccelerometerHS-PS2-1: Newton's Second Law9-12Engineering, Physics
Navigation compass challengeCompass5-ESS1-2: Earth's position3-5STEM
Earthquake shake table modelAccelerometerMS-ESS3-2: Natural hazards6-8Engineering, Geoscience
Multi-sensor weather stationTemp + Light + SoundMS-ESS2-5: Weather data collection6-8Environmental Tech, Data Science
Comfort index (temp + light + noise)Temp + Light + MicrophoneMS-ETS1-4: Design optimization6-8Architecture, Building Tech

Multi-Sensor Combo Projects (Workshop 3 Breakout)

🌿Combo 1: Greenhouse Monitor (Temperature + Light)

Alert when temperature is above 30°C AND light level is below 50 (door closed, overheating risk).

MakeCode MicroPython
basic.forever(function () {
    let temp = input.temperature()
    let light = input.lightLevel()
    if (temp > 30 && light < 50) {
        basic.showIcon(IconNames.Sad)
        music.playTone(880, 500)
    } else {
        basic.showIcon(IconNames.Happy)
    }
    basic.pause(1000)
})
from microbit import *
import music

while True:
    temp = temperature()
    light = display.read_light_level()
    if temp > 30 and light < 50:
        display.show(Image.SAD)
        music.play(["A5:500"])
    else:
        display.show(Image.HAPPY)
    sleep(1000)
🏃Combo 2: Motion + Direction Tracker (Accelerometer + Compass)

Show compass direction only when the device is moving (shake detected). Stationary = show "—".

MakeCode MicroPython
let moving = false
input.onGesture(Gesture.Shake, function () {
    moving = true
})
basic.forever(function () {
    if (moving) {
        let heading = input.compassHeading()
        if (heading < 45 || heading > 315) { basic.showString("N") }
        else if (heading < 135) { basic.showString("E") }
        else if (heading < 225) { basic.showString("S") }
        else { basic.showString("W") }
        moving = false
    } else {
        basic.showString("-")
    }
    basic.pause(500)
})
from microbit import *

compass.calibrate()
while True:
    if accelerometer.was_gesture("shake"):
        heading = compass.heading()
        if heading < 45 or heading > 315:
            display.show("N")
        elif heading < 135:
            display.show("E")
        elif heading < 225:
            display.show("S")
        else:
            display.show("W")
    else:
        display.show("-")
    sleep(300)
📊Combo 3: Classroom Comfort Index (Temp + Light + Sound)

Score 0-9 based on: temperature (20-25°C ideal), light level (100-200 ideal), noise level (below 80 ideal). Display score on LED.

MicroPython
from microbit import *

def comfort_score():
    score = 0
    # Temperature: ideal 20-25C
    t = temperature()
    if 20 <= t <= 25: score += 3
    elif 18 <= t <= 28: score += 2
    else: score += 0
    # Light: ideal 100-200
    light = display.read_light_level()
    if 100 <= light <= 200: score += 3
    elif 50 <= light <= 250: score += 2
    else: score += 0
    # Sound: ideal below 80
    sound = microphone.sound_level()
    if sound < 80: score += 3
    elif sound < 150: score += 2
    else: score += 0
    return score

while True:
    s = comfort_score()
    display.show(str(s))
    sleep(2000)

CRAFT PD Series · UCF DRACO Lab & School of Teacher Education