Introduction: PIR Motion Sensor | HC-SR501 | Arduino

About: I am currently studying Electrical and Computer Engineering at Aristotle University of Thessaloniki.

In this project, we will make a LED to turn on when the PIR sensor detects infrared light. As you may already know humans, emit thermal radiation but we don't see it because most of its spectrum is in the infrared range due to the low temperature. So we can take advantage of this and build alarms etc.

Step 1: Components!

This project is very simple and we only need the following components:

1 X PIR Motion Sensor HC-SR501

An Arduino UNO and its USB cable for connection with the PC (type: A male to B male)

A few male-to-male and male-to-female cables

1 X LED

1 X small or standard breadboard (it doesn't matter)

Step 2: Wiring!

PIR:

GND > GND

Vcc > 5V

Middle probe > digital pin 9

LED:

small probe > GND

long probe > digital pin 2

Step 3: Coding!

#define LED 2
#define PIR 9


void setup() {
  
  pinMode(LED,OUTPUT);
  pinMode(PIR,INPUT);
  Serial.begin(9600);
}


void loop() {
  
  int pir = digitalRead(PIR);
  Serial.println(pir);
  if(pir == HIGH)
  {
    digitalWrite(LED,HIGH);
    delay(2000);
  }
  else
  {
    digitalWrite(LED,LOW);
  }
  
}

Copy this code in a new file in Arduino IDE, upload it to your Arduino UNO through the USB and see the outcome.NOTE: It takes about 1 minute for the sensor to work properly! You can also open the serial monitor but first, go to Tools > port and click on COM.

Thank you and good luck!