stands for Passive InfraRed.
The PIR Sensor detects motion up to 20 feet away by using a Fresnel lens and infrared-sensitive element to detect changing patterns of passive infrared emitted by objects in its vicinity.

In this exercise you will build a simple motion detector using a PIR sensor. You will need the following components (from your kit):

  • 1 Parallax PIR sensor
  • 1 LED
  • 1 560 Ohm Resistor (Green-Blue-Brown-Gold)
  • 1 Arduino Duemilanove
  • 1 Breadboard
  • 7 Jumper Wires
Build this circuit:

Note: You will have to carefully place the PIR sensor on the corner of your breadboard so that it fits.

Once you have built this circuit upload the following code:

int ledPin = 13; // led connected to control pin 13
int pirSensor = 0; // the passive infra red sensor will be plugged at analog pin 0
byte val = 0; // variable to store the value read from the sensor pin
int statePin = HIGH; // variable used to store the last LED status, to toggle the light
int THRESHOLD = 5; // threshold value to decide when detected motion is movement or not
void setup() {
 pinMode(ledPin, OUTPUT); // declare the ledPin as as OUTPUT
 Serial.begin(9600); // use the serial port
void loop() {
  val = analogRead(pirSensor); // read the sensor and store it in the variable "val"
  if (val >= THRESHOLD) {
    statePin = !statePin; // toggle the status of the ledPin (this trick doesn't use time cycles)
    digitalWrite(ledPin, statePin); // turn the led on or off
    Serial.println("Motion Detected"); // send the string "Motion Detected" back to the computer, followed by newline
  delay(150); // A delay to avoid overloading the serial port

You have just built a simple motion detector.

Look HERE for a more sophisticated piece of code for your sensor.
John Marshall,
Sep 22, 2010, 9:26 PM