Build Project

IoT Projects

ESP32 Smart Mailbox

Build an ESP32 smart mailbox that detects mail delivery with a reed switch and sends Telegram notifications. Covers basic alert, ESP-NOW indoor relay, and deep-sleep battery operation.

IntermediateAges 12+75-90 minUnder 25 USDParent Safe
Project Mission

Build a Mailbox Open Alert

The Story

A smart mailbox should report a state change without pretending to prevent theft. This build detects that the lid opened and gives a local alert you can later connect to Wi-Fi or ESP-NOW. This Golden version keeps the promise narrow: the parts list, code constants, GPIO table, expected output, safety notes, and troubleshooting all describe the same low-voltage educational build.

Explain Like I'm 12

A magnet keeps the reed switch in one state. When the lid moves, the switch changes and the ESP32 wakes up to say the mailbox opened. The ESP32 is the decision maker: it reads one signal, compares it with simple rules, then changes an output you can see or hear.

Learning Support

  • Recommended ageAges 12+
  • Adult supervisionAdult supervision required for outdoor placement, enclosure choices, and battery handling.
  • Classroom useUse as a privacy-aware state-change and deep-sleep example.
  • Parent promptAsk what the sensor can prove and what it cannot prove.
  • Screen-free activitySketch the lid-open/lid-closed states and the message that should be sent.
  • Next challengeAdd battery-voltage monitoring before leaving the project outdoors.
  • Skills practiced
    • Reed switch input
    • Deep sleep wake
    • Privacy-aware alerts
    • PWM buzzer output
  • Learning outcomes
    • Detect a mailbox lid opening with a reed switch.
    • Use RTC GPIO33 for deep-sleep wake.
    • Sound a short local buzzer alert.
    • Explain why this is not package security.
  • Mini experiments
    • Move the magnet and observe when the reed switch changes.
    • Change the alert tone count.
    • Compare open and closed Serial Monitor messages.

Safety Standards

  • Unplug USB before changing jumper wires. Recheck 3.3 V, 5 V, and GND before reconnecting power.
  • Do not power motors, pumps, LED strips, or servos from the ESP32 3.3 V pin. Use a suitable external supply and common ground.
  • Breadboards are for low-current prototypes. Move high-current or unattended builds to proper terminals, enclosure, strain relief, and fusing.
  • Relay and mains-voltage projects require isolation, correct relay ratings, enclosed wiring, and qualified adult supervision.
  • Li-ion battery builds need a protected cell, proper charger, fuse, and enclosure. Never charge unknown or damaged cells.

What You Will Build

A privacy-aware mailbox lid-open demo using a reed switch on GPIO33 and a passive piezo alert on GPIO25.

Learning Objectives

  • Detect a mailbox lid opening with a reed switch.
  • Use RTC GPIO33 for deep-sleep wake.
  • Sound a short local buzzer alert.
  • Explain why this is not package security.

Components List

  • ESP32 DevKit boardUSB-programmable ESP32 board used as the controller.
  • Normally open magnetic reed switchDoor/lid state input on RTC GPIO33.
  • Small magnetMounted so the switch changes when the lid opens.
  • Passive piezo buzzerShort local alert on GPIO25.
  • Weatherproof enclosureNeeded before outdoor testing.

Bill of Materials

PartQtyEstimated CostNotes
ESP32 DevKit board1VariesUSB-programmable ESP32 board used as the controller.
Normally open magnetic reed switch1VariesDoor/lid state input on RTC GPIO33.
Small magnet1VariesMounted so the switch changes when the lid opens.
Passive piezo buzzer1VariesShort local alert on GPIO25.
Weatherproof enclosure1VariesNeeded before outdoor testing.

Wiring

The reed switch uses GPIO33 with INPUT_PULLUP for the deep-sleep wake demo. The passive piezo uses GPIO25.

Wiring Diagram ESP32 Smart Mailbox wiring diagram
  1. 1

    Unplug USB before changing reed switch or buzzer wires.

  2. 2

    Connect one reed switch terminal to GPIO33.

  3. 3

    Connect the other reed switch terminal to GND.

  4. 4

    Connect passive piezo positive to GPIO25 and negative to GND.

  5. 5

    Mount the magnet so the switch changes when the lid opens.

  6. 6

    Reconnect USB and test the state before any outdoor enclosure work.

