VOUT Analysis for TPS613221

Created the VOUT-vs-AA battery low-battery analysis and graph in the project document: TPS613221A VOUT vs AA Battery Voltage.
Key takeaway: IC1 should hold ~3.3 V for light loads deep into AA discharge, but high-current WiFi bursts become risky below ~0.9–1.0 V because the boost converter can hit current limit and VOUT collapses.
Keep in mind that in code I set wifi power to lowest level WIFI_POWER_8_5dBm. Wifi Connect last about 2500ms in average. also do not forget about C2, C4 and C5 Now update the graph
I’ll update the low-battery graph to include the reduced WiFi TX power, ~2.5 s connect burst, and the stored energy from C2/C4/C5.
Updated the graph/document with WIFI_POWER_8_5dBm, the ~2500 ms WiFi connect duration, and C2/C4/C5 energy contribution: TPS613221A VOUT vs AA Battery Voltage.
Key change: the relevant low-power WiFi curves are now 75–100 mA; C2/C4 help only with short transients (~0.065 ms at 100 mA), so the 2.5 s connect window is dominated by AA cell loaded voltage, not capacitor storage.
Validate low-battery reliability
Check Espressif current
Set firmware thresholds
Review power layout
Estimate AA ESR impact
BT1
ESP1
Not Recommended for New Designs
Manufacturer Part Number
ESP32-C3-MINI-1-N4
+3V3
USER
BOOT
ESP_RST
+3V3
REED
IO8
+3V3
VBAT
+3V3
LED_R
+3V3
BOOT
+3V3
ESP_TX
BOOT
LED_G
IO2
LED_R
LED_B
ESP_RST
BOOT
LED_B
IO8
USER
ESP_RST
+3V3
LED_G
REED
+3V3
ESP_RX
IO2
+3V3
ESP_TX
ESP_RX
C5
Capacitance
0.01uF
R9
Resistance
10kΩ
C6
Capacitance
0.01uF
C3
Capacitance
0.01uF
C4
Capacitance
22uF
R6
Resistance
50 Ω
R1
Resistance
10kΩ
C7
Capacitance
1uF
R3
Resistance
130 Ω
C2
Capacitance
22uF
R7
Resistance
10kΩ
R8
Resistance
10kΩ
C8
Capacitance
22uF
R2
Resistance
1MΩ
R5
Resistance
50 Ω
C1
Capacitance
0.01uF
R4
Resistance
50 Ω
U1
LED1
2
BOOT
7
USER
3
.1
Regular non-rechargeable AAA battery
Line 1
Line 1
18_USB_DN
.2
19_USB_DP
10
EN
8
IC1
J1
Q1
Manufacturer Part Number
DMG2305UX-7
REED1
Manufacturer Part Number
59170-1-S-00-D
L2
Inductance
2.2uH

Refine this doc
Ask about this doc
Firmware Technical Requirements — WiFi Door and Window Sensor
1. Project overview
This firmware is for the WiFi Door and Window Sensor PCB. The product is a compact battery-powered smart-home door/window contact sensor built around an ESP32-C3-MINI-1-N4 module, a single AA primary cell, a TPS613221A 3.3 V boost regulator, a magnetic reed switch, a user button, BOOT/EN controls, a programming header, and a common-anode RGB status LED.
Primary firmware goals:
  1. Detect door/window open and closed state changes using the reed switch.
  2. Report events reliably over a low-power wireless path.
  3. Spend nearly all time in deep sleep to maximize AA battery life.
  4. Provide simple bring-up/setup feedback through serial logs and the RGB LED.
  5. Support production flashing/debug through the existing UART/programming header.
The hardware can support both WiFi and Bluetooth LE, but BLE event reporting is strongly preferred for battery life when a nearby BLE hub is available.
2. Target hardware

Table


