wirecraft

Time · ESP32 DevKit

Dawn Chorus Alarm

A ESP32 DevKit build with 6 components. Reads: PIR, Button, Light sensor. Drives: Buzzer, LED, OLED. Sound the buzzer when motion is detected; the button arms and disarms.

6 parts · 16 connections · 11 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
SSD1306 OLED display (128×64, I²C)OLED1$3.20
Photoresistor (LDR) + 10 kΩ dividerLightSensor1$0.40
Plus: breadboard, jumper wires, USB cable≈ $5.95

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: An alarm clock with an OLED display, rotary encoder to set the alarm, buzzer melodies and a light sensor to dim at night
4//
5// Wiring, parts and step-by-step assembly live alongside this file.
6
7#include <Arduino.h>
8#include <Wire.h>
9#include <Adafruit_GFX.h>
10#include <Adafruit_SSD1306.h>
11
12#define PIR_PIN 4
13#define BUZZER_PIN 5
14#define LED_PIN 13
15#define BUTTON_PIN 14
16#define LIGHTSENSOR_PIN 32
17
18bool pIRMotion = false;
19bool buttonPressed = false;
20Adafruit_SSD1306 oLED(128, 64, &Wire, -1);
21int lightSensorLevel = 0;
22
23void setup() {
24 Serial.begin(115200);
25 pinMode(PIR_PIN, INPUT);
26 pinMode(BUZZER_PIN, OUTPUT);
27 pinMode(LED_PIN, OUTPUT);
28 pinMode(BUTTON_PIN, INPUT_PULLUP);
29 if (!oLED.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { Serial.println(F("OLED not found")); }
30 oLED.clearDisplay();
31 oLED.setTextColor(SSD1306_WHITE);
32 oLED.setTextSize(1);
33 Serial.println(F("Motion Alarm ready."));
34}
35
36void loop() {
37 // --- Read sensors ---
38 pIRMotion = (digitalRead(PIR_PIN) == HIGH);
39 buttonPressed = (digitalRead(BUTTON_PIN) == LOW);
40 lightSensorLevel = analogRead(LIGHTSENSOR_PIN);
41
42 // --- React ---
43 // Sound the buzzer when motion is detected; the button arms and disarms.
44 if (pIRMotion) {
45 tone(BUZZER_PIN, 880);
46 } else {
47 noTone(BUZZER_PIN);
48 }
49
50 // Refresh the display with live readings
51 oLED.clearDisplay();
52 oLED.setCursor(0, 0);
53 oLED.setCursor(0, 0);
54 oLED.print("PIR: "); oLED.println(pIRMotion);
55 oLED.setCursor(0, 12);
56 oLED.print("Button: "); oLED.println(buttonPressed);
57 oLED.setCursor(0, 24);
58 oLED.print("Light sensor: "); oLED.println(lightSensorLevel);
59 oLED.display();
60
61 delay(50);
62}
63
platformio.ini
1; PlatformIO project for Motion Alarm
2[env:esp32dev]
3platform = espressif32
4board = esp32dev
5framework = arduino
6monitor_speed = 115200
7lib_deps =
8 adafruit/Adafruit SSD1306@^2.5.10
9 adafruit/Adafruit GFX Library@^1.11.9
10

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 OLED

    Place the SSD1306 OLED display (128×64, I²C) on the breadboard. Power first: VCC → + rail, GND → − rail. Then signals: SDA → GPIO21, SCL → GPIO22. Tip: If nothing shows up, try I²C address 0x3D — some modules ship with it.

  8. 8

    Wire the Light sensor

    Place the Photoresistor (LDR) + 10 kΩ divider on the breadboard. Power first: VCC → + rail, GND → − rail. Then signals: SIG → GPIO32. Tip: LDR to VCC, 10 kΩ to GND, read the midpoint. Brighter light = higher reading.

  9. 9

    Double-check before power

    Trace every wire against the diagram once more — 16 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.

  10. 10

    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.

  11. 11

    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.