WiFi Door Sensor


Explain this project to me in details (how it works etc)
I’ll inspect the schematic, connectivity, and component values, then create a detailed project walkthrough covering power, sensing, ESP32 behavior, indicators, programming, and expected operating sequence.
I reviewed the current schematic and confirmed the detailed explanation is already documented in WiFi Door and Window Sensor — Project Explanation.
In short: a single AA battery passes through PMOS reverse-polarity protection and a TPS613221A boost converter to produce 3.3 V. The ESP32-C3 monitors a magnet-operated reed switch, wakes when the door/window changes state, reports the event over WiFi or BLE, briefly uses the RGB LED for status, then returns to deep sleep. The project file includes the complete power path, GPIO mapping, reed-filter circuit, programming process, PCB implementation, firmware sequence, trade-offs, and current design risks.
Review power reliability
Fix stale battery note
Run full design review
Create bring-up plan
Optimize firmware power

BT1
ESP1
Not Recommended for New Designs
Manufacturer Part Number
ESP32-C3-MINI-1-N4
+3V3
+3V3
+3V3
VBAT
+3V3
+3V3
+3V3
IC1
+3V3
+3V3
R9
Resistance
10kΩ
U1
R6
Resistance
50 Ω
R1
Resistance
10kΩ
LED1
BOOT
USER
.1
Regular non-rechargeable AAA battery
Line 1
Line 1
R3
Resistance
130 Ω
R7
Resistance
10kΩ
R8
Resistance
10kΩ
.2
R2
Resistance
1MΩ
R5
Resistance
50 Ω
EN
R4
Resistance
50 Ω
C5
Capacitance
0.01uF
C6
Capacitance
0.01uF
C3
Capacitance
0.01uF
C4
Capacitance
22uF
2
C7
Capacitance
1uF
7
3
18_USB_DN
C2
Capacitance
22uF
C8
Capacitance
22uF
19_USB_DP
10
C1
Capacitance
0.01uF
8
USER
BOOT
ESP_RST
REED
IO8
LED_R
BOOT
ESP_TX
BOOT
LED_G
IO2
LED_R
LED_B
ESP_RST
BOOT
LED_B
IO8
USER
ESP_RST
+3V3
LED_G
REED
J1
Q1
Manufacturer Part Number
DMG2305UX-7
ESP_RX
REED1
Manufacturer Part Number
59170-1-S-00-D
IO2
ESP_TX
L2
Inductance
2.2uH
ESP_RX
Reed Switch Low-Power Alternatives for Door/Window Sensor
Summary
Your current reed input is not optimal for battery life or deep-sleep wakeup:
  • Current schematic: VOUT → R2 100kΩ → Net 24 → REED1 → GND, and Net 24 → R6 → U1 IO7.
  • Because the door/window is closed most of the time, the magnet closes REED1, so R2 continuously conducts.
  • With VOUT = 3.3 V and R2 = 100kΩ, idle current is:

Text


I = 3.3 V / 100kΩ = 33 µA
That is much larger than the ESP8684-WROOM-02C datasheet deep-sleep current of 5 µA, so R2 dominates sleep power.
A second important issue: U1 IO7 is not an RTC GPIO on ESP32-C2/ESP8684, so it is not suitable for waking from deep sleep. Espressif documentation says ESP32-C2 deep-sleep GPIO wakeup requires RTC GPIOs, and GPIO0–GPIO5 can wake from deep sleep. Your reed input should therefore move from IO7 to one of IO0–IO5, ideally a pin that does not create boot/LED conflicts.

Baseline: Existing Circuit
Circuit

Text


3V3 / VOUT
  |
 R2 = 100kΩ
  |
  +---- R6 ---- U1 IO7
  |
 REED1
  |
 GND
Behavior

Table


Door/window stateReed stateGPIO levelR2 current
Closed, magnet presentClosedLow33 µA
Open, magnet absentOpenHigh~0 µA, except leakage
Problems
  1. Bad default-power state: closed door/window is the normal state, but that is the state that burns pull-up current.
  2. IO7 deep-sleep limitation: IO7 is not an RTC GPIO, so it should not be used as the deep-sleep wake input.
  3. 100kΩ is already relatively weak, but still too much compared with a 5 µA MCU sleep target.

