Security · ESP32 DevKit
Porch Package Guard
A ESP32 DevKit build with 5 components. Reads: PIR, Button, Ultrasonic. Drives: Buzzer, LED. Sound the buzzer when motion is detected; the button arms and disarms.
5 parts · 13 connections · 10 steps
Wiring
Parts
| Part | Refs | Qty | Est. |
|---|---|---|---|
| HC-SR501 PIR motion sensor | PIR | 1 | $1.50 |
| Passive piezo buzzer | Buzzer | 1 | $0.60 |
| LED (5 mm) + 220 Ω resistor | LED | 1 | $0.15 |
| Tactile push button | Button | 1 | $0.10 |
| HC-SR04 ultrasonic ranger | Ultrasonic | 1 | $1.90 |
| Plus: breadboard, jumper wires, USB cable | ≈ $4.25 | ||
Prices are rough hobby-market estimates. Click a part for wiring notes and specs.
Firmware
1// Motion Alarm2// Generated by Wirecraft for the ESP32 DevKit (ESP32-WROOM-32)3// Prompt: A porch security monitor with an ultrasonic sensor watching for packages, a PIR for motion, and a buzzer alert4//5// Wiring, parts and step-by-step assembly live alongside this file.67#include <Arduino.h>89#define PIR_PIN 410#define BUZZER_PIN 511#define LED_PIN 1312#define BUTTON_PIN 1413#define ULTRASONIC_TRIG 1614#define ULTRASONIC_ECHO 171516bool pIRMotion = false;17bool buttonPressed = false;18float ultrasonicCm = 0;1920float readUltrasonicCm(int trigPin, int echoPin) {21 digitalWrite(trigPin, LOW); delayMicroseconds(2);22 digitalWrite(trigPin, HIGH); delayMicroseconds(10);23 digitalWrite(trigPin, LOW);24 long us = pulseIn(echoPin, HIGH, 30000UL);25 return us > 0 ? us / 58.0f : -1.0f;26}2728void setup() {29 Serial.begin(115200);30 pinMode(PIR_PIN, INPUT);31 pinMode(BUZZER_PIN, OUTPUT);32 pinMode(LED_PIN, OUTPUT);33 pinMode(BUTTON_PIN, INPUT_PULLUP);34 pinMode(ULTRASONIC_TRIG, OUTPUT);35 pinMode(ULTRASONIC_ECHO, INPUT);36 Serial.println(F("Motion Alarm ready."));37}3839void loop() {40 // --- Read sensors ---41 pIRMotion = (digitalRead(PIR_PIN) == HIGH);42 buttonPressed = (digitalRead(BUTTON_PIN) == LOW);43 ultrasonicCm = readUltrasonicCm(ULTRASONIC_TRIG, ULTRASONIC_ECHO);4445 // --- React ---46 // Sound the buzzer when motion is detected; the button arms and disarms.47 if (pIRMotion) {48 tone(BUZZER_PIN, 880);49 } else {50 noTone(BUZZER_PIN);51 }5253 delay(50);54}551; PlatformIO project for Motion Alarm2[env:esp32dev]3platform = espressif324board = esp32dev5framework = arduino6monitor_speed = 1152007Assembly
- 1
Lay out your workbench
Gather the ESP32 DevKit, a half-size breadboard, and a bundle of male-to-male jumper wires. Keep the parts list open — every component below gets its own spot on the breadboard. Don't plug in USB power until the last wire is placed.
- 2
Seat the board and power rails
Run a red jumper from the ESP32 DevKit's 3V3 (or VIN for 5 V parts) pin to the breadboard's + rail, and a black jumper from GND to the − rail. Every component's power and ground will tap these rails.
- 3
Wire the PIR
Place the HC-SR501 PIR motion sensor on the breadboard. Power first: VCC → + rail, GND → − rail. Then signals: OUT → GPIO4. Tip: Give it 30–60 s to settle after power-up, and turn both trim pots fully counter-clockwise to start.
- 4
Wire the Buzzer
Place the Passive piezo buzzer on the breadboard. Power first: GND → − rail. Then signals: SIG → GPIO5. Tip: Passive buzzers need tone(); active ones just want HIGH. This design assumes passive.
- 5
Wire the LED
Place the LED (5 mm) + 220 Ω resistor on the breadboard. Power first: CATHODE → − rail. Then signals: ANODE → GPIO13. Tip: The longer leg is the anode (+). The resistor can go on either leg.
- 6
Wire the Button
Place the Tactile push button on the breadboard. Power first: GND → − rail. Then signals: SIG → GPIO14. Tip: Legs on the same side are connected in pairs — wire diagonally opposite corners to be safe.
- 7
Wire the Ultrasonic
Place the HC-SR04 ultrasonic ranger on the breadboard. Power first: VCC → + rail, GND → − rail. Then signals: TRIG → GPIO16, ECHO → GPIO17. Tip: On 3.3 V boards, put a voltage divider (1 kΩ / 2 kΩ) on ECHO — the module echoes at 5 V.
- 8
Double-check before power
Trace every wire against the diagram once more — 13 connections in total. The classic mistakes: swapped power and ground, and off-by-one rows on the breadboard. Thirty seconds of checking saves a component.
- 9
Flash the firmware
Open the exported folder in VS Code with the PlatformIO extension (free), plug in the ESP32 DevKit over USB, and hit Upload. PlatformIO fetches the libraries listed in platformio.ini automatically. Prefer the Arduino IDE? Copy src/main.cpp into a new sketch and install the same libraries from the Library Manager.
- 10
Bring it to life
Open the Serial Monitor at 115200 baud to watch live readings. Sound the buzzer when motion is detected; the button arms and disarms. Adjust the thresholds at the top of the sketch to match your environment.