PIR Motion Sensor Interface with AVR ATmega16/ATmega32

Overview of PIR Motion Sensor

PIR sensor detects infrared heat radiations. It can be used to detect the presence of living objects that emit infrared heat radiation.

The PIR sensor is split into two slots. The two slots are connected to a differential amplifier.

Whenever a stationary object is in front of the sensor, the two slots receive the same amount of radiation and the output is zero.

Whenever a moving object is in front of the sensor, one of the slots receives more radiation than the other slot. This makes the output swing high or low.

This change in output voltage is the result of the detection of motion.

For more information on the PIR sensor and how to use it, refer to the topic PIR sensor in the sensors and modules section.

PIR Sensor

 

Connection Diagram of PIR Sensor with ATmega16/32

ATmega Interfacing with PIR Sensor
Interfacing PIR Sensor With AVR ATmega 32

 

 

Note:

  • PIR sensor: Never keep PIR Sensor close to the Wi-Fi antenna, ESP32, or NodeMCU.
  • PIR (Passive Infrared) sensor close to a WiFi antenna impacts the sensor's performance.
  • PIR sensors detect changes in infrared radiation for motion detection.
  • WiFi signals emit electromagnetic radiation that can interfere with the PIR sensor. Which causes false detection.
  • So always keep the PIR sensor and WiFi antenna as far apart as possible.
  • Also, you can try to shield the PIR sensor from the WiFi signal. This can be done by using metal shields or Faraday cages around the PIR sensor.

 

Detect Motion using ATmega16/32 Microcontroller

  • Here, we are going to detect motion using a PIR sensor which is interfaced with AVR ATmega16/32.
  • When Motion is Detected (i.e. out pin goes high), the LED will turn ON.

PIR Motion sensor Code for ATmega16/32

/*
 PIR Motion Sensor Interface with AVR ATmega32
 http://www.electronicwings.com
 */

#define F_CPU 8000000UL
#include <avr/io.h>
#define LED_OUTPUT		PORTB
#define PIR_Input		PINC

int main(void)
{
	DDRC = 0x00;	/* Set the PIR port as input port */
	DDRB = 0xff;	/* Set the LED port as output port */

    while(1)
    {
        LED_OUTPUT = PIR_Input;
	}
}

 

Video of Motion Detection using ATmega16/32 Microcontroller


Components Used

PIR Sensor
PIR motion sensors sense the Infrared signal radiated from moving objects including human or animal body. It is generally used to detect the presence of human or animal motions.
1
ATmega 16
ATmega 16
1
Atmega32
Atmega32
1
LED 5mm
LED 5mm
1
Breadboard
Breadboard
1

Downloads

PIR motion Sensor Datasheet Download
ATmega Interface PIR Sensor Project File Download
Ad