When you are looking for low cost sensors to begin experimenting with then a PIR is a nice low cost option. In the following example we will demonstrate the HC-SR501 PIR sensor, this sensor has many nice features including the ability to be driven by 5v, low cost (£2 to £3), decent range (7 metres) and a fairly small size.
These sensors can take anything between 10-60 seconds to warm up, so you should either avoid motion at this point or in your code you would factor this in.
Connecting these to an Arduino is really simple, connect the VCC and GND up and then connect the output to a digital pin, in our example we connect to pin 8.
Practical examples are obviously alarm systems that may activate a camera, sounder or other device, pest alarm to detect and scare animals in your garden, maybe even activate a light on detection
This basic example will display a different output depending on whether motion is detected.
int pirPin = 8;
val = digitalRead(pirPin);
//low = no motion, high = motion
if (val == LOW)
Serial.println(“Motion detected – ALARM”);