r/microbit 15h ago

Standalone NFPA 72 smoke/CO alarm detector on a micro:bit V2 — pattern-matching, no ML

1 Upvotes

The micro:bit V2's onboard mic samples every 20ms, I threshold it into on/off runs, and match the run lengths against the T3 (smoke) and T4 (CO) temporal patterns that all US alarms are legally required to beep. Two full cycles required before it fires (~9s), which kills false positives from microwaves, battery chirps, etc. When it detects, it strobes all 25 LEDs.

No machine learning — just a ~80-line stopwatch. 67 tests, including one that extracts the matcher embedded in the firmware and proves it's byte-identical to the reference version so they can't drift.

Honest limitations I found on hardware: onboard mic range is short (few inches from a phone speaker), and T4 detection falls off a cliff above ~30ms timing jitter because the debounce eats the 100ms pulse — documented with a plot in the README.

https://github.com/ayaanrustagi/alarm-sentinel — feedback welcome, especially on extending mic range.