DIGITALbeginner

Door Sensor

A TinkerBlock board that takes the two bare wires of a magnetic door or window sensor on a screw terminal and puts it between VCC and SIGNAL. A closed sensor reads HIGH; open, SIGNAL floats, because the board has no pull-down, so you set one in setup(). The red LED lights while the sensor is closed: it is not a power light.

Door Sensor TK107

Specifications

TypeDoor and window sensor interface: a screw terminal that puts a magnetic reed sensor between VCC and SIGNAL. A closed sensor (magnet near) reads HIGH
TerminalKF301-5.0-2P screw terminal, two ways, 5.0 mm pitch. The sensor has no polarity: either wire under either screw
Pull-downNone on the board, and no pull-up. Set the pin to INPUT_PULLDOWN (Pin.PULL_DOWN in MicroPython), or fit 10 kΩ from SIGNAL to GND on a board with none, such as an Uno. ESP32 GPIO 34 to 39 have none either
IndicatorRed LED with 5.1 kΩ on SIGNAL: lit while the sensor is closed, dark while it is open. Not a power light
SupplyYour board's logic voltage on VCC: 3V3 on an ESP32, ESP32-S3 or Pico, 5V on an Uno. The header prints 3V3; VCC powers nothing, a closed sensor puts it on SIGNAL
Current0 mA while open. Closed, about 0.3 mA at 3.3 V and 1.1 mA at 5 V, the LED plus the pull-down (45 kΩ internal on an ESP32, 10 kΩ outside on an Uno); worked out, not measured
Pins to wire3 of the 4: GND, VCC and SIGNAL. NC is connected to nothing on the board
Header4-pin right-angle male, 2.54 mm pitch: GND, 3V3 (VCC), NC, SIGNAL, with GND on the square pad
Board22.4 × 30.4 mm, two 4.8 mm mounting holes 16 mm apart. The front prints ACTIVE HIGH, the back DETECT THE OPEN/CLOSED STATUS OF DOORS AND WINDOWS
In the boxThe kit's listing gives 7 sensors with 7 interface modules (its photo shows 6): 3 plastic surface, 3 recessed, 1 metal housing, each with a magnet, and a Start Card

What it does

It tells your board whether a magnetic door or window sensor is closed. The black block across the top is a two-way screw terminal: the sensor's two bare wires go under the screws, and the sensor, a switch that a magnet closes, sits between VCC and SIGNAL. Closed, SIGNAL is VCC and your pin reads HIGH. Open, SIGNAL is connected to nothing.

Drag to turn it
The TK107. The screw terminal takes the sensor's wires. Turn it over for the back.

A red LED and a 5.1 kΩ on SIGNAL light while the sensor is closed. They are fed from SIGNAL, not from VCC, so the LED is not a power light: the product listing says it is, and it is not. VCC reaches only the terminal and the header, so with the sensor open the block draws no current.

Three things to know before wiring

  • There is no pull-down. Nothing on the board gives SIGNAL a level while the sensor is open. Set the pin to a pull-down in setup(): INPUT_PULLDOWN, or Pin.PULL_DOWN in MicroPython. An Uno has no internal pull-down, so fit 10 kΩ from SIGNAL to GND. ESP32 GPIO 34 to 39 have none either.
  • VCC is your board's logic voltage. The header prints 3V3; that is a label, not a requirement. A closed sensor puts VCC on your pin: 3V3 on an ESP32, an ESP32-S3 or a Pico, 5V on an Uno.
  • Do not use INPUT_PULLUP. It pulls the open pin to the supply, and a closed sensor reads HIGH too.

Which sensor

The kit's listing gives three kinds, each a magnet and a reed switch. Sizes are the listing's, not measured.

SensorIn the boxListing givesSuits
Plastic, surface mount327 × 13 × 8 mmdoors and window frames
Hidden, recessed3no sizecabinets and wooden doors
Metal housing1105 × 37 × 15 mmgates and garage doors

The board and the sketch are the same for all three.

Wiring, in four lines

  1. GND to your board's GND.
  2. 3V3 (VCC) to 3V3 on an ESP32, ESP32-S3 or Pico; 5V on an Uno.
  3. SIGNAL to GPIO 4 on an ESP32-S3, GPIO 25 on an ESP32, D2 on an Uno, GP15 on a Pico. On an Uno, add 10 kΩ from this pin to GND.
  4. NC to nothing: it is connected to nothing on the board.

The sensor's two wires go under the two screws, either way round. Then pinMode(pin, INPUT_PULLDOWN), and digitalRead(pin) is HIGH while the sensor is closed.

Where to start

The handbook below is ten short articles, each with a working figure. The first read is the whole build in three wires and a few lines, and a door that nags adds debouncing and a reminder when one stays open.

For why the board needs a pull-down, read no pull-down on the board. If it will not switch, when it does not switch.

When it doesn’t work

Why does it read randomly when the door is open?
The board has no pull-down, so with the sensor open SIGNAL is connected to nothing and floats. Set the pin to a pull-down in setup(): INPUT_PULLDOWN on an ESP32 or a Pico, Pin.PULL_DOWN in MicroPython. An Uno has none, so fit 10 kΩ from SIGNAL to GND.
Is the red LED a power light?
No, whatever the listing says. It hangs off SIGNAL through 5.1 kΩ and lights only while the sensor is closed. A powered, wired board with the door open is dark.
The header says 3V3. Do I have to use 3.3 V?
No. The pin is VCC and powers nothing; a closed sensor puts that level on SIGNAL, so it should be your board's logic voltage: 5V on an Uno, 3V3 on an ESP32, ESP32-S3 or Pico. An Uno reads 3.3 V as HIGH with 0.3 V to spare.
Can I read it with INPUT_PULLUP?
No. A pull-up pulls SIGNAL to the supply while the sensor is open, and a closed sensor puts VCC on it: both read HIGH and the two cannot be told apart. Use a pull-down.
Does HIGH mean the door is open or shut?
With the magnet on the door and the sensor on the frame, a shut door is closed and reads HIGH, per the listing. Some reed sensors are made the other way. Watch the LED as you move the magnet to check yours before you label anything.
How far apart can the two halves be?
The listing gives no distance and nobody has measured the sensors in this kit. It depends on the magnet and the sensor. Watch the LED as you move the halves apart, and mount them closer than where it goes out.

The door sensor handbook

10 articles · about 45 minutes

This page is the reference: what the part is, what it is made of, and the questions people arrive already asking. The handbook is the walk — the same part in the order somebody actually meets it.

The board

2 articles

Four pins of which three are wired, a screw terminal for the sensor's two wires, and a light that tells you less than its listing says.

How it works

3 articles

A switch from VCC to SIGNAL, the pull-down the board leaves out, and why VCC has to be your board's logic voltage.

Reading it

2 articles

Three wires, a pull-down in setup, and what HIGH and LOW mean for a real door.

Using it

3 articles

Choosing among the three sensors, a door that nags when left open, and the short list of reasons it does not switch.

Edit this page — content/modules/door-sensor.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 →