Arduino and PIR Motion Sensor

This evening i have been playing with a PIR motion detector and connected it to my Arduino. I wanted to see how this motion detector behaved and performed. Maybe to create my own motion sensors.
Left=MS13, right=tested PIR:

Regular MS13 and PIR compared

So i hooked it up to the 5V output from the Arduino and connected the PIR output to one of the Arduino’s digital inputs and added a LED to have a visual confirmation of motion detection:

Arduino, XBee and PIR

And i wrote a sketch that switches the LED and writes some text to the XBee that was also connected to the Arduino.

//
// PIR motion detector with LED indicator
// Status info by XBee to PC
// 07 Oct 2009
//

#include <NewSoftSerial.h>

NewSoftSerial XBSerial = NewSoftSerial(2, 3);

int PIRpin = 4;		// digital pin 4 for PIR
int LEDpin = 9;		// digital pin 9 for LED
int PIRval;             // PIR HIGH or LOW value

void setup() {
  pinMode(LEDpin, OUTPUT);    // set the LED pin as ouput
  pinMode(PIRpin, INPUT);     // set the PIR pin as an input

  // Setup SoftwareSerial port
  XBSerial.begin(9600);
  // send informational message to terminal window
  XBSerial.println("Setup finished.");
}

void loop() {

  PIRval = digitalRead(PIRpin);    // read PIR
  if (PIRval == HIGH) {
    XBSerial.print(millis());      // show uptime
    XBSerial.println(" High!");
    digitalWrite(LEDpin, HIGH);    // LED ON
  }
  else {
    XBSerial.print(millis());
    XBSerial.println(" Low!");
    digitalWrite(LEDpin, LOW);     // LED OFF
  }
  delay(100);
}

And here some sample output, captured with Hyperterminal:

...
205564 Low!
205679 Low!
205793 High!
205908 High!
...
...
209485 High!
209601 High!
209716 Low!
209830 Low!
209945 Low!
...

(those numbers are milliseconds)

From what i have seen so far, detected motion results in a high output value for about 1.5 – 2 seconds minimal. And as long as there is motion detected, the output will remain high.

In the very short time i tested this PIR, sensitivity looks very good.

Actually this is very nice; with this PIR you have almost realtime information about whether there is motion detected or not. Hook it up to an Arduino which will do the polling and for example only forward changes in motion detection.

Perhaps even add extra functionality in when to forward changes, like motion has to have a minimal time of x seconds before it is considered motion. Anything is possible. 🙂

Next thing on the list is combining a PIR and a XBee module to make the PIR wireless.