Supplier photo of an assembled infinity mirror light cube illuminated on a dark background.
Supplier photo
Temu affiliate offer · Project idea

Build an infinity light cube

Listing specifies 5-volt direct current. Soldering required; battery and glue not included.

View kit on Temu

Tricky Circuit may earn a commission through these links. Product ideas have not been bench-tested by Tricky Circuit and are not verified lesson parts lists.

A Door Sensor That Can Tell Open from Unplugged

A basic switch input reports only two levels. If its cable breaks, the controller can mistake the fault for an ordinary open door. This experiment places resistors at the far end of the cable so that four useful conditions produce different analog readings. You will deliberately disconnect and short the low-voltage cable to see which faults the circuit can identify.

Four conditions, one measurement

ADC means analog-to-digital converter: the part of the microcontroller that turns an input voltage into a number. This Pico program uses readings scaled from 0 to 65,535. The scale does not create 16-bit physical measurement accuracy. We only need widely separated ranges.

The fixed resistor at the board pulls SENSE toward 3.3 V. At the remote end, R2 remains in the current path and the reed contact bypasses R3. Closed means a 10 kΩ lower leg. Open means a 20 kΩ lower leg. Disconnecting the complete remote path leaves the node near the upper rail; shorting the outgoing and return wires brings it near ground. GPIO means general-purpose input/output; use GP26, not physical connector position 26.

Parts to gather

  • Original Raspberry Pi Pico with MicroPython 1.26, USB cable and serial console
  • Normally open reed switch and magnet
  • Three 10 kΩ 1% resistors; breadboard and short two-wire cable
A Door Sensor That Can Tell Open from Unplugged. Pico 3V3(OUT), physical pin 36 → R1 10 kΩ → SENSE SENSE → outgoing cable wire → R2 10 kΩ → remote junction J J → R3 10 kΩ → returning cable wire → Pico GND Reed switch between J and the returning cable wire
Original Tricky Circuit connection diagram. Nominal values are calculated; this build has not been physically tested.

Complete connections

ConnectionPurpose
Pico 3V3(OUT), physical pin 36 → R1 10 kΩ → SENSESENSE also connects to GP26, physical pin 31.
SENSE → outgoing cable wire → R2 10 kΩ → remote junction JR2 belongs at the far end, alongside the contact.
J → R3 10 kΩ → returning cable wire → Pico GNDUse physical pin 38 for Pico ground.
Reed switch between J and the returning cable wireThe switch bypasses R3 when closed; it must not bypass R2.

Predict the values first

ConditionLower legVoltage estimateScaled code
Closed10 kΩ3.3 × 10/(10+10) = 1.65 V32,768
Open20 kΩ3.3 × 20/(10+20) = 2.20 V43,690
Cable disconnectedNo complete pathNear 3.3 VNear 65,535
Cable shortNear zeroNear 0 VNear zero

These are nominal calculations, not measured results. The decision windows deliberately leave gaps. A result in a gap becomes CHECK_WIRING rather than being forced into the nearest reassuring label. With a short across the cable, R1 still limits current to approximately 0.33 mA.

Complete MicroPython program

"""Pico GP26: 10k pull-up; remote 10k in series with (reed || 10k)."""
def classify(raw):
    if raw < 3000:
        return "SHORT"
    if 27000 <= raw <= 38000:
        return "CLOSED"
    if 40000 <= raw <= 49000:
        return "OPEN"
    if raw > 61000:
        return "DISCONNECTED"
    return "CHECK_WIRING"

def main():
    from machine import ADC, Pin
    from time import sleep_ms
    adc = ADC(Pin(26))
    last = None
    streak = 0
    while True:
        raw = sum(adc.read_u16() for _ in range(16)) // 16
        state = classify(raw)
        streak = min(3, streak + 1) if state == last else 1
        last = state
        if streak == 3:
            print("raw=%d state=%s" % (raw, state))
        sleep_ms(100)

if __name__ == "__main__":
    main()

Build and challenge the circuit

  1. Disconnect USB power while wiring. Keep all of this circuit on the Pico’s 3.3 V and ground; no 5 V or external alarm supply belongs on GP26.
  2. Load the official Pico MicroPython firmware and save the program as main.py. Open the serial console.
  3. With the magnet present, expect CLOSED. Remove it and expect OPEN. Compare the raw readings with the table.
  4. Unplug either cable conductor and expect DISCONNECTED. Reconnect it.
  5. At the far cable end, temporarily join outgoing and return wires before R2. Expect SHORT. Remove the jumper before normal use.

The program averages 16 readings and requires three matching classifications at 100 ms intervals before reporting a state. During a change it pauses reporting instead of announcing an unqualified intermediate state. This demonstration is not a certified security or fire input, and software labels are not guarantees of fault coverage.

What this cannot diagnose

Some faults imitate valid resistances. A damaged resistor, wet connector or partial short might happen to land inside the open or closed window. A short directly across the reed itself looks exactly like a closed door. The circuit supervises the two-wire path only in the specific ways demonstrated. R2 and R3 must be remote: placing them at the controller can hide cable failures.

If your readings sit between ranges, measure the actual three resistors with power removed, confirm the remote topology and inspect the ground connection. Start with short bench leads; a long field cable introduces interference and protection requirements not handled here.

Challenge: why not use one resistor directly across the switch?

With only a parallel resistor, a closed contact and a direct cable short both produce almost zero resistance. Keeping R2 in series separates the normal closed state from a short across the cable.

Sources and related learning

Explore the Tricky Circuit interactive lessons. This article presents a design and software checks; no physical build results are claimed.

📡Broadcast the signal — amplify the connection.

Leave a Reply

Temu affiliate offers

Find your next electronics project

Explore these do-it-yourself project kits. Check the selected option, included parts and instructions on each offer.

Tricky Circuit may earn a commission if you buy through these Temu affiliate links. These are product ideas; they have not been bench-tested by Tricky Circuit and are not verified lesson parts lists.

Supplier photo of a breadboard, jumper wires and assorted electronic components in a plastic storage case.

Supplier product photo

Try breadboard experiments

Breadboard, wires and assorted parts. Arduino controller board not included.

View kit on Temu

Supplier photo of an assembled blue surface-mount soldering practice board with a circular ring of small lights.

Supplier product photo

Solder a chasing-light board

Surface-mount soldering practice. Battery and battery holder not included.

View kit on Temu

Supplier photo of an assembled two-wheeled line-following car with a blue circuit board, two motors and an empty battery holder.

Supplier product photo

Build a line-following car

Soldering and assembly required. Check battery and track requirements before buying.

View kit on Temu