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. This post will show how to connect these modules to an Arduino Nano and supply the sketch to trigger the on-board LED when motion is detected.

This is an ongoing post. Please suggest corrections, explanations, etc. in the comment section at the bottom of this page.

To get started you will need

These were the parts that were used. Most are available from BangGood, eBay and RS Components. Direct links to some of the parts are supplied lower down.

  • Arduino Nano
  • Arduino IDE installed on a PC
  • Mini-B USB cable
  • HC-SR501 Pyroelectric Infrared Motion Sensor module
  • Breadboard and solderless breadboard jumper cable set
  • 10, 20 or 30 cm female to female jumper wire set
  • 10, 20 or 30 cm male to female jumper wire set

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. For more information about setting up the Arduino Nano with the Arduino IDE, see this post.

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

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 on-board LED of the Arduino Nano will blink.

About the author
Renier busies himself with improving his English writing, creative web design and his websites, photoshopping, micro-electronics, multiple genres of music, superhero movies and badass series.
Behind the Scenes is a free, informative website. If you find value in any of our content, please consider making a donation to our cause.
Donate via PayPal

Save, share & Disqus

Use the buttons below, on the left or the bottom of this page to share this post. Your comment is important, but don't be a knob. Keep it constructive and polite.

Comment via Disqus

Disqus is a worldwide comment hosting service for web sites and online communities. This secure platform ensures a pleasant commenting environment which is manageable from one account. Use the Login button to sign up.

More motion sensor related posts

Improve your skills through Skillshare – get first 2 months for free
Improve your skills through Skillshare – get first 2 months for free
4 April 2020
Ad: Join the Skillshare online learning community with videos on programming, website development, art, designs and many more. Try Skillshare for free for two months now! More…
Laser Transmitter Receiver Modules for Sensing Movement
Laser Transmitter Receiver modules for sensing movement
23 March 2016 | Updated 6 December 2017
Laser Transmitter Receiver Modules consist of a collimated Laser Transmitter module (a straight, non-diverging laser beam) and a separate non-modulating Laser Tube Sensor/Receiver module (a laser beam sensor). More…
Categories
Electronics
The HC-SR501 Pyroelectric Infrared Motion Sensor Module
HC-SR501 Pyroelectric Infrared Motion Sensor module
10 January 2016 | Updated 16 February 2018
HC-SR501 Pyroelectric Infrared Motion Sensor modules are electronic sensors that is used to detect motion. These modules are based on passive infrared technology with a high sensitivity and reliability. More…
Categories
Electronics