When it does not switch
Start by closing the sensor yourself: touch its two wires together. SIGNAL is then joined to VCC, so the LED must light and the pin must read HIGH. That splits every fault in two: no light means VCC, GND or the screws; light with no HIGH means the pin, the pull-down or the sketch; and it works only with the wires touched means the sensor or its magnet.
Close it yourself
Before looking at the code, take the sensor out of the question. Touch its two bare wires together, or put a short wire across the terminal's two screws. That is a closed switch, and the board cannot tell it from the real one.
With the switch closed, SIGNAL is VCC. So the LED has to light, whatever the sketch does, and a pin set to a pull-down has to read HIGH.
No light: VCC, GND, the screws
If the LED stays dark with the wires touched, the board has no VCC or GND, or SIGNAL is not joined to VCC. Count from the square pad: GND, 3V3, NC, SIGNAL. VCC goes to your board's logic voltage, GND to GND. Then the screws: a wire that is only caught by its insulation does not touch the terminal.
The LED being dark with the door open and the real sensor connected is normal. It is not a power light.
Light: the pin and the sketch
If the LED lights and the sketch says LOW, the board is fine. SIGNAL is on a
different pin from the one the sketch reads, or on NC, or the pin is the
wrong sort of pin. If the sketch says HIGH all the time, look for
INPUT_PULLUP, or a sensor of the other kind.
The sensor, the magnet and the wire
If it works with the wires touched and not with the sensor, the fault is the sensor, the magnet or the wire. Hold the magnet to the sensor's face. Check the wire's ends under the screws. If the LED follows the magnet but the count goes wrong, that is bounce, or a door at the edge of the magnet's range: debounce, and mount the magnet closer.
When it does not work
Then SIGNAL is not reaching VCC, or the LED has no GND. Check VCC and GND on the header, count from the square pad, and look at the screws: a wire caught by its insulation, not its copper, touches nothing.
The board works and the level is not reaching your pin. Check SIGNAL is on the pin DOOR_PIN names, that the wire is not on NC, and that your pin is not one of the board's input-only or strapping pins.
The pull-down is missing. Check setup() sets INPUT_PULLDOWN, that your pin has an internal one (GPIO 34 to 39 on the ESP32 have none), and, on an Uno, that the 10 kΩ from SIGNAL to GND is in.
Something holds SIGNAL up: INPUT_PULLUP instead of a pull-down, a sensor of the other kind that is closed when the magnet is away, or a magnet from a speaker or a phone case nearby. The LED tells the last two apart from the first.
A reed switch with its pull-down fitted, so a magnet reads HIGH with no line in setup().
The same sensor on a board of its own: the TK41 Reed Switch →Edit this page — content/books/door-sensor/when-it-does-not-switch.mdx
Questions about this product
See what other owners have asked, and read their solutions.
Door Sensor
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.