BeginnerSecurity and Automation

PIR Motion Alarm

Use a PIR module and microcontroller to sound a small buzzer when motion is detected.

Estimated time: 45โ€“60 minutes ยท Skills: Digital sensor modules, GPIO, input stabilization

Parts from the database

Other supplies

Amazon links may be affiliate links. As an Amazon Associate, Electronics Hobby Hub earns from qualifying purchases.

Connections

  1. Power the PIR module according to its board labeling; connect GND to ESP32 GND and OUT to GPIO 27.
  2. Confirm the module output voltage is safe for the ESP32 input. If the module is powered from 5 V, use a divider or level shifter unless its OUT is confirmed 3.3 V-safe.
  3. Connect the active buzzer through a suitable transistor driver to GPIO 26; do not draw buzzer current directly from an MCU pin.

Build steps

  1. Set the PIR sensitivity and hold-time controls near their low settings for initial tests.
  2. Upload the sketch and wait through the sensor's warm-up period.
  3. Move across the sensor's field of view and observe the serial messages and buzzer.
  4. Adjust sensitivity and module hold time only after the wiring and stable idle state are confirmed.

Software and firmware setup

const int pirPin=27, buzzerPin=26;
void setup(){ pinMode(pirPin,INPUT); pinMode(buzzerPin,OUTPUT); Serial.begin(115200); }
void loop(){ bool motion=digitalRead(pirPin); digitalWrite(buzzerPin,motion?HIGH:LOW); Serial.println(motion?"Motion":"Clear"); delay(100); }

Review the pin assignments in the sketch against the wiring table before uploading.

Test your build

After warm-up, the output should go high when a person moves through the field of view and return low after the module's hold interval.

Troubleshooting

  • False triggers during warm-up are common; wait the module's recommended stabilization time.
  • If the ESP32 resets, power the buzzer from a separate suitable supply and share ground through its transistor driver.
  • If the input voltage is uncertain, measure the module output before connecting it to the ESP32.

Safety and limitations

This is a hobby demonstrator, not a security or life-safety alarm. Do not expose ESP32 GPIO to 5 V.

Manufacturer and platform documentation

Community Notes for This Project

These are unverified visitor contributions, separate from the build guide and manufacturer specifications. Verify technical advice against the linked datasheets before relying on it.

Set up the comments service to load community notes.

Share a tip or question about this build

โ† Browse all projects