(Reference) PIR
PIR - Passive Infrared Sensor
Wiring
Open PIR (Sparkfun) | Photon 2 |
---|---|
VCC | 3.3v |
GND | GND |
OUT | Any digital pin |
A | (Optional) Any analog pin |
Note: The wire color and pin order is specific to the Sparkfun PIR sensor and not all PIR sensors
Wiring Guide
Operation (Sparkfun PIR)
- Requires 1-2 sec delay in
setup()
to get initial reading from room - Digital output from
AL
pin HIGH
when no movement detectedLOW
when movement detected- Signal remains active
low
for about 3 sec after movement (documentation says 15 sec but that doesn’t seem accurate)
Code
This is a basic example where any movement triggers alarm. More sophisticated use can include millis()
const int MOTION_PIN = D2; // Pin connected to motion detector
void setup() {
Serial.begin(9600);
pinMode(MOTION_PIN, INPUT);
delay(10000); // wait to read the room
}
void loop() {
int proximity = digitalRead(MOTION_PIN);
if (proximity == LOW) // If the sensor's output goes low, motion is detected
{
Serial.println("Motion detected!");
} else {
Serial.println("Motion stopped!");
}
}