Projects / Mailbox alert

Mailbox alert

Beginner1 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. ESP32

    Test the reed switch

    Print its state when the magnet moves.

  2. ESP32

    Add deep sleep

    Wake on the pin going high.

  3. ESP32

    Send a message

    ESP-NOW with a count.

  4. ESP32

    Make the home unit

    Beep on receipt.

  5. ESP32

    Test the range

    Walk to the mailbox with the home unit.

  6. ESP32

    Seal the box

    Waterproof, away from the mail slot.

  7. ESP32++

    Check the battery

    Measure the sleep current.

In short

How do you build a mailbox alert?

A tilt switch or hall sensor in the mailbox sends a message when mail arrives. You need ESP32-C3 SuperMini, Door reed switch MC-38, Battery holder 2 × AA, AA alkaline battery × 2 and Resistor 100 kΩ. It takes 7 steps and about 60 minutes.

Level
Beginner
Time
About 60 min
Parts
5

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
Reed switch one sideXIAO D0 (GPIO2)Wake input
Reed switch other sideGNDClosed (LOW) when the magnet is near, which is when the lid is shut
100 kΩ resistorXIAO D0 to 3V3Pulls the pin high when the lid opens
Battery holder plusXIAO 3V3 pin2 AA cells (3 V) power the board directly
Battery holder minusXIAO GNDGround

Code

The ESP32-C3 sleeps almost all the time, drawing a few microamps, and wakes only when the magnet moves away from the reed switch as the mailbox lid opens. It then sends a short ESP-NOW message with a running count and goes back to sleep after the lid has settled. The home unit is a second ESP32 that beeps and flashes on receipt. The 100 kΩ resistor holds the wake pin high when the lid is open, and draws only about 30 µA while the lid is shut, which still lets two AA cells last for years. Fit the electronics in a waterproof box inside the mailbox, away from the opening so that mail does not crush it, and put the magnet on the lid. Range through walls is typically 20 to 40 metres, so test from the house before fixing it. The message is unencrypted; the only thing it tells is that the lid opened. Do not use it as a security alarm for valuables. Arduino IDE with the ESP32 boards package 2.0.x, board "XIAO_ESP32C3".

Runs on a virtual ESP32-C3 in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

// Mailbox sensor: sleep until the lid opens, send an ESP-NOW message, sleep again. Board: XIAO ESP32C3, package 2.0.x.
#include <WiFi.h>
#include <esp_now.h>
#include <driver/gpio.h>

uint8_t HOME[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};       // broadcast, or the home unit's own address
RTC_DATA_ATTR uint16_t count = 0;                             // counts the times the lid opened, survives sleep
const gpio_num_t WAKE_PIN = GPIO_NUM_2;                       // D0 on the XIAO ESP32C3

void setup() {
  count++;
  WiFi.mode(WIFI_STA); esp_now_init();
  esp_now_peer_info_t p = {}; memcpy(p.peer_addr, HOME, 6); p.channel = 0; p.encrypt = false; esp_now_add_peer(&p);
  uint16_t msg[1] = { count };
  esp_now_send(HOME, (uint8_t*)msg, sizeof(msg));
  delay(100);                                                 // let the message go out

  delay(3000);                                                // lid bounce: wait until it settles
  esp_deep_sleep_enable_gpio_wakeup(1ULL << WAKE_PIN, ESP_GPIO_WAKEUP_GPIO_HIGH);   // wake when the pin goes high (lid opened)
  esp_deep_sleep_start();
}

void loop() {}

/* ---- HOME UNIT (any ESP32 with an LED and a buzzer on GPIO 2 and 4)
#include <WiFi.h>
#include <esp_now.h>
void onData(const uint8_t* mac, const uint8_t* data, int len) {
  for (int i = 0; i < 3; i++) { digitalWrite(2, HIGH); tone(4, 1800, 150); delay(300); digitalWrite(2, LOW); delay(150); }
}
void setup() { pinMode(2, OUTPUT); WiFi.mode(WIFI_STA); esp_now_init(); esp_now_register_recv_cb(onData); }
void loop() {}
*/

What the serial monitor should show

Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual ESP32-C3 DevKitM-1 with its sensors at their default values. Your numbers will follow your real readings, but the format should match.

[deep sleep for 60 min 0 s]

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Open the lidHome unit beeps within a second
Close itNothing happens until the next opening
CountRises with each opening
Left for a weekStill works

If it does not work

Wakes constantly

Check the pull-up and the magnet position.

No message

Check both units use the same package version and are in range.

Short battery life

Measure sleep current and remove power LEDs.

Never wakes

Check the wake level and the GPIO number.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the mailbox alert?

ESP32-C3 SuperMini, Door reed switch MC-38, Battery holder 2 × AA, AA alkaline battery × 2 and Resistor 100 kΩ.

How long does the mailbox alert take to build?

About 60 minutes for a beginner maker, in 7 steps.

How do I know the mailbox alert works?

Open the lid: Home unit beeps within a second. Close it: Nothing happens until the next opening. Count: Rises with each opening.

Wakes constantly: what should I check?

Check the pull-up and the magnet position.

No message: what should I check?

Check both units use the same package version and are in range.

Short battery life: what should I check?

Measure sleep current and remove power LEDs.

Never wakes: what should I check?

Check the wake level and the GPIO number.