The HC-SR505 Mini PIR Motion Sensor is based on infrared technology and it can automatic control by itself with high sensitivity and high reliability. Because of the minimum size and low-power operation mode, it widely used in various of automatic electronic equipment, especially battery-powered automatic products.
It works similar to the larger hc-sr501 which is commonly used in many projects
Very simple to use, the code below shows a simple sketch. As you can see it simply a case of reading the output and if it goes high then the PIR has detected something
Code
[codesyntax lang=”cpp”]
void setup() { Serial.begin(9600); pinMode(4,INPUT); digitalWrite(4,LOW); } void loop() { if(digitalRead(4)==HIGH) { Serial.println("Movement detected."); } else { Serial.println("Nothing."); } delay(1000); }
[/codesyntax]
Here is the output you would expect to see in the serial monitor.
Output
Nothing.
Nothing.
Nothing.
Nothing.
Movement detected.
Movement detected.
Movement detected.
Movement detected.
Movement detected.
Movement detected.
Movement detected.
Link
A low cost module this one, you can pick these up for about $2 a piece
HC-SR505 Mini Infrared PIR Motion Sensor Precise Infrared Detector Module