Introduction
You’ve connected a PIR sensor to your Arduino, uploaded a sketch, but nothing happens when you wave your hand. Let’s systematically debug the issue.
1. Verify Hardware Connections
The most common mistake is incorrect wiring. For HC-SR501:
- VCC → 5V (or 3.3V if sensor supports it)
- GND → GND
- OUT → any digital pin (e.g., pin 2)
Double-check pin order—some modules have VCC, OUT, GND; others have VCC, GND, OUT. Check the silkscreen labeling.
2. Power the Sensor Correctly
Measure voltage at the sensor’s VCC and GND pins. It should be within spec (4.5-20V for HC-SR501). If using a 3.3V Arduino, ensure the sensor can run at 3.3V (some can, some can’t).
3. Wait for Warm-Up
After power-up, the sensor needs 30-60 seconds to stabilize. During this time, it may trigger a few times, then settle. Don’t test immediately.
4. Test the Sensor Alone
Disconnect the sensor from Arduino. Power it with a 5V supply and connect an LED with a resistor between OUT and GND (anode to OUT, cathode to GND via resistor). Wave your hand; the LED should light. If not, sensor may be faulty.
5. Check Your Code
Here’s a minimal working example:
const int pirPin = 2;
const int ledPin = 13;
void setup() {
pinMode(pirPin, INPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
int pirState = digitalRead(pirPin);
if (pirState == HIGH) {
digitalWrite(ledPin, HIGH);
Serial.println("Motion detected");
} else {
digitalWrite(ledPin, LOW);
}
delay(100);
}
Make sure your pin number matches the wiring.
6. Input Pull-up Confusion
Some tutorials suggest using pinMode(pirPin, INPUT_PULLUP). Do not use internal pull-up for PIR sensors—they have their own output stage. Use plain INPUT.
7. Signal Inversion
Some PIR sensors output LOW when motion is detected. If your sensor behaves opposite, swap HIGH/LOW in code or check if your module has an active-low output.
8. Check with Serial Monitor
Add Serial.println(digitalRead(pirPin)); to see the raw value. If it stays constant (0 or 1) regardless of motion, wiring or sensor is suspect.
9. Try a Different Pin
Some pins may be used for other functions. Move to another digital pin (e.g., pin 3) to rule out pin issues.
10. Still Not Working?
If all else fails, try a different sensor. It’s possible the sensor is DOA.
Conclusion
Most Arduino-PIR issues are wiring or warm-up related. Follow this checklist and you’ll likely find the culprit.
