Post a new topicPost a reply Page 1 of 1   [ 6 posts ]
Author Message
 Post subject: PIR Sensor Help
PostPosted: Tue Aug 02, 2011 8:50 am 

Joined: Tue Aug 02, 2011 8:43 am
Posts: 3
Hi,

I am using a PIR Sensor for security purposes. I have used this code but when there is nothing is covering the sensor it will still detect something that is there. Please help.

void loop()
{
SensorEvent.attachInt();
SensorEvent.detachInt();
SensorEvent.loadInt();

XBee.setMode(XBEE_ON);
delay(200);
if (SensorEvent.intFlag & SENS_SOCKET7)
{
XBee.println("A person is detected");
Utils.blinkLEDs(1000);

}
delay(500);
XBee.close();
SensorEvent.intFlag = 0;
SensorEvent.attachInt();
}

Best Regards.


Top
 Profile  
 
 Post subject: Re: PIR Sensor Help
PostPosted: Tue Aug 02, 2011 10:26 am 

Joined: Mon Sep 28, 2009 1:06 pm
Posts: 7440
Hi WhoUseMyName,

take into account that the PIR is a very sensitive sensor with a wide input range, so any movement in the surroundings may trigger it. You may select the position H with the jumper so the interruption is triggered only once when continuous movement is detected.

Regards.


Top
 Profile  
 
 Post subject: Re: PIR Sensor Help
PostPosted: Wed Aug 03, 2011 5:51 am 

Joined: Tue Aug 02, 2011 8:43 am
Posts: 3
Hi libelium_dev,

Is it possible to calibrate the sensor so that it will cover a fixed range to detect motion. Or is it possible to program it to send message through zigbee so whenever motion is detected for more then 10 seconds, it will send a message.

Best Regards.


Top
 Profile  
 
 Post subject: Re: PIR Sensor Help
PostPosted: Wed Aug 03, 2011 2:58 pm 

Joined: Mon Sep 28, 2009 1:06 pm
Posts: 7440
Hi WhoUseMyName,

I'm afraid it is not possible to calibrate the sensor. The second option is feasible, with the sensor configured to keep the output high at continuous detection, after receiving the interruption you may keep polling the sensor and use the millis() function or the RTC to control the time elapsed and send the XBee message.

Regards.


Top
 Profile  
 
 Post subject: Re: PIR Sensor Help
PostPosted: Mon Aug 08, 2011 6:11 pm 

Joined: Tue Aug 02, 2011 8:43 am
Posts: 3
Hi libelium-dev,

I used this code to detect motion for an amount of time. If it senses motion it will light an LED, if the motion stops the LED will stop. The LED will keep blinking even though there is no movements. I've tried putting the waspmote inside a box. It will still detect movements even inside the box. Is it something wrong with my code or is the PIR Sensor faulty?

This is my code,

int calibrationTime = 10;
long unsigned int lowIn;
long unsigned int pause = 5000;
boolean lockLow = true;
boolean takeLowTime;

void setup()
{
XBee.setMode(XBEE_ON);
SensorEvent.setBoardMode(SENS_ON);

XBee.println("Init RTC");
RTC.ON();
RTC.setTime("11:08:08:02:16:10:00");

XBee.print("calibrating sensor");
for(int i=0; i < calibrationTime; i++)
{
XBee.print(".");
delay(1000);
}
XBee.println(" done");
XBee.println("SENSOR ACTIVE");
delay(50);
}

void loop()
{
if(SensorEvent.readValue(SENS_SOCKET7) == 1)
{
Utils.setLED(LED0, LED_ON);
if(lockLow)
{
lockLow = false;
XBee.println("---");
XBee.print("motion detected at ");
XBee.print(millis()/1000);
XBee.println(" sec");
XBee.println(RTC.getTime());
delay(50);
}
takeLowTime = true;
}

if(SensorEvent.readValue(SENS_SOCKET7) == 0)
{
Utils.setLED(LED0, LED_OFF);
if(takeLowTime)
{
lowIn = millis();
takeLowTime = false;
}
if(!lockLow && millis() - lowIn > pause)
{
lockLow = true;
XBee.print("motion ended at ");
XBee.print(millis()/1000);
XBee.println(" sec");
XBee.println(RTC.getTime());
delay(50);
}
}

}

Best Regards.


Top
 Profile  
 
 Post subject: Re: PIR Sensor Help
PostPosted: Thu Aug 11, 2011 9:30 am 

Joined: Mon Sep 28, 2009 1:06 pm
Posts: 7440
Hi WhoUseMyName,

I've tested your code and it works pretty well.

The PIR sensor may keep retriggering for a few seconds, so you should wait a little bit. Also, it is a very sensitive sensor, you will have to completely cover it with a solid object to make sure it does not detect anything.

Regards.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 1   [ 6 posts ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Libelium theme based on 610nm Style by Daniel St. Jules of http://www.gamexe.net


© Libelium Comunicaciones Distribuidas S.L. | Terms of use