ItemValue
MCU moduleESP32-C3-MINI-1-N4
VendorEspressif Systems
Main supply rail3.3 V, net VOUT
Power sourceSingle non-rechargeable AA cell
Boost regulatorTPS613221ADBVR, 3.3 V output
Magnetic sensorLittelfuse 59170-1-S-00-D reed/magnetic sensor
RGB LEDEverlight 19-237/R6GHBHC-A04/2T / LTST-C19HE1WT style common-anode RGB LED
ButtonsPTS815 tactile switches for USER, BOOT, EN/reset
Programming headerJ1, 1x6 2.54 mm vertical header
3. Firmware build environment requirements
3.1 Arduino IDE target
Recommended Arduino environment:
  • Arduino IDE: 2.3.x or newer
  • Board package: esp32 by Espressif Systems 2.0.17 or newer
  • Board selection: ESP32C3 Dev Module or ESP32-C3 DevKitM-1 equivalent
  • Serial monitor: 115200 baud
  • Upload speed: start with 460800, fall back to 115200 if upload is unreliable
  • Flash mode: DIO
  • USB CDC on boot: enable if using native USB serial
3.2 Library requirements
Default BLE firmware:

Table


LibraryVersionNotes
Arduino-ESP32 core2.0.17+ or 3.0.7+Code must account for LEDC API differences between 2.x and 3.x if supporting both.
NimBLE-Arduino by h2zero2.2.1+Use for low-power BLE advertising/reporting.
No external WiFi, HTTP, Preferences, or ArduinoJson library is required for the default BLE event-advertising build.
3.3 PlatformIO reference configuration

Ini


[env:esp32-c3-mini-door-sensor]
platform = espressif32@6.10.0
board = esp32-c3-devkitm-1
framework = arduino
monitor_speed = 115200
upload_speed = 460800
board_build.mcu = esp32c3
board_build.f_cpu = 160000000L
lib_deps =
  h2zero/NimBLE-Arduino@^2.2.1
build_flags =
  -D ARDUINO_USB_MODE=1
  -D ARDUINO_USB_CDC_ON_BOOT=1
4. Schematic pin map

Table


FunctionSchematic pathESP32-C3 GPIOElectrical behaviorFirmware requirement
Reed/magnetic sensorESP1:IO0 → R6 50 Ω → REED1:2, with R2 1 MΩ pull-up to 3.3 V and C1 debounce/filter to GNDGPIO0Active LOW when magnet/reed closes to GNDConfigure as input. Do not enable strong internal pull unless needed for diagnostics. Treat LOW as closed = true.
User buttonESP1:IO1 → USER switch, C6 debounce/filter to GNDGPIO1Active LOWConfigure as input. Treat LOW as pressed. Use for setup/test mode.
RGB LED redESP1:IO4 → R3 130 Ω → LED1:RGPIO4Common-anode LED, active LOW sink driveUse PWM-capable output. LOW/on, HIGH/off. Keep off in normal sleep/idle.
RGB LED greenESP1:IO5 → R4 50 Ω → LED1:GGPIO5Common-anode LED, active LOW sink driveUse PWM-capable output. LOW/on, HIGH/off. Keep off in normal sleep/idle.
RGB LED blueESP1:IO6 → R5 50 Ω → LED1:BGPIO6Common-anode LED, active LOW sink driveUse PWM-capable output. LOW/on, HIGH/off. Keep off in normal sleep/idle.
GPIO2 strapESP1:IO2 → R7 10 kΩ pull-up to 3.3 VGPIO2Boot strap/pull-up onlyDo not use as runtime output. Avoid driving this pin.
BOOT buttonESP1:IO9 → BOOT switch to GND + R8 10 kΩ pull-up to 3.3 V + J1 Pin 4GPIO9Active LOW boot/download strapLeave as boot/programming function. Runtime use only if necessary and with strap-state caution.
EN/resetESP1:EN → EN switch to GND + R1 10 kΩ pull-up + C5 filter + J1 Pin 5ENActive LOW hardware resetFirmware cannot read this as GPIO; use for reset/programming only.
UART TXESP1:TXD0 → J1 Pin 2GPIO21 / TXD0Serial output/programmingUse for boot logs and optional debug.
UART RXESP1:RXD0 → J1 Pin 3GPIO20 / RXD0Serial input/programmingUse for flashing/debug only unless required.
3.3 VESP1:3V3 → VOUT3V3Boost outputNo firmware control. Brownout behavior must be tested under RF transmit.
GNDESP1:GND pins → GNDGNDCommon groundN/A
Unused or currently unassigned ESP32-C3 pins visible in schematic: GPIO3, GPIO7, GPIO8, GPIO10, GPIO18, GPIO19. Before using any of these, verify ESP32-C3 boot strap/JTAG/USB/default peripheral interactions in the Espressif datasheet and current board routing.
5. Electrical behavior and polarity
5.1 Reed switch
  • Reed input is connected to GPIO0 through a 50 Ω series resistor.
  • R2 is a 1 MΩ pull-up to 3.3 V.
  • Reed switch closes to GND.
  • Expected firmware interpretation:
    • GPIO0 = LOW → door/window closed / magnet present.
    • GPIO0 = HIGH → door/window open / magnet absent.
