Pantech.AI

How to Interface with PIR Motion Sensor with 8051

PIR Motion Sensor

A PIR (Passive Infrared) sensor detects infrared radiation emitted by living objects, allowing it to sense their presence.

The sensor is divided into two slots, both connected to a differential amplifier. When a stationary object is in front of the sensor, both slots receive equal radiation, resulting in zero output. However, when a moving object passes by, one slot receives more radiation than the other, causing the output to fluctuate.

This change in output voltage indicates motion detection.

For further details on PIR sensors and their usage, refer to the “PIR Sensor” section in the sensors and modules category.

PIR Motion Sensor

Internal Structure of PIR Motion Sensor with Pinout

PIR Sensor Connection with 8051

How to connect PIR Sensor with 8051

Note:

Avoid placing the PIR (Passive Infrared) sensor near Wi-Fi antennas, ESP32, or NodeMCU modules. Wi-Fi signals emit electromagnetic radiation that can interfere with the PIR sensor’s ability to detect infrared changes, leading to false detections. To prevent this interference, always keep the PIR sensor and Wi-Fi antenna as far apart as possible. Alternatively, you can shield the PIR sensor using metal shields or a Faraday cage.

Example

In this example, we’ll create an application where an LED turns ON when motion is detected. The PIR motion sensor is interfaced with the 8051 microcontroller.

According to the circuit diagram, the output pin of the PIR sensor is connected to the PORT0.0 pin of the microcontroller. A transistor is used to ensure proper logic levels (0V and 5V) at the 8051 input pin. When motion is detected, the P0.0 pin goes LOW, activating the LED. If a HIGH is detected on this pin, it indicates either no motion or the end of the trigger period, and the LED will turn OFF.

The module is configured in repeatable trigger mode. Note that after powering up, the PIR sensor requires a warm-up period of 30–50 seconds to function properly.

Code for PIR Sensor using 8051

/*
 * PIR Motion sensor interface with 8051
 * http://www.electronicwings.com
 */


#include <reg51.h>

sbit Motion_detection=P0^0;	/* Read PIR sensor's data on this pin */
sbit LED=P1^0;				/* Connect LED to the PORT1.0 pin */


void MSdelay(unsigned int val);

void main(void) 
{
	P1=0;			/* Initially LED turned OFF*/
	MSdelay(3000);	/* Power-on delay for PIR */
	while(1)
	{
		if(Motion_detection==1)  /* Check for human motion */
		LED = 0;	/* LED turn OFF for No motion */
		else
		LED = 1;	/* LED turn ON if motion is detected */
	}
}
void MSdelay(unsigned int val)
{
     unsigned int i,j;
        for(i=0;i<=val;i++)
            for(j=0;j<112;j++);	/* Delay of 1 ms for 11.0592MHz Frequency */
}

Leave a Comment

Your email address will not be published. Required fields are marked *