Build a Battery-Powered ESP32 Smart Mailbox Notifier
A smart mailbox notifier solves an annoyingly common problem — walking out to check an empty mailbox, or missing a package delivery notification because you weren't watching a doorbell camera app. This build uses a simple reed switch or door sensor on the mailbox, paired with an ESP32 running on battery, to send a notification the moment the mailbox opens.
Why This Approach Over a Commercial Smart Mailbox Sensor
Commercial mailbox sensors exist, but they're often expensive for what's fundamentally a simple job, tied to a specific app/cloud service, and not something you can easily customize (multiple mailboxes, custom notification logic, integration with a broader home automation setup). This build costs a fraction of the price and integrates directly with whatever notification system you already use.
Parts List
ComponentNotes ESP32 dev board (low-power variant preferred)Since this runs on battery outdoors, power efficiency matters more here than raw performance — any standard ESP32 works, but boards specifically designed for low deep-sleep current draw last longer between charges Magnetic reed switchThe same type used in home security door sensors — one half mounts on the mailbox door, the other on the frame, and the circuit opens/closes as the door moves away from/toward the magnet LiPo battery + charge boardSized based on how often the mailbox opens and your deep-sleep power draw — a mailbox that's checked once daily needs far less capacity than a busy multi-unit box Weatherproof enclosureEven inside a metal mailbox, the electronics need protection from moisture and temperature swings — a small weatherproof project box is worth the few extra dollars Optional: small solar panel + charge controllerFor a mailbox in reasonably sunny placement, this can make the whole system essentially maintenance-freeHow It Works
The reed switch is wired to an ESP32 GPIO configured to trigger a wake-from-deep-sleep event. The ESP32 spends essentially all its time in deep sleep, drawing negligible current, and only wakes when the mailbox door's motion physically breaks or makes the magnetic contact — at that point it wakes, connects to WiFi, sends a notification, and immediately goes back to sleep. This event-driven wake pattern (rather than periodic polling) is what makes long battery life practical here, since the ESP32 is essentially off except for the few seconds around an actual mailbox event.
Wiring
- Reed switch: one leg to an ESP32 GPIO capable of external wake interrupt (check your specific board's deep-sleep wake-capable pins), the other leg to ground, with the GPIO configured with an internal pull-up so the resting state reads HIGH and triggers LOW when the switch opens (or vice versa depending on your specific reed switch orientation — test both states to confirm which matches "mailbox opened")
- Battery: through the charge board's output to the ESP32's battery/VIN input, following your specific board's power input requirements
Firmware
#include <WiFi.h> #include <HTTPClient.h> #define WAKE_PIN GPIO_NUM_33 // must be an RTC GPIO capable of EXT0 wake RTC_DATA_ATTR int bootCount = 0; void sendNotification() { WiFi.begin("your-ssid", "your-password"); int attempts = 0; while (WiFi.status() != WL_CONNECTED && attempts < 20) { delay(500); attempts++; } if (WiFi.status() == WL_CONNECTED) { HTTPClient http; // Any notification service with a simple HTTP trigger works here — // a home automation webhook, a push notification service API, etc. http.begin("http://your-home-server/api/mailbox-alert"); http.POST("{\"event\":\"opened\"}"); http.end(); } } void setup() { bootCount++; esp_sleep_wakeup_cause_t wakeup_reason = esp_sleep_get_wakeup_cause(); if (wakeup_reason == ESP_SLEEP_WAKEUP_EXT0) { sendNotification(); } // Configure wake source for next sleep cycle esp_sleep_enable_ext0_wakeup(WAKE_PIN, 0); // wake on LOW — matches pull-up config esp_deep_sleep_start(); } void loop() { // never reached — everything happens in setup() after each wake }The pattern here is deliberately different from a typical Arduino sketch — there's no ongoing loop(), because the whole point is the ESP32 spends its life asleep and only briefly wakes to handle one specific event before immediately sleeping again.
Notification Options
MethodNotes Home Assistant webhookIf you're already running Home Assistant, a simple webhook automation can trigger a push notification, and gives you a full event history/log for free Push notification service (Pushover, ntfy, etc.)Direct HTTP POST to a notification service's API, no home automation platform required Simple SMS/email via a scripting serviceWorks, but generally slower and less immediate-feeling than a push notificationExtending: Package Detection
The basic build tells you the mailbox door opened — it doesn't distinguish "mail was delivered" from "you checked the mailbox and it was empty." A few ways to add that distinction:
- Weight sensor under the mail compartment, reporting whether contents are present — more complex to build but gives a genuinely useful "there's mail waiting" status rather than just "door was opened"
- Time-of-day logic — if your mail carrier reliably arrives in a known window, you can flag door-open events during that window as likely-delivery versus events outside it as likely you checking
- Second reed switch or light sensor as a rough presence-of-mail proxy, depending on your mailbox's physical layout
Battery Life Expectations and Tips
- Deep sleep current draw for a well-configured ESP32 can be in the microamp range — the dominant power cost is actually the brief WiFi connection and transmission on each wake, not the sleeping time between events
- A mailbox checked once or twice daily should comfortably run for weeks to months on a modest LiPo, depending on your specific board's sleep efficiency
- If battery life is disappointing, verify with a multimeter that deep sleep current is actually low — some peripherals (certain sensors, onboard LEDs) draw current even during "sleep" unless explicitly powered down or disabled in code
This is a small project with an outsized quality-of-life payoff — a notification the moment mail arrives, instead of a daily "walk out and check" habit, for the cost of a few cheap components and an afternoon of setup.
Related Guides
- Build a Standalone ESP32 WiFi Security Testing Tool with Marauder
- Build a Battery-Powered Raspberry Pi Wildlife Trail Camera with PIR Trigger
- Tying It Together: Pi + ESP32 + Flipper Home Automation Hub
- ESP32-CAM as a Doorbell/Mailbox Camera with Notifications
- ESP32 Deep Sleep & Battery Optimization for Solar/Battery Projects
- MQTT and Node-RED on Raspberry Pi: Visual Automation for ESP32 Sensor Networks
- Driving E-Paper Displays with ESP32 and Arduino: SPI Wiring, GxEPD2, and Partial Refresh
- Homebridge on Raspberry Pi: Bringing Non-HomeKit Devices and DIY ESP32 Sensors into Apple Home