Tuesday, 1 September 2026

HC-SR501 PIR Sensor Arduino Guide

HC-SR501 PIR Sensor Setup Guide

Object & Motion Detection with Arduino UNO

🔌 Wiring Connections

Component Pin Connection Target Wire Type
PIR VCC Arduino 5V Power (+5V)
PIR OUT (Signal) Arduino Digital Pin 2 Signal
PIR GND Arduino GND Ground
LED Anode (+) Arduino Digital Pin 13 (via 220Ω Resistor) Output Indicator
LED Cathode (−) Arduino GND Ground

📐 Schematic Connection Flow

+------------------+ +--------------------+ | HC-SR501 PIR | | Arduino UNO | | | | | | [ VCC ] ----+--------------------+---> 5V | | [ OUT ] ----+--------------------+---> Digital Pin 2 | | [ GND ] ----+--------------------+---> GND | +------------------+ | | | Digital Pin 13 | +---------+----------+ | [220Ω] | (LED Anode) (LED Cathode) | GND

📋 Setup Instructions

  1. Identify PIR Pins: Remove the white plastic dome (if needed) to view labels on the PCB. Looking at the pins: VCC (left), OUT (center), GND (right).
  2. Wire the Power: Connect PIR VCC to Arduino 5V and PIR GND to Arduino GND.
  3. Wire the Output Signal: Connect PIR OUT to Arduino Digital Pin 2.
  4. Add Status LED: Connect Pin 13 to a 220Ω resistor, then to the LED's longer leg (Anode). Connect the short leg (Cathode) to GND.
  5. Upload & Warm Up: Upload the code below and allow 30–60 seconds for the sensor to calibrate.

⚙️ Hardware Adjustments (Potentiometers)

Sensitivity Adjust (Sx)

Controls detection distance range:

  • Clockwise: Increases distance up to 7 meters.
  • Counter-Clockwise: Decreases distance down to 3 meters.

Time Delay Adjust (Tx)

Controls how long the output pin stays HIGH:

  • Clockwise: Long delay (up to 5 minutes).
  • Counter-Clockwise: Short delay (down to 3 seconds).
💡 Jumper Mode: Set the yellow jumper to H (Repeat Trigger) mode. This ensures the output pin stays HIGH continuously while object motion is detected.

💻 Arduino Code

const int pirPin = 2;     // PIR OUT pin connected to Pin 2
const int ledPin = 13;    // On-board / external LED pin

int pirState = LOW;       // Track active state
int val = 0;              // Sensor reading variable

void setup() {
  pinMode(pirPin, INPUT);
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);

  // PIR sensor needs time to calibrate background IR radiation
  Serial.println("Calibrating PIR sensor...");
  delay(30000); // 30-second delay for startup calibration
  Serial.println("Sensor Active. Ready to detect motion.");
}

void loop() {
  val = digitalRead(pirPin);

  if (val == HIGH) {
    digitalWrite(ledPin, HIGH); // Turn LED ON
    if (pirState == LOW) {
      Serial.println("Motion / Object Detected!");
      pirState = HIGH;
    }
  } else {
    digitalWrite(ledPin, LOW);  // Turn LED OFF
    if (pirState == HIGH) {
      Serial.println("Motion ended.");
      pirState = LOW;
    }
  }
}

No comments:

Post a Comment

Popular IoT Sensors & Actuators — Price Guide (India) Component reference Popular IoT sensors & actuators, wit...

Popular Posts