INTRODUCTION
In this tutorial, we are going to learn how to interface a PIR Sensor to an Arduino UNO. And we will also learn briefly about its working principles.
THEORY
PIR Sensor is stood for Passive Infrared Sensor.
It detects infrared light emitting from nearby objects.
It can able to detect infrared light emitting from animals to human beings.
When this light is higher than a certain threshold level PIR Sensor gives an indicator.
The PIR Sensor has 3 pins.
i)VCC
ii)GND
iii)Data Pin
REQUIREMENTS
Parts | Quantity |
Arduino UNO | 1 |
A-B cable | 1 |
PIR Sensor | 1 |
LED | 1 |
Bread Board | 1 |
220 ohm | 1 |
Connecting Wire | As per required |
CIRCUIT DIAGRAM
PROGRAM
For programming this concept we need to understand some basic syntax of Arduino IDE.
The first thing is we need to install Arduino. After that, we need to know how to interface led to Arduino and how to use Serial Monitor.
Then lets start with declaring the pins. Declare in which pin of UNO the PIR and LED connected.
#define pir_sensor 4
#define LED 13
Then go towards the void setup function. In this we are going to declare whether the PIR Sensor and LED is a Output/ input device.
As we all know sensor are Input devices and LED is a Output device.
also we are writing the function to initiate the Serial Monitor and its Boudrate.
void setup()
{
pinMode(pir_sensor,INPUT);
pinMode(LED,OUTPUT);
Serial.begin(9600); //Normal Baudrate
Serial.println("object detection");
}
After void setup function then void loop is there, in this we will control the PIR Sensor and LED by using some basic syntax of C++.
void loop()
{
if(digitalRead(pir_sensor) == LOW) // If object detected
{
digitalWrite(LED,HIGH); // LED will ON
Serial.println("detected"); // Print details on Serial Monitor
}
else
{
digitalWrite(LED,LOW); // LED will OFF
Serial.println("not detected");
}
}
Final Code
/*
Tested by robogenesis. in
This program blinks pin 13 of the Arduino (the built-in LED)
*/
#define pir_sensor 4
#define LED 13
void setup()
{
pinMode(pir_sensor,INPUT);
pinMode(LED,OUTPUT);
Serial.begin(9600);
Serial.println("object detection");
}
void loop()
{
if(digitalRead(pir_sensor) == LOW)
{
digitalWrite(LED,HIGH);
Serial.println("detected");
}
else
{
digitalWrite(LED,LOW);
Serial.println("not detected");
}
}
Comments