✨ DOWNLOAD OUR APP - Use RCAPP
for additional 5% discount! + Redeem RC COINS 👇
Skip to content
Free Delivery on Orders Above Rs 500/- Pan-India
Cash on Delivery Available for Orders above Rs.500/- and Upto Rs 3000/-
SAVE more when you BUY more. Upto 30% Off on BULK PURCHASE
GST Invoices for Your Business
Dedicated Technical Support Team
Safely Delivering Genuine Products PAN INDIA
  Support

Interfacing PIR Motion Sensor with Arduino

Interfacing PIR Motion Sensor with Arduino - Cover image

What Is a PIR Motion Sensor?

The PIR Motion Sensor monitors the infrared radiation levels in its field of view, waiting for something warm-blooded, like a human or animal, to pass by. The moment it detects a change in infrared energy, it springs into action.

Unlike other kinds of sensors, the PIR Motion sensor doesn't emit anything. There are no infrared beams or radio waves shooting out. It just passively observes. That's where the "Passive" in PIR comes from. Instead, it detects using the pyroelectric material.

PIR Motion Sensor

The pyroelectric material generates electricity when exposed to heat. When you walk past it, your body heat creates a rapid change in the infrared radiation pattern, and the sensor picks up on this shift. 

Most PIR sensors come packaged in white dome-shaped modules. Inside that dome sits a Fresnel lens. These segmented, faceted lenses look like dozens of tiny bubbles.

This lens divides the detection area into multiple zones, making the sensor far more sensitive to movement across its field rather than just straight-on approaches. 

The detection range typically extends from 3 to 7 meters. The field of view usually spans around 120 degrees, creating a cone-shaped detection zone. Some sensors also include adjustable potentiometers that let you fine-tune sensitivity and the duration the output signal stays high after detecting motion. 

Working Principle of a PIR Sensor 

The sensor contains two infrared-sensitive elements positioned side by side. In a stable environment with no movement, both elements receive the same amount of infrared radiation, and their outputs cancel each other out. The sensor remains in a low state. 

When motion occurs, the scenario changes dramatically. Imagine someone walking across the sensor's field of view. First, one sensing element detects the infrared signature of the moving person, while the other doesn't, creating an imbalance.

As the person continues moving, the second element picks up the heat signature. This differential change triggers the sensor's internal comparator circuit, which then drives the output pin high. 

The sensor includes built-in signal processing circuitry. This typically consists of: 

  • A high-gain operational amplifier that boosts the tiny electrical signals from the pyroelectric elements 
  • A comparator that converts the analog signal into a digital output 
  • Timing circuitry that controls how long the output remains high 
  • Optional retriggering logic that can extend the detection signal if motion continues 

Most sensors operate in one of two modes. In repeatable trigger mode, the output stays high as long as motion continues within the detection zone. In non-repeatable trigger mode, the output goes high for a preset time and won't trigger again until that period expires, regardless of continued motion. 

Components Required for This Project 

Make sure you have the following components before you get started with the project: 

Optional but recommended components include a buzzer for audio alerts and a relay module if you plan to switch higher-voltage devices. You can build a functional motion detection using Arduino with just a handful of inexpensive components available at any electronics store. 

Circuit Diagram for Interfacing PIR Sensor with Arduino

Circuit Diagram for Interfacing PIR Sensor with Arduino

Let's break down what's happening in this circuit, because understanding the connections makes building it ten times easier. 

Looking at the image, you've got two main players here: the HC-SR501 PIR sensor sitting at the top and the Arduino Uno board below it. Three wires connect them together and that's all it takes to get motion detection working. 

Looking at this circuit, you've got the HC-SR501 PIR sensor at the top connected to the Arduino Uno below it. 

Here's what's happening with the three wires: 

  • Black wire (GND): Runs from the sensor's left pin to Arduino's ground—this completes the circuit 
  • White wire (VCC): Middle pin connects to Arduino's 5V output, powering up the sensor 
  • Red wire (Signal): Right pin goes to digital pin 7, sending HIGH when motion's detected 

PIR Sensor Pin Configuration and Connections 

The HC-SR501 module keeps things simple with just three pins to work with. Once you know what each one does, you're halfway there. 

The three pins break down like this: 

  • VCC (Power): Supplies operating voltage between 4.5V to 12V. Most projects use the Arduino's 5V output, which works perfectly 
  • GND (Ground): Completes the electrical circuit. Connect this to any Arduino ground pin 
  • OUT (Signal): The digital output pin that goes HIGH (3.3-5V) when motion's detected, LOW otherwise

Arduino Code for PIR Motion Sensor 

The code that brings your Arduino with PIR Motion Sensor to life is quite simple. Here's a complete, working program with detailed explanations:


