A reed switch is triggered by a magnet. It is usually used above door as a buglar alarm.
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.
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.
compass.get_field_strength()returns the magnetic field in nano teslas.
Published: December 23, 2016 Updated: December 23, 2016