The 1 MΩ pull-up reduces idle current but makes the input higher impedance than a typical digital input. Firmware should avoid enabling internal pulldowns or strong pulls during normal operation. Sampling should allow a short settle/debounce time after wake.
5.2 User button
  • User button is active LOW.
  • The button should be used for setup mode, test mode, pairing/provisioning, or factory reset gestures.
  • Because deep sleep wake is level-based and the reed wake polarity changes, the user button may not be simultaneously wake-armed in all reed states without a more advanced wake strategy.
5.3 RGB LED
  • LED is common-anode tied to 3.3 V (VOUT).
  • GPIO pins sink current through resistors.
  • Logic:
    • GPIO LOW → LED channel ON.
    • GPIO HIGH → LED channel OFF.
  • LED must remain off except during boot, setup, pairing, error indication, and manual test because LED current dominates sleep current.
Recommended status colors:

Table


StateLED behavior
BootShort dim white or blue flash
Open eventShort green flash
Closed eventShort red flash
User/setup modeBlue or RGB cycling
Wireless transmit failureShort amber/red blink pattern
Low battery, if battery measurement is later addedRed repeated blink during manual wake only
6. Power and battery constraints
6.1 Battery and regulator
  • Battery is a single AA primary cell.
  • The boost regulator is TPS613221ADBVR with 3.3 V output.
  • TPS613221A quiescent current into VOUT is approximately 6.5 µA typical, 10 µA max.
  • ESP32-C3 deep sleep with RTC timer + RTC memory is approximately 5 µA typical.
  • Expected base sleep current estimate: about 11.5 µA before reed pull-up conduction.
  • If the reed is closed and R2 is pulled to GND, the 1 MΩ pull-up adds approximately 3.3 µA.
6.2 RF burst current risk
WiFi TX current can be high for a single AA + boost design:

Table


ESP32-C3 WiFi caseApprox current at 3.3 V
802.11n HT20 MCS7 @ 17.5 dBm290 mA
802.11g 54 Mbps @ 18 dBm295 mA
802.11b 1 Mbps @ 20.5 dBm350 mA
Approximate AA input current during WiFi TX through the boost converter can reach:

Table


Battery voltageLow/mid WiFi TXHigh WiFi TX
1.5 V~0.8–1.1 A~1.1 A
1.2 V~1.0–1.4 A~1.4 A
0.9 V~1.3–1.8 A~1.8 A
TPS613221A switch current limit is approximately 0.75 A minimum, 1.20 A typical, 1.60 A maximum, so high-power WiFi at low AA voltage may brown out or fail. Firmware must minimize RF-on time and avoid unnecessarily high TX power.
6.3 Runtime targets and expectations
For WiFi reporting with 2-second events and 10 open/close cycles/day, expected AA runtime is approximately 112–244 days, depending on AA capacity, TX mode, and reed state.
For BLE reporting with optimized 0.2-second events and 10 open/close cycles/day, expected AA runtime can improve dramatically, approximately 1453–2191 days for a 2000 mAh AA in modeled low-to-mid BLE cases. Real-world cell aging, pulse capability, self-discharge, RF retries, and enclosure/range effects will reduce this.
7. Wireless reporting requirements
7.1 Preferred default: BLE event advertising
The default firmware should prioritize BLE event reporting for battery life.
Requirements:
  1. Device wakes from deep sleep on reed state change or user interaction.
  2. Firmware reads reed/user state after debounce/settle.
  3. Firmware broadcasts a compact BLE event payload.
  4. Firmware returns to deep sleep immediately after a short advertising window.
  5. Target BLE active time: 0.2–0.5 s if the hub reliably receives events.
  6. Initial bring-up advertising window may be 700 ms; increase to 1.5–3 s only if reliability requires it.
  7. Use the lowest BLE TX power that passes range/reliability testing; start with 0 dBm or 9 dBm for margin, then reduce if possible.
