door sensor/How it works/04. No pull-down on the board
How it works · 04 of 10

No pull-down on the board

With the sensor open, nothing connects SIGNAL to anything, so a pin reading it floats and can read HIGH or LOW from one read to the next. The board has no pull-down. Every sketch here makes one in setup(): INPUT_PULLDOWN on an ESP32 or a Pico, Pin.PULL_DOWN in MicroPython. An Uno has none, so it needs 10 kΩ from SIGNAL to GND outside.

What a floating pin does

A switch on its own gives a pin two states: joined to VCC, or joined to nothing. Joined to nothing, a pin is not LOW. It is undefined: it picks up the charge it had, the wire next to it and the finger near it, and it can read HIGH one time and LOW the next. A longer sensor cable is a better antenna for it.

An open sensor leaves SIGNAL floating
Pull-down
Open, SIGNAL is
floating
Pull-down
none
Closed, extra draw at 3V3
0 mA
Nothing holds SIGNAL anywhere while the sensor is open, so the pin picks up whatever is near it and reads HIGH or LOW from one read to the next. Your sketch cannot tell that from a door opening. This is the board as it ships, and it is why every sketch sets a pull-down.

The other TinkerBlock sensors put a resistor on the board so that "nothing" means 0 V. This one does not, so the resistor has to come from somewhere else. That is the pull-down: a resistor from SIGNAL to GND that gives the pin a level, and that the closed sensor overrules by joining SIGNAL to VCC.

Where the pull-down comes from

Every board has its own answer, and it is a range, not a number:

BoardInternal pull-downWhat to do
ESP32, ESP32-S3about 45 kΩ, on a GPIO that has oneINPUT_PULLDOWN
Raspberry Pi Picoabout 50 to 80 kΩINPUT_PULLDOWN, or Pin.PULL_DOWN
Arduino Uno, NanononeINPUT and 10 kΩ from SIGNAL to GND, outside
ESP32 GPIO 34 to 39none: input-only pinsanother pin, or 10 kΩ outside

The 10 kΩ outside works on any board, and the listing allows anything from 4.7 kΩ to 47 kΩ. A smaller one holds LOW harder and draws more while the sensor is closed: VCC divided by it, 0.33 mA at 3.3 V and 0.5 mA at 5 V.

One line in setup

In an Arduino sketch that is pinMode(DOOR_PIN, INPUT_PULLDOWN), guarded by #ifdef INPUT_PULLDOWN so an Uno falls back to INPUT and says so in a comment. The first read has the whole sketch. In MicroPython it is Pin(DOOR_PIN, Pin.IN, Pin.PULL_DOWN). Both sketches in the book do it, and a sensor read without it is the one mistake that makes this block look broken.

INPUT_PULLUP is wrong here

A pull-up is the opposite resistor: it pulls the pin to the supply. While the sensor is open the pin reads HIGH, and a closed sensor puts VCC on it, which reads HIGH too. The two cannot be told apart. The light's branch loads the pull-up, so the open level may sit somewhere between the two thresholds where the chip promises nothing; that is worked out, not measured. Either way, the reading is useless, so use a pull-down.

When it does not work

It reads HIGH and LOW at random with the door open.

That is the missing pull-down. The pin is floating: its level is whatever charge, nearby wires and your hand put on it. Set INPUT_PULLDOWN in setup(), or fit a 10 kΩ from SIGNAL to GND, and the open level is LOW.

I used INPUT_PULLUP and the door always reads HIGH.

A pull-up pulls the pin to the supply while the sensor is open, and a closed sensor puts VCC on it: both read HIGH, so the pin cannot tell them apart. Use a pull-down. INPUT_PULLUP is wrong for this block.

INPUT_PULLDOWN does not compile on my Uno.

It does not exist there: the ATmega328P has an internal pull-up and no pull-down. Use pinMode(pin, INPUT) and fit a 10 kΩ resistor between SIGNAL and GND. The sketches do this for you with an #ifdef, and say so in a comment.

It still floats on GPIO 34 on my ESP32.

GPIO 34 to 39 on the ESP32 are input-only and have no internal pull-up or pull-down at all, so INPUT_PULLDOWN does nothing there. Use another pin, such as 25, or fit the 10 kΩ outside.

Where this goes next

Why the pin printed 3V3 goes to 5V on an Uno.

VCC is your logic voltage →

Edit this page — content/books/door-sensor/no-pull-down-on-the-board.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 →