Getting started with the HC-SR501 Pyroelectric Infrared Motion Sensor module & Arduino

Getting Started with the HC-SR501 Pyroelectric Infrared Motion Sensor Module & Arduino

The HC-SR501 Pyroelectric Infrared Motion Sensor module is an electronic sensor that triggers a digital signal when motion is detected.

Introduction

The HC-SR501 Pyroelectric Infrared Motion Sensor module is an electronic sensor that triggers a digital signal when motion is detected. This post will show how to connect these modules to an Arduino Nano and supply the sketch to trigger the onboard LED when motion is detected.

On detecting motion, the HC-SR501 Pyroelectric Infrared Motion Sensor module will write a digital (LOW to HIGH) signal to its signal pin. This signal can be read by one of the Arduino Nano’s digital read pins which can be used to trigger the on-board LED (pin 13).

By looking at the power requirements of the HC-SR501 Pyroelectric Infrared Motion Sensor module (3.3 ~ 20 V DC), the Arduino’s 5V DC and the GND pins can be connected without any additional components.

Step 1 – Wire it up

The Arduino Nano and the HC-SR501 Pyroelectric Infrared Motion Sensor module (PIR) can be connected using a breadboard or directly using jumper wires. With a board where the pins are not marked, the Gnd (-) pin will be on the right and the Pwr (+) on the left when the board is turned upside down and the ‘pins edge’ is closest to the observer.

Getting started with the HC-SR501 Pyroelectric Infrared Motion Sensor module & Arduino

The bottom of the HC-SR501 Pyroelectric Infrared Motion Sensor module (PIR) & its pins(marked)

Getting started with the HC-SR501 Pyroelectric Infrared Motion Sensor module & Arduino

Connecting the HC-SR501 Pyroelectric Infrared Motion Sensor module to an Arduino Nano.

The red wire is connecting the Arduino’s 5V pin with the Pwr pin of the PIR and the black wire is connecting the two Gnd pins. In this case, a yellow wire is connecting the signal pin (situated between Pwr and Gnd) of the PIR to a digital read pin (D8 will be used in this example) of the Arduino Nano. The module in the featured image already had wires attached.

Step 2 – The sketch

After connecting the Arduino Nano with a PC, the following sketch can be uploaded using the Arduino IDE:

/*
Turns on the on-board LED (digital pin 13) when motion is detected using a HC-SR501 Pyroelectric Infrared Motion Sensor Module (PIR) using the 5V and digital pin 8.
*/

int val; // read value integer 

// the setup function runs once when you press reset or power the board
void setup() {
  pinMode(13, OUTPUT); // initialize digital pin 13 as an output
  pinMode(8, INPUT);  // initialize digital pin 8 as an input
}

void loop() { // the loop function runs over and over again forever
  val = digitalRead(8); // read state of the PIR on D8
  if (val == LOW) {
    digitalWrite(13, LOW); // turn LED off by making voltage LOW
  }
  else {
    digitalWrite(13, HIGH); // turn LED on by making voltage HIGH
  }
  delay(200); // wait for 200 ms
}

Now each time motion is detected by the PIR, the onboard LED of the Arduino Nano will blink.

Conclusion

On detecting motion, the HC-SR501 Pyroelectric Infrared Motion Sensor module will write a digital (LOW to HIGH) signal to its signal pin. This signal can be read by one of the Arduino Nano’s digital read pins which can be used to trigger the on-board LED (pin 13).

Leave a Reply

Your email address will not be published. Required fields are marked *