Recommended BLE identity:

Table


ItemValue
Device nameLatchBit or project-specific product name
Service UUID7b18d000-9f2a-4e1c-9c6a-2b4b0d6d0001
Advertisement typeNon-connectable or short connectable event, depending on hub design
Recommended manufacturer data payload:

Table


Byte(s)Meaning
0–1Company ID or temporary pseudo ID. Existing starter used 0xFFFF. Replace with real assigned ID if productized.
2Protocol version, start at 1.
3Event code: 1=boot, 2=opened, 3=closed, 4=user/setup.
4Reed closed flag: 0/1.
5User pressed flag: 0/1.
6–9Event counter, little-endian uint32.
10–13Boot counter, little-endian uint32.
7.2 Optional: WiFi reporting
WiFi reporting is supported by the ESP32-C3 hardware, but should be treated as a higher-power mode.
If WiFi is implemented:
  1. Store WiFi credentials securely using ESP32 NVS/Preferences.
  2. Avoid continuous WiFi association.
  3. Wake, connect, report, and sleep as fast as possible.
  4. Use static IP or other fast reconnect techniques if acceptable.
  5. Minimize DHCP, DNS, TLS handshake, and retry time.
  6. Target less than 2 seconds active time per event; ideally less than 1 second.
  7. Use lowest TX power that reliably reaches the access point without increasing retries.
  8. Include brownout/retry logging during development.
  9. If reporting fails, use a bounded retry count and go back to sleep rather than draining the AA cell indefinitely.
8. Sleep and wake requirements
8.1 Sleep mode
  • Use ESP32-C3 deep sleep for normal idle.
  • Preserve small state in RTC memory, including last reed state, boot count, and event count.
  • Turn LED pins to off state before sleeping.
  • Disable unused peripherals before sleep.
  • Keep GPIO pulls consistent with the external hardware to minimize leakage.
8.2 Reed wake strategy
The reed input is effectively level-based, so firmware must store the last reed state and arm wake for the opposite level:

Table


Current reed state before sleepGPIO0 levelDesired next eventWake level
Closed / magnet presentLOWOpenHIGH
Open / magnet absentHIGHClosedLOW
ESP32-C3 Arduino builds may not expose classic ESP32 EXT1 wake APIs. Prefer ESP32-C3-compatible GPIO wake APIs such as gpio_wakeup_enable() plus esp_sleep_enable_gpio_wakeup() when using Arduino-ESP32 versions where EXT1 is unavailable.
8.3 User wake limitation
The USER button is active LOW. In the simple wake strategy:
  • If reed is open and firmware arms LOW wake, USER can also be armed as LOW wake.
  • If reed is closed and firmware arms HIGH wake to detect opening, USER cannot always be simultaneously armed using the same simple level-wake mode.
  • EN/reset remains physically available at all times.
If always-wake-on-user is required, the firmware developer should evaluate ESP32-C3 wake-source capabilities in the exact Arduino/IDF version and may need a different wake design.
9. Debounce and event handling
9.1 Reed debounce
The PCB includes hardware filtering on the reed input, but firmware should still debounce after wake.
Recommended behavior:
  1. On wake, wait 20–50 ms for input settling.
  2. Sample reed multiple times over a short window.
  3. Accept a state change only if readings are stable.
  4. Suppress duplicate reports where the state equals the last reported state unless the wake cause is boot/timer/manual test.
9.2 User button handling
Suggested gestures:

Table


