Arduino Nano PIR Passive Infrared Motion Sensor

The PIR Motion Sensor project demonstrates how to interface a Passive Infrared (PIR) motion sensor (such as the popular HC‑SR501) with an Arduino Nano. The PIR sensor outputs a digital signal when it detects motion, and the Arduino can use this signal to trigger LEDs, buzzers, relays, or messages in the Serial Monitor, enabling automatic lights, security alarms, and other motion‑based systems.

What Is a PIR Motion Sensor?

A PIR (Passive Infrared) sensor detects motion by measuring changes in the infrared radiation emitted by warm objects such as humans or animals. The sensor does not emit infrared itself; it only “listens” to changes in the IR pattern in its field of view. When a warm body moves across the detection zone, the sensor sets its output pin HIGH for a short time (typically a few seconds), signaling that motion has been detected.

Most hobby PIR modules (e.g. HC‑SR501) include a 3‑pin interface, an LED to indicate detection, and two onboard potentiometers to adjust the sensing range and the ON‑time after motion is detected.

Components Needed

  • Arduino Nano
  • PIR motion sensor module (e.g. HC‑SR501)
  • LED (for motion indication)
  • 220 Ω resistor (for LED)
  • Buzzer (optional, for alarm)
  • Jumper Wires
  • Breadboard

Circuit Setup

1. Connect PIR Sensor to Arduino Nano:

A typical PIR module exposes three pins:

  • VCC → 5V on the Arduino Nano.
  • GND → GND on the Arduino Nano.
  • OUT (or OUT) → any digital pin on the Nano, commonly D2.

If your PIR module is powered by 12 V (e.g. via a screw‑terminal adapter), connect the sensor’s VCC and GND to the external supply, and still route the OUT pin to the Arduino Nano’s digital pin (the sensor usually outputs a 3.3 V–compatible HIGH signal).

2. Connect Indicator Devices:

  • Connect an LED anode to a digital pin (e.g. D3) through a 220 Ω resistor; connect the cathode to GND.
  • Optionally connect a buzzer to another digital pin, such as D5, for sound alerts when motion is detected.

How the PIR Sensor Works

The PIR sensor continuously monitors the infrared scene in front of it. When a warm object moves into or across the detection zone, the difference in IR radiation triggers the internal circuit, and the OUT pin goes HIGH for a configurable time (set by the sensor’s time‑delay potentiometer). The Arduino Nano reads this state with digitalRead() and can act accordingly, such as turning on an LED or relay.

Compared to PIR‑like microwave sensors, PIR modules are simpler, low‑cost, and very reliable for human‑motion detection but are more sensitive to changes in ambient temperature and blocked or reflective environments.

Program: Arduino Nano PIR Motion Sensor (Motion‑Activated LED & Buzzer)
/*
PIR Motion Sensor (HC‑SR501 style)
with Arduino Nano
*/

// PIR sensor output pin
const int pirPin = 2;
// LED indicator for motion
const int ledPin = 3;
// Optional buzzer for alarm
const int buzzerPin = 5;

// Variables to track state
int pirState = LOW;
int val = 0;

void setup() {
  pinMode(pirPin, INPUT);
  pinMode(ledPin, OUTPUT);
  pinMode(buzzerPin, OUTPUT);
  
  digitalWrite(ledPin, LOW);
  digitalWrite(buzzerPin, LOW);
  
  Serial.begin(9600);
  Serial.println("=== PIR MOTION SENSOR READY ===");
}

void loop() {
  // Read the PIR sensor
  val = digitalRead(pirPin);

  if (val == HIGH) {
    // Motion detected
    digitalWrite(ledPin, HIGH);
    digitalWrite(buzzerPin, HIGH);
    
    if (pirState == LOW) {
      Serial.println("Motion detected!");
      pirState = HIGH;
    }
  } else {
    // No motion
    digitalWrite(ledPin, LOW);
    digitalWrite(buzzerPin, LOW);
    
    if (pirState == HIGH) {
      Serial.println("Motion ended!");
      pirState = LOW;
    }
  }
  
  delay(100);  // Small delay to smooth reading
}

Instructions

1. Circuit Setup:

Wire the PIR motion sensor according to the pinout described above, taking care that VCC, GND, and OUT are connected to the correct pins and match the pirPin used in the code.

2. Adjust Sensitivity and Time Delay:

Rotate the two onboard potentiometers on the PIR module:

  • Time delay (TIME) potentiometer: controls how long the OUT pin stays HIGH after motion is detected (e.g. 3–30 seconds).
  • Sensitivity (SENS) potentiometer: controls how close and how strongly an object must move to trigger the sensor.

3. Code Upload:

Connect the Arduino Nano to your computer via USB, open the Arduino IDE, paste the PIR‑sensor code, and upload it to the board.

4. Testing:

Open the Serial Monitor (9600 baud). Walk in front of the PIR sensor; the LED should light, the buzzer should sound, and the Serial Monitor should show "Motion detected!". When you stop moving, the signals and messages should return to normal.

Applications

Automatic Lighting: Use the PIR sensor to turn on corridor or room lights when motion is detected and turn them off after a delay, saving energy and improving convenience.

Security & Alarm Systems: Deploy the sensor at doors, windows, or storage areas to trigger buzzers, LEDs, or relays that lock gates or record video when motion is detected.

Smart‑Home & Automation: Integrate the PIR sensor with relays to control fans or ventilation systems that run only when humans are present, or to trigger smart‑door notifications when someone approaches.

Troubleshooting

  • Sensor never triggers? Check that VCC and GND are correctly wired and that the sensitivity and time‑delay potentiometers are not turned too low.
  • Constant false triggers? Avoid placing the sensor near heaters, air conditioners, or vibrating objects, and mask the detection area if necessary with a tube or shield.
  • LED or buzzer does not respond? Verify that the OUT pin matches the pirPin used in the code and that the LED and buzzer are wired with correct polarity and a current‑limiting resistor.

Best Practices and Notes

  • Mount the PIR sensor at an appropriate height (typically 2–2.5 meters) and with its detection window facing the area of interest, avoiding direct sun or strong light sources.
  • Avoid rapid changes in background temperature; sudden warming or cooling can cause false motion signals.
  • For outdoor use, choose a weather‑proof enclosure that still allows an unobstructed view through the sensor window.

Extensions and Ideas

You can extend this project by adding a relay to control high‑voltage lights or gates, combining the PIR sensor with an LDR so that lights only turn on at night, or using the Arduino Nano to log motion events to an SD card or display them on an LCD. For advanced systems, connect the sensor to an ESP‑based module and send motion‑alert notifications over Wi‑Fi or mobile networks.