Combining Arduino with PIR motion detector

Show or discuss your existing Home automation project here, so a detailed explanation!.....
Post Reply
Digit
Global Moderator
Global Moderator
Posts: 3388
Joined: Sat Mar 25, 2006 10:23 am
Location: Netherlands
Contact:

Combining Arduino with PIR motion detector

Post by Digit »

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:

Image

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:

Image

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

Code: Select all

//
// 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:

Code: Select all

...
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.[8D]

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


<hr noshade size="1"><font size="1">Robert
http://www.hekkers.net <i>Digit's Online Home.</i></font id="size1">
erisan500
Member
Member
Posts: 72
Joined: Thu Jun 18, 2009 10:20 pm
Location: Belgium, Oppuurs
Contact:

Combining Arduino with PIR motion detector

Post by erisan500 »

Looks like you're getting quite confident with the arduino [;)]
Digit
Global Moderator
Global Moderator
Posts: 3388
Joined: Sat Mar 25, 2006 10:23 am
Location: Netherlands
Contact:

Combining Arduino with PIR motion detector

Post by Digit »

Only scratching the surface of what is possible yet :-)

<hr noshade size="1"><font size="1">Robert
http://www.hekkers.net <i>Digit's Online Home.</i></font id="size1">
Post Reply

Return to “Home Automation Projects”