Connect PIR Motion Sensor to Arduino: Read Motion Detection
Connect PIR Motion Sensor to Arduino: Read Motion Detection
PIR sensors are popular for projects that need to detect movement, like automatic lights or security alerts. They are inexpensive, low-power, and straightforward to connect.
How PIR Sensors Work
PIR means Passive Infrared. Unlike ultrasonic sensors, PIR does not emit any waves - it only receives infrared radiation from its surroundings.
The human body emits heat at about 37°C, which radiates infrared energy constantly. When a person walks in front of a PIR sensor, the infrared pattern hitting the sensor changes immediately. The sensor detects this change and outputs a signal at the OUT pin.
Key Specifications
| Parameter | Value |
|---|---|
| Dimensions | 3.2 x 2.4 x 1.8 cm |
| Operating Voltage | DC 4.5V - 20V |
| Current Draw | < 60 μA |
| Output Signal | High/Low 3.3V TTL |
| Detection Range | 3 - 7 meters (adjustable) |
| Detection Angle | < 140° |
| Delay Time | 5 - 200 seconds (adjustable) |
| Blockade Time | 2.5 seconds |
| Operating Temp | -20 to +80 °C |
Note on voltage levels: although the module accepts 4.5V to 20V, the output signal is 3.3V TTL. This works fine with 5V Arduino boards since they read 3.3V as HIGH without issues.
Wiring PIR Sensor to Arduino
The wiring is simple - only 3 connections needed.
| PIR Sensor | Arduino |
|---|---|
| VCC (+5V) | 5V |
| GND | GND |
| OUT (Output) | Pin 3 |
The module also has a header for an optional LDR (Light Dependent Resistor) if you want the sensor to only work at night.
Arduino Code to Read PIR
This basic code reads the PIR signal and turns the built-in LED on or off based on motion detection.
const int ledPin = 13; // Arduino's built-in LED
const int pirPin = 3; // PIR OUT connected to pin 3
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(pirPin, INPUT);
Serial.begin(9600); // Open Serial Monitor to view output
}
void loop() {
int motion = digitalRead(pirPin);
if (motion == HIGH) {
digitalWrite(ledPin, HIGH);
Serial.println("Motion detected!");
} else {
digitalWrite(ledPin, LOW);
Serial.println("No motion");
}
delay(1000);
}
Upload this code and open the Serial Monitor. Walk in front of the sensor and you should see the message change immediately if wiring is correct.
Adjusting Sensitivity and Delay Time
The module has two potentiometers on board for customization.
First potentiometer (Delay Time) controls how long the output stays HIGH after detecting motion, adjustable from 5 to 200 seconds. Turn right for longer delay if you want lights to stay on after someone passes.
Second potentiometer (Distance / Sensitivity) adjusts detection range from 3 to 7 meters. Turn left for higher sensitivity, right to reduce range.
There’s also a jumper with two trigger modes:
- L (Non-repeatable trigger) Once triggered, the sensor waits until the delay time expires before detecting again
- H (Repeatable trigger) If motion continues, the output stays HIGH continuously
Project Ideas Using PIR
- Automatic Lighting - Turn lights on when someone enters a room, off when they leave
- Security Alarm - Trigger buzzer or alert when motion is detected
- Auto Camera - Take photos when animals or people pass by
- People Counter - Use two sensors spaced apart to count entries and exits
Practical Considerations
PIR sensors detect changes in heat, so anything causing sudden temperature shifts can trigger false positives. Common sources of interference include:
- Opening doors that let sunlight in suddenly
- Hot air from fans or HVAC vents
- Pets moving around the house
Placement matters too. Avoid mounting the sensor directly in front of windows or in spots with direct sunlight hitting the lens.
Reference Video
อยากทำโปรเจคแบบนี้?
รับทำโปรเจค Arduino / IoT จบงานไว ส่งงานครบ พร้อมสอน
If you need Arduino project service or urgent IoT development, see full service details on the home page
จ้างทำโปรเจคเลย