const int pirPin = 2;        // PIR sensor output connected to pin 2 
const int ledPin = 13;       // LED connected to pin 13 
int pirState = LOW;          // Start assuming no motion detected 
int val = 0;                 // Variable to store sensor status 
 
void setup() { 
  pinMode(ledPin, OUTPUT);   // Set LED pin as output 
  pinMode(pirPin, INPUT);    // Set PIR pin as input 
  Serial.begin(9600);        // Initialize serial communication 
  delay(2000);               // Give sensor time to stabilize 
  Serial.println("PIR Sensor Ready"); 
} 
 
void loop() { 
  val = digitalRead(pirPin); // Read the sensor output 
   
  if (val == HIGH) {         // Motion detected 
    digitalWrite(ledPin, HIGH); 
     
    if (pirState == LOW) { 
      Serial.println("Motion Detected!"); 
      pirState = HIGH; 
    } 
  }  
  else {                     // No motion 
    digitalWrite(ledPin, LOW); 
     
    if (pirState == HIGH) { 
      Serial.println("Motion Ended"); 
      pirState = LOW; 
    } 
  } 
}

The code architecture follows a simple but effective pattern. During setup, pin modes are configured and the serial monitor initializes for debugging. The 2-second delay allows the PIR sensor to calibrate itself—critical for accurate operation.

The main loop continuously polls the PIR sensor's digital output. When motion is detected (HIGH signal), the LED illuminates and a message prints to the serial monitor. The pirState variable prevents flooding the serial monitor with repeated messages while motion continues. 

You can enhance this basic code in numerous ways. Adding a buzzer creates an audible alarm. Implementing a relay module allows controlling lights, fans, or other AC-powered devices.

For more sophisticated applications, consider adding a timer that sends notifications if motion is detected during specific hours, or integrate multiple sensors to cover larger areas. 

The serial monitor output provides valuable debugging information. Open it through the Arduino IDE (Tools → Serial Monitor) and set the baud rate to 9600. You'll see real-time status updates showing exactly when motion starts and stops, helping troubleshoot any detection issues.

 

 

Conclusion

Building a motion detection system by interfacing a PIR sensor with Arduino opens doors to countless practical applications. From energy-efficient automatic lighting to security systems, the possibilities extend only as far as your imagination.

The straightforward hardware connections and simple code make this project accessible to beginners while providing enough flexibility for advanced implementations. With this foundation, you're equipped to create responsive, intelligent systems that react to human presence.

Excerpt
Learn how to connect and program a PIR sensor with Arduino to create intelligent, responsive systems. A simple guide for beginners to get started.
Frequently Asked Questions

1. Can a PIR sensor detect through glass or walls?  

No, PIR sensors cannot see through glass, walls, or other solid barriers. They detect infrared radiation, which glass and walls block. The heat signature must travel unobstructed to the sensor's lens. This actually makes them useful for window-mounted security applications—they won't falsely trigger from outdoor heat sources on the other side of glass.

2. Can I use multiple PIR sensors with one Arduino board?  

Absolutely. An Arduino Uno has multiple digital input pins, so you can connect several PIR sensors simultaneously. Each sensor connects to a different digital pin—sensor one to pin 2, sensor two to pin 3, and so on. Your code simply reads all pins in the loop function. This creates multi-zone motion detection across larger areas or different rooms.

3. Does a PIR motion sensor work in the dark?  

Yes, PIR sensors work perfectly in complete darkness. They detect infrared heat radiation, not visible light. Whether it's pitch black or bright daylight, the sensor responds identically to heat signatures. This makes them ideal for security systems, nighttime monitoring, and automatic lighting that needs to work 24/7 without depending on ambient light conditions.

4. How do I prevent false triggering of a PIR sensor?  

Reduce false triggers by adjusting the sensitivity and time delay potentiometers. Lower sensitivity prevents picking up minor heat fluctuations from air vents or pets. Increase the delay time so the sensor doesn't re-trigger too quickly. Allow the sensor 30-60 seconds to stabilize after power-on. Position it away from heat sources like radiators, sunlight, or air conditioning units that can cause spurious activations.

5. Can a PIR sensor detect animals or only humans?  

PIR sensors detect any warm-blooded moving object like humans, dogs, cats, birds etc. They respond to infrared heat signatures, not species. A small mouse generates less detectable heat than a large dog, affecting range. If you need human-only detection, you'd need additional logic or a different sensor type. For most applications, this multi-detection capability is actually beneficial for comprehensive motion monitoring.

Prev Post
Next Post

Leave a comment

Please note, comments need to be approved before they are published.

Thanks for subscribing!

This email has been registered!

Shop the look

Choose Options

Edit Option
Back In Stock Notification
Compare
Product SKU Description Collection Availability Product Type Other Details

Choose Options

this is just a warning
Login
Shopping Cart
0 items
FREE SHIPPING!
₹100 OFF
₹200 OFF
WhatsApp Chat Chat