PIR Sensor Interfacing with PIC16F877A

In this tutorial we are going to discuss PIR sensor interfacing with PIC16F877A. This sensor will detect motion in the room, automatic door in elevator, automatic lighting system, and washroom amenities.


Before start this tutorial we should know below topics. If you know already, please go further.

Components Required

  • PIC16F877A Development Board
  • PIR Motion Sensor
  • LCD Module (To print the Sensor output)

PIR Motion Sensor


The term PIR is the short form of the Passive Infra Red. The term “passive”indicates that the sensor does not actively take part in the process, which means, it does not emit the referred IR signals itself, rather passively detects the infrared radiations coming from the human body in the surrounding area.

pir-sensor-300x240 PIR Sensor Interfacing with PIC16F877A

The detected radiations are converted into an electrical charge, which is proportional to the detected level of the radiation. Then this charge is further improved by a built in FET and fed to the output pin of the device which becomes applicable to an external circuit for further triggering and amplification of the alarm stages.The PIR sensor range is up to 10 meters at an angle of +15o or -15o. Most PIR modules have a 3-pin connection at the side or bottom. The pinout may vary between modules so triple-check the pinout!

Working of PIR Sensor

The PIR sensor itself has two slots in it, each slot is made of a special material that is sensitive to IR. The lens used here is not really doing much and so we see that the two slots can ‘see’ out past some distance (basically the sensitivity of the sensor). When the sensor is idle, both slots detect the same amount of IR, the ambient amount radiated from the room or walls or outdoors. When a warm body like a human or animal passes by, it first intercepts one half of the PIR sensor, which causes a positive differential change between the two halves. When the warm body leaves the sensing area, the reverse happens, whereby the sensor generates a negative differential change. These change pulses are what is detected.

pir-diagram PIR Sensor Interfacing with PIC16F877A

Adjusting PIR Sensor Settings

There are three ways to adjust the PIR sensor settings.

  • Re-Triggering
  • Adjust Sensitivity
  • Adjust Delay

PIR_Sensor-adjustment PIR Sensor Interfacing with PIC16F877A


As you can, see the Re-triggering section has three SMD pads. . Few PIR sensor modules comes with through hole male pin headers and it is shorted with one of the states either it is in non re-triggering mode or re-triggering mode. We could see the two status High(H) and Low(L) on board. In our case it is default connected to H. The ‘L’ mode setting behaves erratic, when we move in front of sensor output pin goes high and low again. This is called ‘non re-triggering mode’. In ‘H’ mode setting when we move in infrared proximity the output pin of the sensor will go high. This is called ‘Non re-triggering mode’ In ‘H’ mode setting when we move in infrared proximity the output pin of the sensor will go high. This is called ‘Re-triggering mode’. This mode of setting is widely used setting.


The potentiometer shown in the image above is provided for sensitivity adjustment. If pot is turned clockwise the sensitivity increases, and decreases the other way around.

Delay time 

The ‘delay time’ determines the how much time the output pin of the sensor will keep it high when motion has been detect. The range od the delay time of the sensor become few seconds to few minutes. In our case it become 2 seconds to 200 seconds. Note : For first time of testing the PIR sensor keep delay time less .


  • Intruder alarms
  • Automatic ticket gates
  • Entryway lighting
  • Security lighting
  • Hand dryers
  • Automatic door

PIR Sensor Interfacing with PIC16F877A


PIR Sensor

  • Vcc – 5v
  • Gnd – Ground
  • Vout – RD0 (Port D.0)


  • RS – RC0
  • RW – RC1
  • EN –RC2
  • Data Lines – PORTB

pir-sensor-interfacing-with-pic16f877a PIR Sensor Interfacing with PIC16F877A


Whenever it detects human presence, LCD will display Intruder detected.

You can also add buzzer to Indicate the Human presence.