Min menu

Pages

Arduino PIR Sensor Tutorial | PIR Motion Sensor with Arduino


In this project, we will learn about PIR Sensor and how can it be used as a Motion Sensor through the Arduino PIR Sensor Tutorial. By going through this project, you can understand how PIR Sensor works and how to hook up a PIR Sensor to Arduino.
We have made a project using Arduino, PIR Sensor and GSM Module called GSM based Home Security System using Arduino. If you understand how a PIR Sensor works, then you can many such interesting projects and even more complex ones.

Components Required

  • Arduino UNO
  • PIR Sensor 
  • 5V Buzzer 
  • Breadboard 
  • Connecting Wires 
  • Power Supply

Circuit Design

The design of the PIR Motion Sensor using Arduino is very simple. The PIR Sensor Module has three pins: VCC, Digital Out and GND. Connect VCC and GND to +5V and GND respectively. Then connect the Digital Out Pin of the PIR sensor to the digital I/O pin 8 of Arduino.
As we need to indicate the detection of motion by the sensor, connect a buzzer to Pin 11 of the Arduino.

Code

int buzzer = 11;
int sensor = 8;
int led = 13;
void setup()
{
pinMode(buzzer, OUTPUT);
pinMode(sensor, INPUT);
pinMode(led, OUTPUT);
digitalWrite(buzzer,LOW);
digitalWrite(sensor,LOW);
digitalWrite(led,LOW);
while(millis()<13000)
{
digitalWrite(led,HIGH);
delay(50);
digitalWrite(led,LOW);
delay(50);
}
digitalWrite(led,HIGH);
}
void loop()
{
if(digitalRead(sensor)==HIGH)
{
digitalWrite(buzzer,HIGH);
delay(3000);
digitalWrite(buzzer,LOW);
while(digitalRead(sensor)==HIGH);
}
}
reaction: