> Projects / Motion_Alarm_System

ESP32 Motion Detection
Alarm System

DATE: 2026.05.15 STATUS: ACTIVE LEVEL: BEGINNER
PIR Project

> problem

I needed a simple motion detection system for my garage. When someone enters, it should trigger a local buzzer and send a notification to my phone — all running locally, no cloud required.

> hardware

  • ESP32 Dev Board × 1
  • HC-SR501 PIR Sensor × 1
  • Active Piezo Buzzer × 1
  • Status LED × 1
  • Breadboard + Wires × 1

> wiring architecture

graph LR A[PIR Sensor] -->|GPIO 27| B[ESP32] B -->|GPIO 26| C[Piezo Buzzer] B -->|GPIO 25| D[Status LED] B -->|WiFi| E[Telegram API]

> logic flow

sequenceDiagram participant P as PIR Sensor participant E as ESP32 participant B as Buzzer/LED participant T as Telegram P->>E: Motion Detected (High Signal) E->>B: Trigger Alarm (PWM) E->>T: Send Secure Alert T->>E: Acknowledge Note over E,B: Alarm active for 30s E->>B: Reset System

> code

void setup() {
  pinMode(PIR_PIN, INPUT);
  pinMode(BUZZER_PIN, OUTPUT);
  attachInterrupt(digitalPinToInterrupt(PIR_PIN), onMotion, RISING);
}

> result

The HC-SR501 is surprisingly sensitive. I had to turn down its sensitivity potentiometer slightly to avoid false triggers from small vibrations. The interrupt-driven approach means no motion events are missed.

> SECURITY_LOG.SH

[2026-05-18 22:15:10] INFO: System armed. Monitoring GPIO 27...
[2026-05-18 23:42:01] ALERT: MOTION DETECTED - SECTOR 1 (GARAGE)
[2026-05-18 23:42:02] SUCCESS: Telegram notification sent to OPERATOR_01
[2026-05-18 23:42:32] INFO: Alarm timeout. Re-arming system...
[2026-05-18 23:42:33] SUCCESS: System ready.