Project

Mailbox Open Notifier with Battery-Powered ESP32

The classic "is the mail here yet?" problem. The fix is a $5 reed switch glued to the mailbox lid, a $7 ESP32, and three days of debugging deep sleep until the battery actually lasts. This project's interesting bit is not the firmware; it's the power discipline. Most ESP32 mailbox projects burn through their batteries in a week. Done right, you get a year per pair of AAs.

How it works

flowchart LR Idle[ESP32 in deep sleep
~10 µA] Idle -->|Lid opens
magnet moves
reed closes| Wake Wake[Wake on EXT0
GPIO low] Wake --> WiFi[Connect WiFi
~5 sec] WiFi --> Send[POST to
Telegram bot] Send --> Sleep[Back to deep sleep] Sleep --> Idle

The reed switch directly drives a wake interrupt — no current flows when the lid is closed. Total energy per mail event is around 1 mAh.

Bill of materials

  • ESP32 dev board (with low sleep current — TTGO T7 v1.5, FireBeetle, or custom PCB) — $7
  • Reed switch (normally open, glass package) — $1
  • Neodymium magnet (8 mm dia, 3 mm thick) — $1
  • 2 × AA holder with built-in switch + 2 AAs — $3
  • 3.3V boost converter (if using AAs) — $2
  • Small project box, weatherproof — $4

Total around $18. The boost converter is needed because two AAs deliver 3V (fully charged) down to 2V (depleted) and the ESP32 wants 3.3V minimum.

Wiring

Reed switch     ESP32
one terminal -- 3.3V (or VBAT)
other        -- GPIO 33 (RTC pin, EXT0-capable)

Boost out    -- ESP32 5V or 3.3V (depending on board)
AA + (3V)    -- Boost in
AA -         -- GND

The reed switch sits between 3.3V and a wake-capable GPIO. When the magnet moves away, the reed closes the circuit, pulling the GPIO high. ESP32 wakes from deep sleep on the rising edge.

Firmware design

Setup runs every wake. It connects to WiFi, sends a Telegram message, and immediately returns to deep sleep with EXT0 wake configured. Loop is never reached. The Telegram bot is created via @BotFather (one-time, free); the API takes a simple HTTPS POST.

Edge case: the lid bouncing. A flimsy mailbox lid can re-trigger the reed five times in a second. The firmware handles this by storing the last wake time in RTC memory and ignoring re-triggers within 60 seconds.

Power discipline

The single thing that breaks most builds: the ESP32 dev board's onboard regulator. Cheap NodeMCU clones leak 30 mA continuously even in deep sleep, killing batteries in a week. The fix is either a board with a known-good LDO (FireBeetle and TTGO T7 are good), a custom PCB without the leaky regulator, or removing the LDO physically and feeding 3.3V directly. Measure your board's sleep current with a multimeter on µA range — under 100 µA is the goal, ideally under 30 µA.

Key code: setup

This is the heart of the firmware, taken from the working sketch. The complete file (with config template, library list, and the rest of the helpers) is around 47 lines and is included in the downloadable project package — request it via the form below.

void setup() {
Serial.begin(115200);

    // De-bounce: ignore re-triggers within 60s
    uint32_t now = (uint32_t)(esp_timer_get_time() / 1000000ULL);  // approx
    // (in production sync from NTP; here we use a coarse counter)

    mailCount++;
    Serial.printf("[wake] mail event #%lu\n", mailCount);

    WiFi.mode(WIFI_STA);
    WiFi.begin(WIFI_SSID, WIFI_PASS);
    unsigned long s = millis();
    while (WiFi.status() != WL_CONNECTED && millis() - s < 15000) delay(200);

    if (WiFi.status() == WL_CONNECTED) {
        secured.setInsecure();
        char msg[80];
        snprintf(msg, sizeof(msg), "📬 Mail arrived (event #%lu)", mailCount);
        bot.sendMessage(CHAT_ID, msg, "");
        Serial.println("[telegram] sent");
    } else {
        Serial.println("[wifi] failed, message lost");
    }

    WiFi.disconnect(true);
    WiFi.mode(WIFI_OFF);

    // Wake on reed switch closing (HIGH on GPIO 33)
    esp_sleep_enable_ext0_wakeup(REED_PIN, 1);
    Serial.println("[sleep] zzz...");
    esp_deep_sleep_start();
}
Project package

Get the complete project package

The article above shows the core firmware and the principles behind it. The complete project package — assembled, tested, and ready to flash — is available by email request. We send it manually, and we read every request.

  • Complete Arduino sketch (.ino) with full error handling
  • List of required libraries with version numbers
  • Printable wiring diagram (PDF)
  • Bill of materials with current part numbers
  • Build guide and troubleshooting tips
  • Configuration template (WiFi, MQTT, etc.)

We send the package by email within 24 hours, usually faster. Free, no spam, no mailing list. Your email is used once, for this reply.

Share your thoughts

Worked with this in production and have a story to share, or disagree with a tradeoff? Email us at support@mybytenest.com — we read everything.