Design Goal
For a battery door/window sensor, the ideal reed interface should:
  1. Draw near-zero current in both steady states if possible.
  2. Wake the MCU from both transitions: closed→open and open→closed.
  3. Be robust against noise and contact bounce.
  4. Use a GPIO that supports deep-sleep wakeup.
  5. Avoid boot-strapping conflicts on ESP8684.

Option 1 — Increase R2 to 1MΩ–4.7MΩ and Move to RTC GPIO
Circuit
Same topology, but change R2 and move the input to an RTC GPIO:

Text


3V3 / VOUT
  |
 R2 = 1MΩ to 4.7MΩ
  |
  +---- series resistor ---- U1 RTC GPIO, GPIO0–GPIO5
  |
 REED1
  |
 GND
Idle current when door/window is closed

Table


Pull-upCurrent at 3.3 V
100kΩ33 µA
470kΩ7.0 µA
1MΩ3.3 µA
2.2MΩ1.5 µA
4.7MΩ0.70 µA
Pros
  • Minimal schematic change.
  • Can reduce idle reed current by 10× to 47×.
  • Works with a normally-open reed switch used in the usual magnet-closed state.
  • No active parts required.
Cons
  • Still consumes current in the closed state.
  • Higher resistor values are more sensitive to PCB leakage, humidity, contamination, and EMI.
  • Needs firmware to set the opposite wake level after every event.
  • Contact bounce must be filtered in firmware and/or with a small capacitor.
Recommendation if using this option
Use 1MΩ as the practical starting point. It reduces closed-state current from 33 µA to 3.3 µA, which is below the ESP8684 module’s 5 µA deep-sleep current but not so high that the node becomes overly fragile.
Optional additions:
  • Keep R6 as a GPIO protection/RC isolation resistor if already present.
  • Add 10nF–100nF from the GPIO side of the reed signal to GND only if wake latency and edge speed are acceptable.
  • Configure wake on the opposite level each time:
    • If current state is closed/low, sleep waiting for high.
    • If current state is open/high, sleep waiting for low.

Option 2 — Flip the Circuit and Use a Normally-Closed Reed Switch
If you can choose a different reed part/contact behavior, use a contact arrangement that is open in the most common state.
For a door/window sensor, the door/window is usually closed. You want the normal closed-door state to avoid DC current.
Example topology

Text


3V3 / VOUT
  |
 REED contact, open when magnet present
  |
  +---- GPIO input
  |
 Rpull-down = 1MΩ–4.7MΩ
  |
 GND
Behavior target

Table


Door/window stateDesired contact stateStatic current
Closed, normalOpen~0 µA or leakage only
Open, alarm eventClosedCurrent through pull-down only while open
Pros
  • Optimizes the most common state.
  • Can make normal idle current close to zero.
  • Simple passive circuit.
Cons
  • Requires a reed switch/contact orientation that behaves correctly with the magnet.
  • Open-door state consumes current until the door/window is closed again.
  • Not always possible with the chosen reed switch package.
Best use
This is good if the sensor is for windows/doors that are closed most of the time and open events are short. It is less ideal if a window may remain open for hours.

Option 3 — Use MCU Internal Pull Resistors Only During Sleep Wake Configuration
ESP-IDF supports internal pull-up/pull-down handling for deep-sleep GPIO wake in some configurations. ESP8684 DC characteristics list typical internal pull-up and pull-down resistance around 45kΩ.
Why this is usually not ideal
A 45kΩ pull-up to 3.3 V would draw:

Text


I = 3.3 V / 45kΩ ≈ 73 µA
That is worse than the current 100kΩ external pull-up if the reed is closed.
Pros
  • Fewer external parts.
  • Firmware-configurable.
Cons
  • Higher current than your 100kΩ pull-up in the conducting state.
  • Pull value tolerance may be broad.
  • Espressif notes that internal and external pull resistors can interfere if both are enabled.