GestureBehavior
Short press during wake/setupSend user/test event.
Hold USER during reset/power-upEnter setup/provisioning/test mode.
Long hold, e.g. >10 sOptional factory reset / clear credentials if WiFi provisioning is implemented.
10. Programming and bring-up requirements
10.1 Programming header J1

Table


J1 pinConnection
13.3 V / VOUT
2ESP32-C3 TXD0
3ESP32-C3 RXD0
4BOOT / GPIO9
5EN/reset
6GND
Flashing procedure if auto-reset is not available:
  1. Connect 3.3 V UART adapter GND, TX, RX.
  2. Hold BOOT low.
  3. Pulse EN/reset low, then release EN.
  4. Release BOOT after the upload begins.
  5. Use 115200 baud if upload at higher speed is unreliable.
Do not use a 5 V UART interface on ESP32-C3 RX/TX pins.
10.2 Serial logs
During development, print at 115200 baud:
  • Firmware version/build date.
  • Wake cause.
  • Reed raw level and interpreted state.
  • User button state.
  • Event code.
  • Wireless report result.
  • Sleep wake configuration.
  • Brownout/reset reason if available.
Release builds should reduce or disable serial output to save active time.
11. Firmware states
Recommended state machine:
  1. Boot/init
    • Initialize GPIOs.
    • Initialize serial if debug build.
    • Read reset/wake cause.
  2. Input settle/debounce
    • Wait 20–50 ms.
    • Read reed and user button.
  3. Mode decision
    • If USER held, enter setup/test/provisioning.
    • Else determine event from current reed state vs RTC last state.
  4. Indication
    • Optional short LED feedback.
  5. Report
    • BLE advertising by default, optional WiFi report if configured.
  6. Persist state
    • Update RTC/NVS as needed.
  7. Arm wake
    • Configure reed opposite-level wake.
    • Configure user wake if compatible with selected wake mode.
  8. Deep sleep
12. Battery measurement
The current schematic data does not show a dedicated battery-voltage divider into an ADC pin. Therefore:
  • Do not implement battery voltage reporting unless a valid ADC input path is confirmed on the PCB.
  • Do not enable internal pulls or repurpose strap pins for battery measurement.
  • If a future PCB revision adds a divider, ensure the divider is switched or high impedance enough for AA sleep current targets, and account for ADC source impedance/acquisition time.
13. Reliability and failure behavior
Firmware must avoid battery-draining failure loops.
Requirements:
  1. Wireless retries must be bounded.
  2. If report fails, optionally send a failure LED indication only during manual/setup mode, then sleep.
  3. Maintain event counters to help detect missed reports.
  4. Avoid long blocking setup/connect loops on every reed wake.
  5. Do not keep WiFi/BLE active while waiting indefinitely for a hub/AP.
  6. Include a periodic failsafe wake only if useful; if implemented, use a long interval such as once per day.
14. Validation checklist for firmware developer
14.1 Compile and flash
  • Compile for ESP32-C3 target.
  • Confirm selected Arduino-ESP32 core version.
  • Confirm NimBLE-Arduino version.
  • Flash through J1/UART or native USB method used for bring-up.
  • Confirm serial boot log at 115200 baud.
14.2 GPIO validation
  • Confirm reed closed reports GPIO0 LOW and closed=true.
  • Confirm reed open reports GPIO0 HIGH and closed=false.
  • Confirm USER button reports active LOW.
  • Confirm BOOT/EN still work for flashing/reset.
  • Confirm RGB LED channel polarity and colors.
  • Confirm GPIO2 is not driven by firmware.
14.3 Sleep/wake validation
  • Closed → open transition wakes and reports open.
  • Open → closed transition wakes and reports closed.
  • Device returns to deep sleep after report.
  • LED is off in deep sleep.
  • Wake cause logging matches expected behavior.
  • USER wake/setup behavior is documented and tested for both reed states.
14.4 Wireless validation
  • BLE advertisement payload decodes correctly.
  • Hub receives events at intended distance and enclosure orientation.
  • Advertising window is minimized after reliability testing.
  • TX power is reduced only after packet reliability remains acceptable.
  • If WiFi is used, active time and retry count are measured.
