ad space

PIR Sensor: Interfacing with ATmega32 Microcontroller

PIR stands for Passive Infrared Sensor. It detects infrared radiation emitted by warm bodies, such as humans or animals, within its range. Unlike active infrared sensors, PIR sensors do not emit infrared radiation but passively detect it, making them energy-efficient and cost-effective.

The PIR sensor module is shown below:

PIR Sensor Module

PIR Sensor module

 PIR Sensor module pins

The bottom of the module reveals its key components:

  1. Pins:

    • Vcc: Provides power to the sensor.
    • Ground: Common ground connection.
    • Data Out: Outputs the detected signal to a connected device.
  2. Jumper Settings: Configure specific functionalities like trigger mode (single or repeatable).

  3. Adjustment Potentiometers:

    • Sensitivity: Determines the detection range.
    • Time Delay: Adjusts the duration for which the output signal remains high after detecting motion.

Interfacing a PIR Sensor with ATmega32

Schematic Overview

Interfacing PIR sensor with Microcontroller

The PIR sensor module connects to the ATmega32 microcontroller using three pins:

  1. Ground Pin: Connects to the ground of the microcontroller's power supply.
  2. Data Output Pin: The middle pin, which connects to pin PC7 on the ATmega32.
  3. Vcc Pin: Connects to the 5V power supply of the microcontroller.

Additionally, an LED is connected to pin PB0 of the microcontroller. The LED serves as an indicator: it lights up whenever the PIR sensor detects motion within its field of view.

The schematic ensures that:

  • The PIR sensor and microcontroller share the same ground and power supply.
  • The microcontroller processes the PIR sensor's output signal and appropriately toggles the LED state.

Breadboard Implementation

The schematic above can be implemented on a breadboard as shown below:

PIR sensor with ATmega32 breadboard


Working Principle

  1. When the PIR sensor detects motion, it sends a high signal through its data pin.
  2. The microcontroller reads this signal on pin PC7.
  3. If the signal is high, the microcontroller turns on the LED connected to pin PB0.
  4. Otherwise, the LED remains off.

This setup can easily be extended to trigger alarms or other devices based on motion detection.


C Program for PIR Sensor with ATmega32

Below is a simple C program for the ATmega32 microcontroller. The program checks the PIR sensor's output and toggles the LED accordingly:

#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);    
}

Explanation:

  • PC7 is configured as an input to read the PIR sensor's output.
  • PB0 is configured as an output to control the LED.
  • The if-else statement in the while loop checks the PIR sensor's signal. If the signal is high, the LED turns on; otherwise, it remains off.

Video Illustration

For a better understanding, refer to the following video demonstrating how the PIR sensor module interfaces with the ATmega32 microcontroller.



Applications and Extensions

This project showcases a simple yet effective way to utilize PIR sensors for motion detection. With slight modifications, the setup can trigger alarms, activate cameras, or control multiple devices in response to detected motion.

If you're interested in exploring further, check out these related tutorials:

In the next tutorial, we’ll learn how to use a PIR sensor with Arduino for similar applications.


Hopefully, this guide helps you understand the basics of PIR sensors and their interfacing with AVR microcontrollers. Feel free to experiment with this setup to create more advanced automation and security systems!

Post a Comment

Previous Post Next Post