BeginnerSecurity and Automation
PIR Motion Alarm
Use a PIR module and microcontroller to sound a small buzzer when motion is detected.
Parts from the database
- PIR-DYP-ME003 ร 1PIR motion sensor module
- ESP32-WROOM-32 ร 1Use on an ESP32 development board
Other supplies
- ESP32 development boardCommon build supply
- small active buzzerCommon build supply
- breadboardCommon build supply
- jumper wiresCommon build supply
- USB cableCommon build supply
Amazon links may be affiliate links. As an Amazon Associate, Electronics Hobby Hub earns from qualifying purchases.
Connections
- Power the PIR module according to its board labeling; connect GND to ESP32 GND and OUT to GPIO 27.
- 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.
- Connect the active buzzer through a suitable transistor driver to GPIO 26; do not draw buzzer current directly from an MCU pin.
Build steps
- Set the PIR sensitivity and hold-time controls near their low settings for initial tests.
- Upload the sketch and wait through the sensor's warm-up period.
- Move across the sensor's field of view and observe the serial messages and buzzer.
- 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); }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.