All onboard sensors, how to access them in MakeCode and MicroPython, and calibration notes for classroom use.
| Sensor | What It Measures | Range | MakeCode Block | MicroPython |
|---|---|---|---|---|
| Temperature | CPU die temperature (°C) | -5 to 50°C | input.temperature() | temperature() |
| Accelerometer | Motion / tilt (x, y, z) | ±2g default | input.acceleration(Dimension.X) | accelerometer.get_x() |
| Compass | Magnetic heading (°) | 0–359° | input.compassHeading() | compass.heading() |
| Light Level | Ambient light via LED matrix | 0–255 | input.lightLevel() | display.read_light_level() |
| Microphone (V2) | Sound level (dB approx) | 0–255 | input.soundLevel() | microphone.sound_level() |
| Touch Logo (V2) | Capacitive touch | Boolean | input.logoIsPressed() | pin_logo.is_touched() |
| Buttons | A, B, A+B press | Boolean | input.buttonIsPressed(Button.A) | button_a.is_pressed() |
The temperature sensor reads the CPU die temperature, not ambient air temperature. It typically reads 3–8°C higher than the actual room temperature, and the offset varies by device and workload.
Classroom fix: Have students measure the offset by comparing the micro:bit reading to a known thermometer, then subtract the offset in code. This is a real engineering calibration exercise!
let offset = input.temperature() - KNOWN_ROOM_TEMP
basic.forever(function () {
let calibrated = input.temperature() - offset
basic.showNumber(calibrated)
})
On first use, the micro:bit displays "TILT TO FILL SCREEN" — tilt the board to light up all LEDs. This calibrates the magnetometer. Nearby magnets, metal desks, and electronics can interfere.
The light sensor works by briefly reversing the LED matrix to sense ambient light. This means the display flickers very briefly during readings. In a dark room, readings may be inaccurate if the LEDs are actively displaying something bright.
The built-in MEMS microphone is new in V2. It measures sound level (loudness), not frequency or pitch. Values are relative (0–255), not calibrated to actual decibels. Good for "loud vs. quiet" experiments, not precise acoustic measurement.
| Project | Sensors Used | NGSS Connection | Grade Band |
|---|---|---|---|
| Greenhouse Monitor | Temperature + Light | PS3.D: Energy in Chemical Processes | 6–8 |
| Earthquake Detector | Accelerometer | ESS3.B: Natural Hazards | 6–8 |
| Noise Pollution Map | Microphone + Buttons | ESS3.C: Human Impacts | 3–5 |
| Compass Navigator | Compass + Accelerometer | PS2.A: Forces and Motion | 6–8 |
| Light Intensity Experiment | Light Level | PS4.B: Electromagnetic Radiation | 6–8 |
| Step Counter | Accelerometer | LS1.A: Structure and Function | 3–5 |
| Comfort Index | Temperature + Light + Sound | ETS1.B: Developing Solutions | 9–12 |
| Feature | MakeCode | MicroPython |
|---|---|---|
| Interface | Block-based (drag & drop) or JavaScript | Text-based Python |
| Editor URL | makecode.microbit.org | python.microbit.org |
| Best for | Beginners, visual learners, K–8 | Text-ready students, 6–12, CS courses |
| LLM Support | Ask LLM for "MakeCode JavaScript" — translates well to blocks | Ask LLM for "MicroPython for micro:bit" — specify V2 for mic/touch |
| Deployment | Download .hex, drag to MICROBIT drive | Flash directly from editor, or download .py |