DIY Arduino Motion Alarm: PIR Sensor Security Tutorial

Motion-activated alarms are foundational projects for learning sensor integrationIntegrating Third-Party LibrariesIntegrating Third-Party LibrariesLearn to integrate third-party libraries into Arduino projects with our guide. Discover tips on selection, installation, coding, and troubleshooting. and automation. Using a Passive Infrared (PIR) sensorIntroduction to Sensors for ArduinoIntroduction to Sensors for ArduinoLearn the fundamentals of Arduino sensors, including setup, calibration, and coding examples—perfect for building interactive, smart projects with precision. and ArduinoWhat is Arduino? A Comprehensive OverviewWhat is Arduino? A Comprehensive OverviewDive into the world of Arduino with our in-depth guide covering hardware, software, and community projects ideal for students, hobbyists, and educators., you’ll create a system that triggers audible/visual alerts when movement is detected. This project is ideal for security applications, interactive installations, or energy-saving systems.

Table of Contents🔗

1. Components Needed

2. CircuitYour First Hands-On Arduino ProjectYour First Hands-On Arduino ProjectEmbark on your Arduino journey with our step-by-step guide. Learn to build a simple circuit, write your first code, and troubleshoot your project easily. Assembly

3. CodeYour First Hands-On Arduino ProjectYour First Hands-On Arduino ProjectEmbark on your Arduino journey with our step-by-step guide. Learn to build a simple circuit, write your first code, and troubleshoot your project easily. Breakdown

4. Sensor CalibrationInterfacing and Calibrating Various SensorsInterfacing and Calibrating Various SensorsDiscover essential techniques to interface and calibrate sensors with Arduino. Enhance measurement accuracy with practical examples and troubleshooting tips.

5. Testing and TroubleshootingYour First Hands-On Arduino ProjectYour First Hands-On Arduino ProjectEmbark on your Arduino journey with our step-by-step guide. Learn to build a simple circuit, write your first code, and troubleshoot your project easily.

6. Real-World Applications

7. EnhancementsYour First Hands-On Arduino ProjectYour First Hands-On Arduino ProjectEmbark on your Arduino journey with our step-by-step guide. Learn to build a simple circuit, write your first code, and troubleshoot your project easily. and Future Ideas

8. Conclusion

Components Needed🔗

ComponentPurpose
Arduino Uno/NanoMain microcontroller unit
PIR Sensor (HC-SR501)Detects motion via infrared radiation
BuzzerAudible alarm trigger
LEDVisual alert indicator
220Ω ResistorLimits current to the LED
Jumper WiresConnects components
BreadboardPrototyping platform

PIR SensorIntroduction to Sensors for ArduinoIntroduction to Sensors for ArduinoLearn the fundamentals of Arduino sensors, including setup, calibration, and coding examples—perfect for building interactive, smart projects with precision. Theory: PIR sensorsMotion Detection with PIR SensorsMotion Detection with PIR SensorsMaster Arduino PIR motion detection with practical wiring tips, code examples, and troubleshooting for optimal sensor performance. detect changes in infrared radiation (e.g., body heat). They have a 120° detection range and adjustable sensitivity (0-7 meters). The sensorIntroduction to Sensors for ArduinoIntroduction to Sensors for ArduinoLearn the fundamentals of Arduino sensors, including setup, calibration, and coding examples—perfect for building interactive, smart projects with precision. is passive, meaning it doesn’t emit energy-it only detects infrared light variations.

Circuit Assembly🔗

Schematic Overview

ComponentConnection Description
PIR SensorVCC → 5V, GND → Ground, OUT → Digital Pin 2
LEDAnode → Digital Pin 4 via 220Ω resistor, Cathode → GND
BuzzerPositive → Digital Pin 3, Negative → GND

Wiring Steps

1. PIR SensorIntroduction to Sensors for ArduinoIntroduction to Sensors for ArduinoLearn the fundamentals of Arduino sensors, including setup, calibration, and coding examples—perfect for building interactive, smart projects with precision.:

2. Buzzer:

3. LEDYour First Hands-On Arduino ProjectYour First Hands-On Arduino ProjectEmbark on your Arduino journey with our step-by-step guide. Learn to build a simple circuit, write your first code, and troubleshoot your project easily.:

Circuit Diagram

Code Breakdown🔗

const int pirPin = 2;     // PIR output pin
const int buzzerPin = 3;  // Buzzer control
const int ledPin = 4;     // LED indicator
void setup() {
  pinMode(pirPin, INPUT);
  pinMode(buzzerPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);     // For debugging
}
void loop() {
  int motion = digitalRead(pirPin);
  if (motion == HIGH) {
    Serial.println("Motion detected!");
    digitalWrite(ledPin, HIGH);
    tone(buzzerPin, 1000, 500); // 1kHz tone for 500ms
    delay(2000);                // Alarm duration
  } else {
    digitalWrite(ledPin, LOW);
    noTone(buzzerPin);
  }
}

