PIR Conference Room Detection

I saw an Adafruit tutorial for a conference room "in use" detection a few days ago so I built one using slightly different parts:

Nano v3 clone Max7219 dot matrix module Radio Shack PIR module

Wiring is straightfoward but I seem to be having a small problem with my build/code:

What I observe is the PIR sensor going HIGH at somewhat random intervals ...Now, it could be the fact that the sensor has a 120 degree view but it's being pointed at a wall and it still goes high....

Here's my code (I know it's not the most elegant code possible)

include "LedControl.h" // need the library

LedControl lc=LedControl(12,11,10,1); //

// pin 12 is connected to the MAX7219 pin 1 // pin 11 is connected to the CLK pin 13 // pin 10 is connected to LOAD pin 12 // 1 as we are only using 1 MAX7219 //pin 9 = PIR Sensor

define PIR 9

define LOW_BRIGHTNESS 0

define MEDIUM_BRIGHTNESS 7

define HIGH_BRIGHTNESS 15

uint8_t pirState = LOW;

void setup() { //Set up Serial Debugging Serial.begin(9600); // the zero refers to the MAX7219 number, it is zero for 1 chip lc.shutdown(0,false);// turn off power saving, enables display lc.setIntensity(0,LOW_BRIGHTNESS);// sets brightness (0~15 possible values) lc.clearDisplay(0);// clear screen pinMode(PIR, INPUT); showFree(); }

void loop(){ Serial.println(digitalRead(PIR)); int sense = digitalRead(PIR); if(sense == HIGH){ showOccupied();

} else { showFree(); } }

void resetDisplay() { lc.clearDisplay(0); } void showFree() { resetDisplay(); //Column 0, change row from 0 to 7 lc.setLed(0,0,0,true); // turns off LED at col, row lc.setLed(0,0,1,true); lc.setLed(0,0,2,true); lc.setLed(0,0,3,true); lc.setLed(0,0,4,true); lc.setLed(0,0,5,true); lc.setLed(0,0,6,true); lc.setLed(0,0,7,true); //Column 7, change row from 0 to 7 lc.setLed(0,7,0,true); lc.setLed(0,7,1,true); lc.setLed(0,7,2,true); lc.setLed(0,7,3,true); lc.setLed(0,7,4,true); lc.setLed(0,7,5,true); lc.setLed(0,7,6,true); lc.setLed(0,7,7,true); //Row 0, change column from 0 to 7 lc.setLed(0,1,0,true); lc.setLed(0,2,0,true); lc.setLed(0,3,0,true); lc.setLed(0,4,0,true); lc.setLed(0,5,0,true); lc.setLed(0,6,0,true); lc.setLed(0,7,0,true); //Row 7, change column from 0 to 7 lc.setLed(0,0,7,true); lc.setLed(0,1,7,true); lc.setLed(0,2,7,true); lc.setLed(0,3,7,true); lc.setLed(0,4,7,true); lc.setLed(0,5,7,true); lc.setLed(0,6,7,true); lc.setLed(0,7,7,true);

} void showOccupied(){ resetDisplay(); lc.setLed(0,0,0,true); // turns off LED at col, row lc.setLed(0,1,1,true); lc.setLed(0,2,2,true); lc.setLed(0,3,3,true); lc.setLed(0,4,4,true); lc.setLed(0,5,5,true); lc.setLed(0,6,6,true); lc.setLed(0,7,7,true); lc.setLed(0,0,7,true); lc.setLed(0,1,6,true); lc.setLed(0,2,5,true); lc.setLed(0,3,4,true); lc.setLed(0,4,3,true); lc.setLed(0,5,2,true); lc.setLed(0,6,1,true); lc.setLed(0,7,0,true); }

What I observe is the PIR sensor going HIGH at somewhat random intervals ...Now, it could be the fact that the sensor has a 120 degree view but it's being pointed at a wall and it still goes high....

http://www.radioshack.com/graphics/uc/rsk/Support/ProductManuals/2760347_PM_EN.pdf

Section 2 ... Motion Detection for either mode operates at 2-second intervals.

It could be that thermals in the room between the wall and sensor is causing motion detection. IR is funny stuff. The sensor must be kept stationary during operation and should not be pointed directly at a window or area of known drafts.

Ladyada has a good tutorial: http://www.ladyada.net/learn/sensors/pir.html