GPIO Mapping

SignalESP32 PinDirectionNotes
Reed switchGPIO33InputRTC-capable input used for ext0 wake.
Piezo buzzerGPIO25PWM OutputShort local alert tone.

Circuit Explanation

GPIO33 is held by INPUT_PULLUP and changes when the reed switch closes to ground. The ESP32 can wake from deep sleep and play a short tone on GPIO25.

Engineering Explanation

This confirms lid movement only. It does not identify mail, prevent theft, or guarantee delivery. Outdoor use needs enclosure, strain relief, and battery protection.

Libraries

  • Arduino ESP32 coreUses ESP32 deep sleep functions and LEDC PWM.

Code

Copy into Arduino IDE. Install any libraries noted in the component guides first.

esp32-smart-mailbox.ino
// ESP32 Smart Mailbox - reed switch demo on RTC GPIO33
const int REED_PIN = 33;   // RTC-capable input for ext0 wake
const int BUZZER_PIN = 25; // passive piezo alert
const int BUZZER_CHANNEL = 0;

void alertTone() {
  ledcSetup(BUZZER_CHANNEL, 2000, 8);
  ledcAttachPin(BUZZER_PIN, BUZZER_CHANNEL);
  for (int i = 0; i < 3; i++) {
    ledcWrite(BUZZER_CHANNEL, 128);
    delay(180);
    ledcWrite(BUZZER_CHANNEL, 0);
    delay(120);
  }
  ledcDetachPin(BUZZER_PIN);
}

void setup() {
  Serial.begin(115200);
  pinMode(REED_PIN, INPUT_PULLUP);
  esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
  if (cause == ESP_SLEEP_WAKEUP_EXT0) {
    Serial.println("Mailbox lid opened.");
    alertTone();
  } else {
    Serial.println("Mailbox monitor armed.");
  }
  esp_sleep_enable_ext0_wakeup(GPIO_NUM_33, 1);
  Serial.println("Entering deep sleep.");
  Serial.flush();
  esp_deep_sleep_start();
}

void loop() {}

Code Explanation

REED_PIN is GPIO33 so ext0 wake can work. After a wake event, the sketch prints a lid-open message, plays the buzzer, then returns to deep sleep.

Expected Output

Serial Monitor prints Mailbox monitor armed on first boot. When the reed switch wake condition occurs, it prints Mailbox lid opened and plays three short tones.

Troubleshooting

  • No wake event Confirm GPIO33 changes state when the reed switch moves.
  • Buzzer silent Check GPIO25 piezo wiring.
  • False alerts Move the magnet and switch closer or add mechanical stability.

Common Mistakes

  • Claiming the project prevents package theft.
  • Using GPIO4 with boot-sensitive wiring for the final design.
  • Putting an unenclosed ESP32 outdoors.
  • Inventing battery life without measurement.

Testing Checklist

  • Test reed switch with Serial Monitor before mounting.
  • Open and close the lid ten times.
  • Confirm the ESP32 re-enters deep sleep.
  • Test inside the enclosure before outdoor use.

Engineering Tips

  • Use GPIO33 for wake-capable input.
  • Keep notification wording privacy-aware.
  • Measure current before making battery claims.

Upgrade Ideas

  • Add ESP-NOW to an indoor receiver.
  • Add battery-voltage monitoring.
  • Add a small OLED setup screen for bench testing.

Real-World Applications

  • Mailbox lid-open alert
  • Reed switch lesson
  • Deep-sleep wake prototype

FAQs

Does this secure packages?

No. It only detects a lid-open event.

Why use GPIO33?

GPIO33 is RTC-capable and suitable for this wake demo.

Can it send Wi-Fi notifications?

Yes, after the local sensor and wake behavior are reliable.

Review, Testing, and References

Author: Abdul Mubeen and the ESP32 Engine editorial team. Last updated: 2026-06-27. Reviewed: wiring logic, Arduino code structure, beginner safety, and learning sequence.

Educational level: Intermediate. Estimated completion time: 75-90 min. This project is for learning and prototyping; production or unattended hardware needs additional engineering review.

Project Complete!

You completed ESP32 Smart Mailbox as a trustworthy ESP32 learning build with matching wiring, code, testing, and safety boundaries.

  • Reed switch input
  • Deep sleep wake
  • Privacy-aware alerts