Introduction
This is the MQ-2 smoke sensor module. It is sensitive to flammable gases such as LPG, propane, and methane.
In this guide, we will learn to connect it to the micro:bit and program it to sound an alarm, if it goes above the threshold level. When it is below the threshold level, a heart icon will be displayed instead.
Complete this guide to understand the basics on how to connect and program a smoke sensor with the micro:bit.
-
-
-
-
-
-
-
-
-
-
-
let threshold = 0 let sensorVal = 0 basic.forever(function () { sensorVal = pins.analogReadPin(AnalogPin.P1) threshold = 800 if (sensorVal > threshold) { music.playTone(262, music.beat(BeatFraction.Whole)) basic.showIcon(IconNames.Sad) } else { basic.showIcon(IconNames.Heart) } })
-