Introduction
A reed switch is an electrical switch which is operated when a magnetic field is brought near to it.Â
In this guide, you will learn how to connect it to the micro:bit and turn an LED as well as an alarm on and off. We will then test it with a magnet.
Complete this guide and use it to create a security alarm system. Most alarm systems use a magnetic reed switch on doors and windows. They may come in different forms and styles, but they operate using the same principle!
-
-
-
-
-
-
-
-
-
-
-
-
-
let signal = 0 pins.setPull(DigitalPin.P1, PinPullMode.PullUp) basic.forever(function () { signal = pins.digitalReadPin(DigitalPin.P1) if (signal == 0) { music.playTone(262, music.beat(BeatFraction.Whole)) basic.showIcon(IconNames.Angry) basic.showNumber(signal) } else if (signal == 1) { basic.showIcon(IconNames.Heart) basic.showNumber(signal) } })
-
let signal = 0 pins.setPull(DigitalPin.P1, PinPullMode.PullUp) basic.forever(function () { signal = pins.digitalReadPin(DigitalPin.P1) if (signal == 0) { music.playTone(262, music.beat(BeatFraction.Whole)) basic.showIcon(IconNames.Angry) pins.digitalWritePin(DigitalPin.P2, 1) basic.pause(500) pins.digitalWritePin(DigitalPin.P2, 0) basic.pause(500) } else { basic.showIcon(IconNames.Heart) } })
-