Overview of PIR Motion Sensor
The PIR sensor detects infrared heat radiation and is commonly used to identify the presence of living objects that emit such radiation.
The sensor consists of two slots connected to a differential amplifier. When a stationary object is in front of the sensor, both slots receive an equal amount of radiation, resulting in no output signal.
However, when a moving object passes in front of the sensor, one slot receives more radiation than the other. This imbalance causes the output to fluctuate, either swinging high or low. This change in output voltage indicates motion detection.
For more details about the PIR sensor and its usage, refer to the topic PIR Sensor in the Sensors and Modules section.
PIR Sensor
Connection Diagram of PIR Sensor with ATmega16/32
Interfacing PIR Sensor With AVR ATmega 32
Note:
Avoid Placing PIR Sensors Near Wi-Fi Antennas
To ensure optimal performance, never place a PIR (Passive Infrared) sensor close to a Wi-Fi antenna, ESP32, or NodeMCU.
PIR sensors work by detecting changes in infrared radiation to sense motion. However, Wi-Fi signals emit electromagnetic radiation that can interfere with the PIR sensor, often causing false detections.
To prevent this interference:
- Keep the PIR sensor and Wi-Fi antenna as far apart as possible.
- Consider shielding the PIR sensor from Wi-Fi signals using metal shields or Faraday cages.
Proper placement and shielding will help maintain accurate motion detection and reduce interference issues.
Detect Motion using ATmega16/32 Microcontroller
In this project, we will detect motion using a PIR sensor interfaced with the AVR ATmega16/32 microcontroller.
When motion is detected (i.e., the sensor’s output pin goes HIGH), an LED will turn ON, indicating the presence of movement.
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;
}
}