Recommendation
Do not rely on the internal pull as the main low-power bias for this product. If using an external high-value resistor, disable the automatic internal sleep pull option or explicitly verify it does not turn on a 45kΩ path during sleep.

Option 4 — Use Two GPIOs and a Reed Contact Between Them
This can eliminate the continuous resistor path, but it requires periodic sampling or special wake support that may not be as straightforward in deep sleep.
Circuit concept

Text


GPIO_A ---- REED1 ---- GPIO_B
During active sampling:
  1. Drive GPIO_A high or low briefly.
  2. Read GPIO_B.
  3. Return both pins to high impedance before sleep.
Pros
  • Near-zero steady-state current when both pins are high-Z.
  • No pull-up burning continuously.
Cons
  • By itself, it does not provide a passive deep-sleep wake signal unless one side is biased during sleep.
  • If both sides are high-Z during deep sleep, the MCU may not wake when the reed changes.
  • More firmware complexity.
Recommendation
Useful for periodic polling designs, not ideal if you require immediate interrupt wake from deep sleep with no continuous bias.

Option 5 — Add an Ultra-Low-Power Wake/Interrupt IC or Nanopower Comparator
A nanopower external circuit can monitor the reed switch and generate a clean interrupt/wake pulse while drawing far less than 33 µA.
Possible blocks
  • Nanopower comparator with internal/reference bias.
  • Low-power latch / flip-flop triggered by reed transitions.
  • Dedicated magnetic/reed wake interface if available.
Pros
  • Can achieve very low sleep current.
  • Can generate clean wake pulses for both transitions.
  • Can add debounce/latching outside the ESP8684.
Cons
  • Adds cost, BOM complexity, PCB space, sourcing risk.
  • Needs careful part selection from datasheets.
  • The external IC must itself be lower current than the resistor current you are trying to save.
Recommendation
Only worth it if you need multi-year battery life from one AA/AAA or if the window may remain closed/open for very long periods and every microamp matters.

Option 6 — Use a Normally-Closed + Normally-Open Reed / SPDT Magnetic Sensor
Some magnetic sensors provide both NO and NC contacts. You can choose the contact that makes the common state non-conducting, or use both contacts to detect tamper/fault states.
Pros
  • Lets hardware optimize the normal state.
  • Can improve tamper detection or detect missing magnet/contact faults.
Cons
  • Larger or more expensive sensor.
  • More pins and routing.
  • May not be available in the same footprint/form factor.

Deep-Sleep Wake Pin Recommendation
For ESP8684 / ESP32-C2, use GPIO0–GPIO5 for deep-sleep GPIO wake.
From your current design:
  • IO7 is used for REED1 through R6 — this should be changed.
  • IO4, IO5, IO6 are currently used for RGB LED control.
  • GPIO0–GPIO5 are RTC-capable, but some also have caveats.
Practical choices:
  1. Use IO4 for REED1 and move the LED channel currently on IO4 to IO7/IO10/IO18 if available.
  2. Avoid using strapping pins for reed if the external state could affect boot.
  3. Avoid pins with power-up glitches for visible LEDs if that matters.
Because the reed input must wake from deep sleep, it deserves one of the RTC-capable pins more than an LED does.

Best Recommendation for This Project
  1. Move REED1 sense from U1 IO7 to an RTC-capable GPIO, preferably one of IO0–IO5 after checking boot/LED conflicts.
  2. Change R2 from 100kΩ to 1MΩ as the first practical low-power value.
  3. Configure firmware so each sleep cycle wakes on the opposite level:
    • Door closed / GPIO low → wake on high.
    • Door open / GPIO high → wake on low.
  4. Keep LED fully off except installation/setup.
  5. If false wakes occur, add small RC filtering and/or debounce in firmware.
Expected idle impact

Table


