PIR Sensor with AVR Interfacing and Programming

The PIR sensor is abbreviation for Passive Infrared sensor and are used for heat sensing radiated by human and animal bodies. Such sensor finds application in industrial automation control, at home for automatic light control for floors, bathroom, garage, ventilators, security system, alarm etc. In this post, you will find how to interface a PIR sensor with AVR's microcontroller ATmega32 and C program to turn on a LED when the  sensor senses heat radiation from body.

Shown below is a picture of PIR sensor module. 

PIR Sensor module

The bottom part is shown below along with the pins, their meaning, jumper setting and the two adjustment potentiometer for sensitivity and time delay.

PIR Sensor module pins
Interfacing PIR sensor with Microcontroller

The schematic below shows how you can interface PIR sensor module with ATmega32 microcontroller. The PIR sensor module and 3 pins(see picture above)- the ground pin, the data output pin and the Vcc pin for power supply to the sensor. The ground and Vcc pin are connected to the same ground and Vcc used for the microcontroller. The data output pin(the middle one) is connected to the PC7 pin of the microcontroller. 

Also a led is connected to the PB0 pin of the microcontroller to indicate the presence of detected body by the PIR sensor. So whenever, someone enters the heat detection zone of the PIR sensor, it outputs signal to the Microcontroller which then turns on the LED, indicating that someone is there or trigger alarm etc.
 

Interfacing PIR sensor with Microcontroller

The picture below shows PIR sensor module interfacing with ATmega32 on a breadboard.

PIR sensor with ATmega32 breadboard

Video Illustration of PIR Sensor with ATMega32 microcontroller is shown below.

 

C program for PIR sensor and AVR microcontroller

A C program for AVR based ATmega32A microcontroller which turn on a LED whenever the PIR sensor detects something in its zone is below. A simple if else statement in the while loop checks whether the PIR sensor data pin is high or low and accordingly turns on/off the LED.


#ifndef F_CPU
#define F_CPU 4000000UL
#endif

#include <avr/io.h>

int main(void)
{
	DDRC &= (1<<PC7);	//make PC2 pin an input for PIR sensor input
	PORTC |= (1<PC7);	//enable PC2 internal pullup
	DDRB |= (1<<PB0);	//make PB0 pin an output for LED

    while(1)
    {
        if(PINC & (1<<PC7)){
				PORTB |= (1<<PB0);
		}
		else
			PORTB &= ~(1<<PB0);
	}return(0);    
}

Hopefully this small project is helpful to you to learn about PIR sensor, its interfacing and programming with AVR microcontrollers.

See next how to program PIR Sensor with Arduino.

Other tutorials on light controls,

- Laser Diode & LDR based alarm system using Arduino

- Light Dependent Resistor (LDR) Light Detector Alarm with Arduino

Post a Comment

Previous Post Next Post