How to use PIR motion sensor - Simple tutorial

Wednesday, April 19, 2017

Arduino PIR motion sensor tutorial

This is a simple, brief  guide to use or test your PIR motion sensor with arduino for first time.
When the PIR sensor is detect a motion the LED will glow. 

Parts required 

  • Arduino UNO/Nano (any arduino board)
  • HC SR501 PIR sensor module
  • Jumper cables 
  • LED bulb


  1.  Connect +ve (long leg) of  LED  to Arduino pin  2
  2.  Connect -ve (short leg) of LED to Arduino  pin GND
  3.  Connect VCC of PIR sensor to Arduino pin 5V
  4.  Connect OUT of  PIR sensor to Arduino pin 9
  5.  Connect GND of  PIR sensor to Arduino pin GND

Circuit diagram of PIR motion sensor with arduino.

Arduino PIR motion sensor circuit diagram

Source code for PIR motion sensor with arduino.

 int pirPin = 9;  //the digital pin connected to the PIR sensor's output  
 int ledPin = 2;  //the digital pin connected to the +ve od LED  
 void setup() {  
  pinMode(pirPin, INPUT);  
  pinMode(ledPin, OUTPUT);  
  digitalWrite(pirPin, LOW);  
 void loop() {  
  if(digitalRead(pirPin) == HIGH)  
    Serial.print("Motion Detected");  
   digitalWrite(ledPin, HIGH);  
  if(digitalRead(pirPin) == LOW)  
   digitalWrite(ledPin, LOW);  

Click here to download the code

You Might Also Like


  1. Using PIR MOTION SENSOR was an intimidating tak for me because i have not proper information about the requirements and things which we need to carry it but your post has helped me a lot . Dissertation Writing Service


Click on 'Notify me' to get replies of your comment.

Popular Posts

Like us on Facebook

Contact Form


Email *

Message *