PIR Sensor Interfacing with 8051

In our previous tutorial, we have discussed the RTC interface with 8051. In this tutorial, we are going to discuss PIR sensor interfacing with 8051. This sensor will detect motion in the room, automatic door in the elevator, automatic lighting system, and washroom amenities.

Prerequisites

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

Components Required

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

PIR Motion Sensor

Introduction

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.

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 sensor interfacing

Adjusting PIR Sensor Settings

There are three ways to adjust the PIR sensor settings.

  • Re-Triggering
  • Adjust Sensitivity
  • Adjust Delay

Re-Triggering

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 statuses 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 the ‘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 a widely used setting.

Sensitivity 

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 how much time the output pin of the sensor will keep it high when motion has been detecting. The range of the delay time of the sensor becomes few seconds to few minutes. In our case, it becomes 2 seconds to 200 seconds. Note: For the first time of testing the PIR sensor keep delay timeless.

Applications

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

PIR Sensor Interfacing with 8051

Connection

PIR Sensor

  • Vcc – 5v
  • Gnd – Ground
  • Vout – P1.0

LCD

  • RS – P2.0
  • RW – P2.1
  • EN – P2.2
  • Data Lines – P3.0 – P3.7

PIR sensor interfacing with 8051

Code

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

#include<reg51.h>
#define lcd P3

sbit PIR=P1^0;

sbit rs=P2^0; //register select
sbit rw=P2^1; //RW
sbit en=P2^2; //enable

void lcd_init();
void cmd(unsigned char);
void dat(unsigned char);
void delay();
void lcd_string(char *s);

void main()
{
    lcd_init();
    lcd_string("  EmbeTronicX   ");
    while(1) {
        if(PIR == 0) {
            cmd(0xc0);
            lcd_string("Intruder Detcted");
            delay();
        } else {
            cmd(0xc0);
            lcd_string("                ");
        }
    }
}

void lcd_init()
{
    cmd(0x38);
    cmd(0x0e);
    cmd(0x06);
    cmd(0x01);
    cmd(0x80);
}

void cmd(unsigned char a)
{
    lcd=a;
    rs=0;
    rw=0;
    en=1;
    delay();
    en=0;
}

void dat(unsigned char b)
{
    lcd=b;
    rs=1;
    rw=0;
    en=1;
    delay();
    en=0;
}

void lcd_string(char *s)
{
    while(*s) {
       dat(*s++);
     }
}

void delay()
{
    unsigned int i;
    for(i=0;i<20000;i++);
}

You can also add a buzzer to Indicate the Human presence. In our next tutorial, we will see how to interface the IR sensor with 8051.

You can also read the below tutorials.

Linux Device Driver TutorialsC Programming Tutorials
FreeRTOS TutorialsNuttX RTOS Tutorials
RTX RTOS TutorialsInterrupts Basics
I2C Protocol – Part 1 (Basics)I2C Protocol – Part 2 (Advanced Topics)
STM32 TutorialsLPC2148 (ARM7) Tutorials
PIC16F877A Tutorials8051 Tutorials
Unit Testing in C TutorialsESP32-IDF Tutorials
Raspberry Pi TutorialsEmbedded Interview Topics
Reset Sequence in ARM Cortex-M4BLE Basics
VIC and NVIC in ARMSPI – Serial Peripheral Interface Protocol
Bootloader Tutorials
0 0 votes
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x