The pull-down and the light
Open, the 10 kΩ ties SIGNAL to GND and the block draws nothing. Closed, SIGNAL is VCC, and current runs down the 10 kΩ and through the LED: about 1.6 mA at 3.3 V, 3.5 mA at 5 V, all from VCC and none from your pin. Read it with INPUT, never INPUT_PULLUP.
A switch needs something on the other side
A switch on its own gives your pin two states: joined to VCC, or joined to nothing. Joined to nothing, a pin floats, picks up whatever is nearby, and reads HIGH or LOW at random. The 10 kΩ from SIGNAL to GND is there so that "nothing" means 0 V. That is a pull-down, and it is why this board is active high: the resistor holds LOW, and the switch overrules it with VCC.
Close the switch and follow the dashes. Current comes in at VCC, through the contacts, and splits: 0.33 mA down the 10 kΩ at 3.3 V, and about 1.3 mA down the 1 kΩ and the LED. None of it comes from your pin, which only reads the voltage. The contacts are rated at 0.1 Ω at most, so they drop well under a millivolt of it.
The light shows the switch
The LED is on SIGNAL, fed through the switch, so it lights when the contacts close and not a moment otherwise. It does not need a sketch, or even a microcontroller: VCC and GND alone are enough to see it work. When something is wrong, that splits the fault in two, which when it does not switch uses.
INPUT, not INPUT_PULLUP
The pull-down is already on the board, so the pin needs no resistor of its
own: pinMode(pin, INPUT). INPUT_PULLUP adds the chip's internal pull-up,
which pulls the other way against the 10 kΩ while the switch is open. On an
ESP32 that lifts the open level to about 0.6 V and wastes a few tens of
microamps. On an Uno, with the pull-up at the strong end of its 20 to 50 kΩ
range, it reaches about 1.7 V, more than the 1.5 V the pin promises to read
as LOW. INPUT_PULLDOWN on an ESP32 is harmless; it only adds a second
pull-down.
Nothing while open
VCC goes to the switch and nowhere else, so while it is open the block draws nothing. That makes it a good partner for a sleeping ESP32: the pin can wake the chip on HIGH, and nothing on the block runs while it waits. Closed, it draws about 1.6 mA at 3.3 V for as long as the magnet stays, so put it where the long-lasting state is the open one.
When it does not work
The pin's own pull-up and the board's 10 kΩ pull-down then fight while the switch is open. On an ESP32 the open level rises to about 0.6 V, still LOW; on an Uno it can reach about 1.7 V, which the pin does not promise to read as either. Use pinMode(pin, INPUT).
No. The LED and its 1 kΩ draw their current from VCC through the closed switch, not from your pin. Your pin only measures the voltage, and it sees VCC less a fraction of a millivolt.
A door sensor usually has the magnet on the door, so the switch is closed, and drawing about 1.6 mA at 3.3 V, the whole time the door is shut. Mount it so the switch is open in the state that lasts longest, and it draws nothing then.
Why VCC goes to 3V3 on an ESP32 and 5V only on an Uno.
VCC is your logic voltage →Edit this page — content/books/reed-switch/the-pull-down-and-the-light.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.