top of page

Motion Detection using PIR Sensor with Arduino


What is a PIR sensor?


PIR sensors allow you to sense motion. They are used to detect whether a human has moved in or out of the sensor’s range. They are commonly found in appliances and gadgets used at home or for businesses. They are often referred to as PIR, "Passive Infrared", "Pyroelectric", or "IR motion" sensors.

Following are the advantages of PIR Sensors −

· Small in size

· Wide lens range

· Easy to interface·

· Inexpensive

· Low-power

· Easy to use

· Do not wear out


Material Required:


Material Quantity

Arduino Uno 1

PIR Motion Sensor 1

Jumper cables 3


Pinout Diagram:



Circuit Diagram:



Working:


The module actually consists of a Pyroelectric sensor which generates energy when exposed to heat.

That means when a human or animal body will get in the range of the sensor it will detect a movement because the human or animal body emits heat energy in a form of infrared radiation. That’s where the name of the sensor comes from, a Passive Infra-Red sensor. And the term “passive” means that sensor is not using any energy for detecting purposes, it just works by detecting the energy given off by the other objects.



The module also consists a specially designed cover named Fresnel lens, which focuses the infrared signals onto the pyroelectric sensor.


You can adjust the sensor sensitivity and delay time via two variable resistors located at the bottom of the sensor board.



Tested Programming Code:

/*

* PIR sensor tester

*/


int ledPin = 13; // choose the pin for the LED

int inputPin = 2; // choose the input pin (for PIR sensor)

int pirState = LOW; // we start, assuming no motion detected int val= 0; // variable for reading the pin status


void setup() {

pinMode(ledPin, OUTPUT); // declare LED as output pinMode(inputPin, INPUT); // declare sensor as input


Serial.begin(9600);

}


void loop(){

val = digitalRead(inputPin); // read input value

if (val == HIGH) { // check if the input is HIGH digitalWrite(ledPin, HIGH); // turn LED ON

if (pirState == LOW) {

// we have just turned on Serial.println("Motion detected!");

// We only want to print on the output change, not state pirState = HIGH;

}

} else {

digitalWrite(ledPin, LOW); // turn LED OFF if (pirState == HIGH) {

// we have just turned of Serial.println("Motion ended!");

// We only want to print on the output change, not state pirState = LOW;

}

}

}


Precautions:


1. Double Check the connections before powering on the circuit.

2. Don’t use loose jumper cables.

3. Check Whether proper board is selected from Arduino IDE.

4. Ensure proper placement of sensor for correct working.

5. Don’t come in range of the sensor, else it will be always triggering ON.


Conclusion:


You can successfully check for Motion Detection using an IR sensor. Many more other applications can be made using PIR Motion sensor as it has many possibilities to work with.


Output:


Once the sensor detects any motion, Arduino will send a message via the serial port to say that a motion is detected. The PIR sense motion will delay for certain time to check if there is a new motion. If there is no motion detected, Arduino will send a new message saying that the motion has ended.


Situation Screenshot: Serial Monitor (Ctrl+Shift+M)




GET IN TOUCH

We'd love to hear from you

bottom of page