Reed Switch

A reed switch opens and closes in the presence of a magnet.

Typically they are usually open and closed when near a magnet.

The circuit and code for the reed switch is essentially the same as the button also covered in the components base.


Reed switches can come in many different forms. Both of those below are reed switches. A search on Amazon on eBay will reveal many more types but they all work the same way.

bare reed switch

The reed switch on the right is enclosed in two-part module. The upper module contains the reed switch, the lower part is the magnet to trigger the reed switch. These are usually found in burglar alarm systems.


The reed switch is connected to the microbit between pin0 and the 3v pin. The circuit is the same as the button example.


Scroll 'burglar' on display if reed switch is open (the magnet is not present; eg. the door is open)
from microbit import *

while True:
    if pin0.read_digital():
        # reed switch is closed.
        # magnet present
        # reed swich open
        # magnet not present



Share On
Facebook Twitter Google Plus

Published: December 23, 2016 Updated: December 23, 2016

Reed Switch

A reed switch is triggered by a magnet. It is usually used above door as a buglar alarm.

Jez Dean