Wednesday, April 8, 2009

Using the PIR module

The pir module is part number PIR_MODULE from www.futurlec.com.
This module is really simple to use. Power, Gnd, and TTL output pin you can connect up to one of the arduino digital input pins.

Here is some really simple code that dumps 0 (no activity) or 1 (activity) to the serial port.

int inputPin = 2; // choose the input pin (for the PIR)
void setup(){
pinMode(inputPin, INPUT); // declare pir as input
Serial.begin(9600);
}
void loop(){
Serial.println(digitalRead(inputPin));
delay(100);
}


Once the sensor is tripped it keeps the output high for ~5 seconds and wont trip right away again. This behavior can be adjusted with the small pot on the side of the sensor.

No comments: