wirecraft

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

Mini Map
power
ground
data
signal
analog

Parts

PartRefsQtyEst.
HC-SR501 PIR motion sensorPIR1$1.50
Passive piezo buzzerBuzzer1$0.60
LED (5 mm) + 220 Ω resistorLED1$0.15
Tactile push buttonButton1$0.10
HC-SR04 ultrasonic rangerUltrasonic1$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

src/main.cpp
1// Motion Alarm
2// 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 alert
4//
5// Wiring, parts and step-by-step assembly live alongside this file.
6
7#include <Arduino.h>
8
9#define PIR_PIN 4
10#define BUZZER_PIN 5
11#define LED_PIN 13
12#define BUTTON_PIN 14
13#define ULTRASONIC_TRIG 16
14#define ULTRASONIC_ECHO 17
15
16bool pIRMotion = false;
17bool buttonPressed = false;
18float ultrasonicCm = 0;
19
20float 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}
27
28void 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}
38
39void loop() {
40 // --- Read sensors ---
41 pIRMotion = (digitalRead(PIR_PIN) == HIGH);
42 buttonPressed = (digitalRead(BUTTON_PIN) == LOW);
43 ultrasonicCm = readUltrasonicCm(ULTRASONIC_TRIG, ULTRASONIC_ECHO);
44
45 // --- 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 }
52
53 delay(50);
54}
55
platformio.ini
1; PlatformIO project for Motion Alarm
2[env:esp32dev]
3platform = espressif32
4board = esp32dev
5framework = arduino
6monitor_speed = 115200
7

Assembly

  1. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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.