PIR Sensor With Arduino And With Raspberry PI

PIR sensors detect motion and are always used to determine whether a human has entered or exited the sensor’s range. They’re small, cheap, low-power, simple to use, and they don’t wear out. As a result, they’re often found in home and business equipment and gadgets.In this blog, we discuss about the interfacing of  PIR sensor with the Arduino Board and Raspberry Pi


A Passive Infrared sensor defined as an electrical sensor that detects the infrared light radiated by a warm object or used to sense motion. It is widely used to detect the motion of a human body within the sensor’s range. Hence often referred to as “PIR”, “Pyroelectric”, “Passive Infrared” and “IR Motion” sensor.

PIR sensor senses infrared energy emits the human body within a detection area of approximately 3-7 meters. When the human body moves within the detection range at a certain field of view in sequence and then walks out of the field of view. As a result, the pyroelectric sensor senses the moving human body for a while and then does not see it, so the infrared radiation of the human body constantly changes the temperature of the pyroelectric material. Thus outputs a corresponding signal, which is the alarm signal. This sensor offers a wide range of applications in burglar alarms and automatically-activated lighting systems etc.

The module consists of an on-board pyroelectric sensor, conditioning circuitry, and a dome-shaped Fresnel lens. In addition to it, it consists of a delay time adjustment Potentiometer and sensitivity adjustment Potentiometer. These pyroelectric sensors introduce changes in their temperature due to incident infrared radiation into an electric signal. But there will be no change in the detection distance. In order to lengthen the detection distance of the detector, an optical system added to collect the infrared radiation. Usually, a plastic optical reflection system or plastic Fresnel lens used as a focusing system for infrared radiation. These small, inexpensive, low-power sensors can be easily interfaced with ARDUINO, RASPBERRY PI, AVR, PIC, 8051, etc.


  • Complete with PIR, Motion Detection.
  • Dual Element Sensor with Low Noise and High Sensitivity.
  • Supply Voltage – 5V.
  • Delay Time Adjustable.
  • Standard TTL Output.
  • Sensitivity Adjustable: Turn On Lights during Day or nights
  • Automatic On & Off Lights
  • Wide operating range
  • Good solution for energy saving & easy in installation
  • Delay adjustment: 10 Seconds – 7 Minutes 
  • Adjustable Lux: turn on the lights during the day or night

Illustration of PIR sensitive crystal:

The IR sensitive crystal, which is contained in the black area of the metal, can detect the level of infrared in the environment. It contains two pyroelectic sensors that detect moving things. The output is activated if one of the sensitive crystals detects a greater change in infrared (increment or decrement) than the other sensitive crystal. A dome shaped plastic structure is normally placed over this sensitive crystal which acts as lens to focus the infrared light on the sensors.


The PIR sensor IC consists of 3 pins-  Vcc, Ground and Output.

  • Pin1: Corresponds to the drain terminal of the device, which is connected to the positive supply 5V DC.
  • Pin 2: Corresponds to the source terminal of the device, which connects to the ground terminal via a 100K or 47K resistor.  The measured IR signal is sent to an amplifier through pin 2 of the sensor, which is connected to the ground.
  • Pin 3: Connected to the ground.

Senstivity And Delay Adjusment In PIR Motion Sensor

PIR sensor

Apart from these fundamentals, you’ll notice two potentiometers on the PIR sensor if you examine the module.

The sensitivity of a potentiometer is used to change the range sensing. The delay is controlled by a potentiometer labeled Output-timing.

  • Troubleshoot if the PIR module still doesn’t work

There are a variety of reasons why the module can stop operating, and I’ve mentioned a number of them below.

  • The Module is Not Giving Any Output in The first Minute After Turning it on

If you’re having this issue, don’t panic; it’s not a problem; the PIR sensor begins reading the IR rays around it in the first minute after power is provided. As a result, it should be stable in its surroundings.

  • The output is not stable

If you’re having this difficulty, there are two possible causes: first, you may have erroneously set the module’s first potentiometer (sensitivity) to its maximum setting, and second, the PIR sensor may be positioned incorrectly. If you’ve placed the PIR sensor in a location where it’ll be in direct contact with air and light. This could be the reason why the sensor is giving the incorrect reading.

Interfacing  PIR sensor with Arduino

The interface of the PIR sensor with the Arduino board is shown in the diagram below. We did this by connecting the PIR sensor’s signal pin to the Arduino’s D9 pin and powering the sensor directly from the Arduino.

PIR Motion sensor with arduino

PIR Motion sensor Arduino code

int led = 13; // the pin that the LED is atteched to
int sensor = 9; // the pin that the sensor is atteched to
int state = LOW; // by default, no motion detected
int val = 0; // variable to store the sensor status (value)

void setup() {
pinMode(led, OUTPUT); // initalize LED as an output
pinMode(sensor, INPUT); // initialize sensor as an input
Serial.begin(9600); // initialize serial

void loop(){
val = digitalRead(sensor); // read sensor value
if (val == HIGH) { // check if the sensor is HIGH
digitalWrite(led, HIGH); // turn LED ON
delay(100); // delay 100 milliseconds

if (state == LOW) {
Serial.println(“Motion detected!”);
state = HIGH; // update variable state to HIGH

Interfacing of PIR sensor with Raspberry Pi

The following fig shows the interfacing diagram of the PIR sensor with the raspberry pi.  

PIR Motion sensor Python Code 

import RPi.GPIO as GPIO

From time import sleep



GPIO.setup(14, GPIO.IN) #Read output from PIR motion sensor

while True:


if input == 0: #When output from motion sensor is LOW
print (“No object detected”,input)
elif input == 1: #When output from motion sensor is HIGH
print (“Object detected”,input)


Hope all of you had understand how to Interface the PIR sensor using Arduino &b Raspberry Pi. We MATHA ELECTRONICS will be back soon with more informative blogs soon.

Leave a Reply

Your email address will not be published.