Key FunctionsCreating Custom FunctionsCreating Custom FunctionsElevate your Arduino projects with custom functions. Our guide features practical examples, troubleshooting advice, and best practices for clear, modular code.:

Sensor Calibration🔗

Most PIR sensors have two potentiometersConnecting LCD DisplaysConnecting LCD DisplaysDiscover how to connect and program LCD displays with Arduino in this comprehensive guide. Learn wiring, coding, and troubleshooting for optimum performance.:

1. Sensitivity: Adjusts detection range (clockwise = ↑ range).

2. Time DelayYour First Hands-On Arduino ProjectYour First Hands-On Arduino ProjectEmbark on your Arduino journey with our step-by-step guide. Learn to build a simple circuit, write your first code, and troubleshoot your project easily.: Sets how long the outputUnderstanding Digital Signals and PinsUnderstanding Digital Signals and PinsExplore our complete Arduino guide on digital signals and pins, featuring hands-on examples and expert tips for reliable projects. stays HIGH after detection (clockwise = ↑ delay).

TestingYour First Hands-On Arduino ProjectYour First Hands-On Arduino ProjectEmbark on your Arduino journey with our step-by-step guide. Learn to build a simple circuit, write your first code, and troubleshoot your project easily. Tips:

Testing and Troubleshooting🔗

Common Issues

IssueSolution
False triggersReduce sensitivity; check for heat sources
No detectionVerify wiring; test with a 5V LED at PIR OUT
Alarm doesn’t stopAdjust time delay potentiometer

Testing Steps

1. Power up the Arduino and open the Serial MonitorUsing the Serial MonitorUsing the Serial MonitorDiscover our detailed Arduino Serial Monitor guide covering setup, coding, and troubleshooting to optimize your debugging and project performance in real-time..

2. Wave your hand in front of the sensorIntroduction to Sensors for ArduinoIntroduction to Sensors for ArduinoLearn the fundamentals of Arduino sensors, including setup, calibration, and coding examples—perfect for building interactive, smart projects with precision.. The LED and buzzer should activate for 2 seconds.

3. Adjust potentiometersConnecting LCD DisplaysConnecting LCD DisplaysDiscover how to connect and program LCD displays with Arduino in this comprehensive guide. Learn wiring, coding, and troubleshooting for optimum performance. to fine-tune responsiveness.

Real-World Applications🔗

1. Home Security: Mount near entry points; pair with an SD card logger to record intrusion times.

2. Pet Monitoring: Trigger a camera when pets approach restricted areas.

3. Energy SavingsAutomated Irrigation System with Sensors and RelaysAutomated Irrigation System with Sensors and RelaysDiscover how to design and implement an automated irrigation system using sensors and relays to efficiently manage water and enhance plant care.: Activate lights only when motion is detected in a room.

4. Occupancy Detection: Automate HVAC systems in offices based on human presence.

Enhancements and Future Ideas🔗

1. Wireless Alerts: Add an ESP8266Connecting Arduino to the InternetConnecting Arduino to the InternetDiscover how to connect your Arduino to the Internet with our complete guide covering hardware, protocols, coding tips, and troubleshooting for IoT projects./GSM module to send SMS/email notifications.

2. Camera IntegrationIntegrating Third-Party LibrariesIntegrating Third-Party LibrariesLearn to integrate third-party libraries into Arduino projects with our guide. Discover tips on selection, installation, coding, and troubleshooting.: Trigger a camera to capture images/video on detection.

3. Multi-Zone Coverage: Chain multiple PIR sensorsMotion Detection with PIR SensorsMotion Detection with PIR SensorsMaster Arduino PIR motion detection with practical wiring tips, code examples, and troubleshooting for optimal sensor performance. for large areas.

4. Machine Learning: Use a Raspberry Pi to differentiate humans from pets.

5. Cloud IntegrationIntegrating Third-Party LibrariesIntegrating Third-Party LibrariesLearn to integrate third-party libraries into Arduino projects with our guide. Discover tips on selection, installation, coding, and troubleshooting.: Log motion events to platforms like AWS IoT or Blynk.

Conclusion🔗

By completing this project, you’ve built a functional motion-activated alarm using Arduino and a PIR sensor. This foundation opens doors to advanced IoT and automation projects, from smart home security to energy-efficient systems. Keep experimenting with enhancementsYour First Hands-On Arduino ProjectYour First Hands-On Arduino ProjectEmbark on your Arduino journey with our step-by-step guide. Learn to build a simple circuit, write your first code, and troubleshoot your project easily. like wireless alerts or multi-sensor networks to expand your skills.

Happy building and stay innovative!

Author: Marcelo V. Souza - Engenheiro de Sistemas e Entusiasta em IoT e Desenvolvimento de Software, com foco em inovação tecnológica.

References🔗

Share article

Related Articles