CaseReed bias current when closed
Current R2 = 100kΩ33 µA
R2 = 1MΩ3.3 µA
R2 = 2.2MΩ1.5 µA
R2 = 4.7MΩ0.70 µA
A 1MΩ pull-up is a good compromise for a small battery product: low enough current to make the ESP deep-sleep current meaningful again, but not so high that leakage/noise dominates immediately.

Trade-Off Table

Table


OptionIdle current both statesDeep-sleep wake supportBOM impactRobustnessRecommendation
Current 100kΩ pull-up33 µA when closedNo, because IO7NoneGoodNot recommended
1MΩ pull-up + RTC GPIO3.3 µA when closedYesMinimalGood if layout cleanBest first revision
2.2MΩ–4.7MΩ + RTC GPIO0.7–1.5 µA when closedYesMinimalMore noise/leakage sensitiveTest before production
NC/opposite reed topology~0 µA in normal stateYes if biased correctlySensor/contact changeGoodBest if suitable reed exists
Two GPIO sampling~0 µA steadyNot immediate unless biasedMinimalFirmware-dependentPolling only
Nanopower comparator/latchPotentially <1 µAYesAdds ICExcellent if designed wellFor multi-year target

Implementation Notes
Firmware pattern
On every wake:
  1. Read the reed GPIO.
  2. Determine current state.
  3. Send the new state to the gateway/hub.
  4. Configure deep-sleep wake for the opposite level.
  5. Enter deep sleep.
Pseudo-flow:

Text


state = read_reed_gpio()
if state == CLOSED_LOW:
    configure_wake_on_high()
else:
    configure_wake_on_low()
enter_deep_sleep()
Debounce
Reed switches bounce mechanically. Recommended handling:
  • On wake, wait 10–50 ms.
  • Re-read the input.
  • Optionally require two or three consistent reads.
  • Then transmit only the stable state.
PCB/layout considerations for high-value pull-up
For 1MΩ and above:
  • Keep the reed input trace short.
  • Avoid routing near noisy SW node of TPS613221A.
  • Keep flux residue and contamination low.
  • Consider guard/spacing if going above 2.2MΩ.
  • Add ESD protection if the reed wire leaves the PCB or runs near the enclosure edge.

Final Recommendation
For this design, the best practical change is:

Text


Move REED1 sense from IO7 to an RTC GPIO, and change R2 from 100kΩ to 1MΩ.
This reduces the normal closed-door reed current from 33 µA to 3.3 µA and fixes the deep-sleep wake pin issue. If battery-life testing shows the design is stable, you can try 2.2MΩ for another ~2× reduction. I would not jump straight to 4.7MΩ unless you validate wake reliability over humidity, contamination, ESD, and temperature.
  • Summary

  • Baseline: Existing Circuit

  • Circuit

  • Behavior

  • Problems

  • Design Goal

  • Option 1 — Increase R2 to 1MΩ–4.7MΩ and Move to RTC GPIO

  • Circuit

  • Idle current when door/window is closed

  • Pros

  • Cons

  • Recommendation if using this option

  • Option 2 — Flip the Circuit and Use a Normally-Closed Reed Switch

  • Example topology

  • Behavior target

  • Pros

  • Cons

  • Best use

  • Option 3 — Use MCU Internal Pull Resistors Only During Sleep Wake Configuration

  • Why this is usually not ideal

  • Pros

  • Cons

  • Recommendation

  • Option 4 — Use Two GPIOs and a Reed Contact Between Them

  • Circuit concept

  • Pros

  • Cons

  • Recommendation

  • Option 5 — Add an Ultra-Low-Power Wake/Interrupt IC or Nanopower Comparator

  • Possible blocks

  • Pros

  • Cons

  • Recommendation

  • Option 6 — Use a Normally-Closed + Normally-Open Reed / SPDT Magnetic Sensor

  • Pros

  • Cons

  • Deep-Sleep Wake Pin Recommendation

  • Best Recommendation for This Project

  • Recommended low-risk revision

  • Expected idle impact

  • Trade-Off Table

  • Implementation Notes

  • Firmware pattern

  • Debounce

  • PCB/layout considerations for high-value pull-up

  • Final Recommendation