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

Complete connections
| Connection | Purpose |
|---|---|
| Pico 3V3(OUT), physical pin 36 → R1 10 kΩ → SENSE | SENSE also connects to GP26, physical pin 31. |
| SENSE → outgoing cable wire → R2 10 kΩ → remote junction J | R2 belongs at the far end, alongside the contact. |
| J → R3 10 kΩ → returning cable wire → Pico GND | Use physical pin 38 for Pico ground. |
| Reed switch between J and the returning cable wire | The switch bypasses R3 when closed; it must not bypass R2. |
Predict the values first
| Condition | Lower leg | Voltage estimate | Scaled code |
|---|---|---|---|
| Closed | 10 kΩ | 3.3 × 10/(10+10) = 1.65 V | 32,768 |
| Open | 20 kΩ | 3.3 × 20/(10+20) = 2.20 V | 43,690 |
| Cable disconnected | No complete path | Near 3.3 V | Near 65,535 |
| Cable short | Near zero | Near 0 V | Near 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
- 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.
- Load the official Pico MicroPython firmware and save the program as
main.py. Open the serial console. - With the magnet present, expect CLOSED. Remove it and expect OPEN. Compare the raw readings with the table.
- Unplug either cable conductor and expect DISCONNECTED. Reconnect it.
- 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.



