Reed switch (magnet) with TinkerPie
Put the magnet on a door and the switch on the frame: door alarms.
| Type | Digital sensors |
|---|---|
| Connect to | any accessory pin (switch to GND) |
| Gives | true when a magnet is near |
| Simulator | Yes: a control appears under the simulated board |
How it works
A reed switch has two thin metal contacts inside a small glass tube. A magnet nearby pulls them together and closes the switch. Fix the magnet on a door and the switch on the frame to know if the door is open.
How to wire it
Signal (DO / OUT / S) to any accessory pin: S1-S4, P10-P13, P43 or P44. Power from 3.3 V where the module allows it.
Code
In blocks: Accessories category in TinkerPie Studio. As code:
// JavaScript
sensors.reedSwitch(Pin.S1)
// Arduino C++
sensors::reedSwitch(Pin::S1) Good to know
- Needs no power of its own.
- Works when the magnet is within about 1-2 cm.
- The glass tube is fragile: do not bend the legs close to it.
Projects with the Reed switch (magnet)
Similar modules
- PIR motion sensor HC-SR501
- IR obstacle sensor
- Touch sensor TTP223
- Push button module
- Tilt switch SW-520D
- Vibration sensor SW-420
- Hall effect sensor A3144
- Line tracker TCRT5000
More projects to try
Questions
Can I try the Reed switch (magnet) without buying one?
Yes. In TinkerPie Studio the simulator shows a control for it under the board, so you can test your program before you build it.
Reed switch or Hall sensor: which is better?
Both notice magnets. The reed switch is simple and great for doors and windows; the Hall sensor has no moving parts and is better for fast counting, like wheel turns.