When it does not switch
Start with the LED. It lights from VCC through the closed contacts, whatever the sketch does, so it splits every fault in two: dark means the magnet, VCC or GND; lit means the SIGNAL wire, the pin number or pinMode. Then the magnet's position, and debouncing if it counts.
The LED first
The LED sits on SIGNAL and gets its current from VCC through the switch. It does not need your board's pin, or a sketch, to light. So before looking at code, hold a magnet to the glass and watch it.
Pick what you see. The board shows what the LED does in that case, and the verdict says where to look.
Dark: magnet, VCC, GND
If the LED stays dark with a magnet on the glass, either the switch did not close or the block has no power. Lay the magnet along the tube and flat on it; a magnet pointed straight at the middle can fail to close it. Then count from the square pad: GND, VCC, NC, SIGNAL. VCC goes to your board's logic voltage, GND to GND.
Lit: the wire and the sketch
If the LED lights and the sketch says LOW, the block is fine. SIGNAL is on a
different pin from the one the sketch reads, or on NC. If the sketch says
HIGH all the time, look for INPUT_PULLUP, or a GND wire that is not
there.
Flickers and missed counts
Several changes for one pass of the magnet are bounce, or a magnet sitting
at the edge of its range: debounce, and mount the magnet closer.
Missed changes on something fast mean a delay() in the loop, or a speed
beyond what a mechanical switch should be asked for: the switch is rated
to 100 closings a second.
When it does not work
The switch is not closing or the block has no power. Lay the magnet along the tube, flat on it, and try both ends. Then count from the square pad, GND, VCC, NC, SIGNAL, and check VCC goes to 3V3 or 5V and GND to GND.
The switch works and the block has power; the level is not reaching your pin. Check SIGNAL is on the pin REED_PIN names, and that the wire is not on NC, which is connected to nothing.
Something holds SIGNAL up: INPUT_PULLUP instead of INPUT, GND not connected so nothing holds it down, or a magnet nearby you have not noticed, such as a speaker or a phone case clasp. The LED tells the last one apart: it is lit.
The tube may be cracked. A cracked reed switch can look whole and still never close, or never open. The LED shows which: dark with a magnet, or lit without one.
A chip instead of contacts: nothing to wear or bounce, active low, and it needs power all the time.
The other magnet sensor: the TK18 Hall Effect Sensor →Edit this page — content/books/reed-switch/when-it-does-not-switch.mdx
Questions about this product
See what other owners have asked, and read their solutions.
Reed Switch
Loading discussions…
Discuss this article
Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.