door sensor/How it works/03. A switch between VCC and SIGNAL
How it works · 03 of 10

A switch between VCC and SIGNAL

The terminal puts the sensor between VCC and SIGNAL, and that is the whole circuit. Closed, SIGNAL is joined to VCC and reads HIGH. Open, SIGNAL is joined to nothing and floats. Nothing on the board draws current while the door is open; closed, the light draws a fraction of a milliamp.

One switch, two states

The sensor's two wires go under the two screws. One screw is on VCC, the other on SIGNAL. So the sensor is a plain switch between them.

A switch between VCC and SIGNAL
Sensor
VCC wired to
SIGNAL
floating
LED
dark
Taken from VCC
0 mA
Open, VCC reaches nothing and SIGNAL is connected to nothing. It is not 0 V and it is not LOW: it is floating, and the pin reads whatever it picks up. The LED is dark either way. Only a pull-down, which you add, makes open mean LOW.

Closed, the switch is a wire: SIGNAL is VCC, less a fraction of a millivolt, and your pin reads HIGH. Open, the switch is a gap, and SIGNAL is connected to nothing but the light's branch to GND, which does not conduct at that level. Nothing holds it up or down.

What is in the sensors

Every sensor in the box is a magnetic reed sensor, as the listing gives them: a switch in a small case that a magnet closes when it comes near. That is the same part inside the Reed Switch block, without the board around it: the glass tube and its leads are inside the plastic or the metal, and the two bare wires come out. Nothing in it needs power, and either wire can go to either screw.

What it draws

Open, VCC reaches the sensor's wire and nothing else, so the board takes no current at all. Closed, SIGNAL is at VCC and the light's branch conducts: about 0.25 mA at 3.3 V and 0.6 mA at 5 V, worked out, not measured. The pull-down you add (the next article) draws its own share while closed: VCC divided by its resistance.

A door is shut most of the day, so the closed current is the one that lasts. For a mains-powered board it is nothing. For a battery it is the number to keep small, and the larger the pull-down's resistance, the less it takes.

Why a closed switch is the active state

On this block HIGH means closed, and the sensor is closed while the magnet is beside it. A sensor mounted with the magnet on the door therefore reads HIGH while the door is shut. Which way is open works through that, because it depends on the sensor you have.

When it does not work

The sensor is open and the pin reads HIGH sometimes.

That is a floating pin, not a fault in the board: with the sensor open nothing holds SIGNAL at a level, so it can read either. Set the pin to a pull-down in setup(), as the next article shows, and it reads LOW.

Can I put VCC on 5V when my board is 3.3 V?

Not safely. The sensor passes on whatever VCC is, so with VCC on the 3V3 pin an ESP32's pin sees 3.3 V at most. Wire VCC to 5V on a 3.3 V board and the pin sees 5 V every time the door shuts.

Does the sensor need power to work?

No. A reed sensor is a switch closed by a magnet, with nothing inside to power. VCC is there so the closed switch has a level to pass to SIGNAL, and GND is there so the light and the pull-down have somewhere to go.

Where this goes next

What SIGNAL does while the sensor is open, and the one line that fixes it.

No pull-down on the board →

Edit this page — content/books/door-sensor/a-switch-between-vcc-and-signal.mdx

Community

Questions about this product

See what other owners have asked, and read their solutions.

Ask a question ↗

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.

Browse Modules and blocks on the forum →