Arduino Evolution: From Prototype to Global Innovation
DIY Arduino Motion Alarm: PIR Sensor Security Tutorial
Motion-activated alarms are foundational projects for learning sensor integrationIntegrating 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) sensor
Introduction to Sensors for ArduinoLearn the fundamentals of Arduino sensors, including setup, calibration, and coding examples—perfect for building interactive, smart projects with precision. and Arduino
What 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🔗
2. CircuitYour 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 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 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 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.
7. EnhancementsYour 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🔗
Component | Purpose |
---|---|
Arduino Uno/Nano | Main microcontroller unit |
PIR Sensor (HC-SR501) | Detects motion via infrared radiation |
Buzzer | Audible alarm trigger |
LED | Visual alert indicator |
220Ω Resistor | Limits current to the LED |
Jumper Wires | Connects components |
Breadboard | Prototyping platform |
PIR SensorIntroduction 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 sensors
Motion 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 sensor
Introduction 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
Component | Connection Description |
---|---|
PIR Sensor | VCC → 5V, GND → Ground, OUT → Digital Pin 2 |
LED | Anode → Digital Pin 4 via 220Ω resistor, Cathode → GND |
Buzzer | Positive → Digital Pin 3, Negative → GND |
Wiring Steps
- VCC → 5V (Arduino
What 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.)
- OUT → Digital Pin
Digital Pins and LogicExplore our comprehensive Arduino guide on digital pins and logic. Learn configuration, wiring, troubleshooting, and practical applications. 2 (Interrupt-capable for efficiency)
- GND → GND
2. Buzzer:
- Positive (+) → Digital Pin
Digital Pins and LogicExplore our comprehensive Arduino guide on digital pins and logic. Learn configuration, wiring, troubleshooting, and practical applications. 3
- Negative (-) → GND
- Anode (+) → Digital Pin 4 via 220Ω resistor
Controlling LEDs with Arduino: The BasicsLearn the essentials of Arduino LED control: proper wiring, coding with digitalWrite and PWM, plus troubleshooting tips to enhance your projects.
- Cathode (-) → GND

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);
}
}
tone()
: Generates a PWMPractical Examples: Controlling LED BrightnessLearn to adjust LED brightness using Arduino PWM techniques. This practical guide covers hardware setup, code examples, and troubleshooting tips. signal for the buzzer.
digitalRead
: Monitors PIR’s outputImplementing Button InputsUnlock the full potential of your Arduino projects with our guide on button inputs, covering wiring, debouncing, interrupts, and state machine techniques.()
Understanding Digital Signals and PinsExplore our complete Arduino guide on digital signals and pins, featuring hands-on examples and expert tips for reliable projects. state.
- Delays
Your 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.: The first delay
Your 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. (2000ms) keeps the alarm active; the second (in the else clause) adds a buffer to prevent rapid retriggering.
Sensor Calibration🔗
Most PIR sensors have two potentiometersConnecting 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 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 output
Understanding 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).
- Use the serial monitor
Using the Serial MonitorDiscover our detailed Arduino Serial Monitor guide covering setup, coding, and troubleshooting to optimize your debugging and project performance in real-time. (
Serial.println("Motion Detected!")
) to debug false positives. - Shield the sensor
Introduction to Sensors for ArduinoLearn the fundamentals of Arduino sensors, including setup, calibration, and coding examples—perfect for building interactive, smart projects with precision. from direct sunlight or HVAC vents to reduce noise.
- Test with a 5V LED
Your 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. connected to the PIR’s OUT pin to verify signal integrity.
Testing and Troubleshooting🔗
Common Issues
Issue | Solution |
---|---|
False triggers | Reduce sensitivity; check for heat sources |
No detection | Verify wiring; test with a 5V LED at PIR OUT |
Alarm doesn’t stop | Adjust time delay potentiometer |
Testing Steps
1. Power up the Arduino and open 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 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 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 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 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 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 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 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 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🔗
- Adafruit Arduino Tutorials: learn.adafruit.com/category/arduino
- Arduino Forum: forum.arduino.cc
- Arduino IDE Official Website: arduino.cc
- Arduino Project Hub: create.arduino.cc/projecthub
- SparkFun Arduino Tutorials: learn.sparkfun.com/tutorials/tags/arduino