14.5 Power validation
  • Measure deep-sleep current with LED off.
  • Measure current with reed closed and open to quantify R2 contribution.
  • Measure active current during BLE and/or WiFi report.
  • Test with fresh and partially depleted AA cells.
  • Test cold/aged cell behavior if product environment requires it.
  • Confirm no brownouts during RF transmit.
15. Known firmware starter issue to avoid
Earlier starter code targeted Arduino-ESP32 3.x APIs and may fail under Arduino-ESP32 2.x with errors such as:
  • ledcAttach not declared.
  • NimBLEAdvertising has no setScanResponse member.
  • ESP32-C3 EXT1 wake symbols unavailable.
A robust implementation should:
  1. Use Arduino-ESP32 2.x compatible ledcSetup() + ledcAttachPin() or guard LEDC calls by core version.
  2. Avoid adv->setScanResponse(false) unless confirmed available in the installed NimBLE-Arduino version.
  3. Use ESP32-C3-compatible GPIO wake APIs for the selected Arduino/IDF version.
16. Acceptance criteria
Firmware is acceptable for initial hardware bring-up when:
  1. It compiles with the documented Arduino/PlatformIO environment.
  2. It flashes successfully through the available programming method.
  3. Serial logs identify firmware version, wake cause, reed state, and event type.
  4. Reed open/closed events are correctly detected and reported.
  5. RGB LED status works and remains off during sleep.
  6. Device returns to deep sleep after each event.
  7. BLE reporting works with a documented payload and hub decode method, or WiFi reporting works with bounded retries.
  8. Deep sleep current and RF burst behavior are measured on assembled hardware.
  9. The firmware does not use GPIO2 as a runtime output and does not interfere with BOOT/EN programming behavior.
  • 1. Project overview

  • 2. Target hardware

  • 3. Firmware build environment requirements

  • 3.1 Arduino IDE target

  • 3.2 Library requirements

  • 3.3 PlatformIO reference configuration

  • 4. Schematic pin map

  • 5. Electrical behavior and polarity

  • 5.1 Reed switch

  • 5.2 User button

  • 5.3 RGB LED

  • 6. Power and battery constraints

  • 6.1 Battery and regulator

  • 6.2 RF burst current risk

  • 6.3 Runtime targets and expectations

  • 7. Wireless reporting requirements

  • 7.1 Preferred default: BLE event advertising

  • 7.2 Optional: WiFi reporting

  • 8. Sleep and wake requirements

  • 8.1 Sleep mode

  • 8.2 Reed wake strategy

  • 8.3 User wake limitation

  • 9. Debounce and event handling

  • 9.1 Reed debounce

  • 9.2 User button handling

  • 10. Programming and bring-up requirements

  • 10.1 Programming header J1

  • 10.2 Serial logs

  • 11. Firmware states

  • 12. Battery measurement

  • 13. Reliability and failure behavior

  • 14. Validation checklist for firmware developer

  • 14.1 Compile and flash

  • 14.2 GPIO validation

  • 14.3 Sleep/wake validation

  • 14.4 Wireless validation

  • 14.5 Power validation

  • 15. Known firmware starter issue to avoid

  • 16. Acceptance criteria

WiFi Door and Window Sensor

WiFi Door and Window Sensor thumbnail
A compact battery-powered door/window sensor built around the ESP32-C3-MINI-1-N4 module. The design uses a single non-rechargeable AA cell with a TPS613221A 3.3 V boost regulator, reed switch magnetic contact sensing, low-power wake/report/sleep firmware strategy, RGB status LED for setup feedback, BOOT/EN controls, programming header, and input polarity protection. It is intended for smart-home security and automation applications, supporting WiFi or Bluetooth LE hub reporting with emphasis on low idle current, reliable RF burst power delivery, and field-replaceable battery operation. #ESP32-C3 #BLE #WiFi #DoorSensor #WindowSensor #ReedSwitch #LowPower #BatteryPowered #SmartHome #IoT

Pricing & Availability

Distributor

Qty 1

Arrow

$1.62–$2.68

Digi-Key

$2.20

HQonline

$0.47

LCSC

$5.58–$5.68

Mouser

$3.94

TME

$2.92

Verical

$1.50–$4.74

Controls