Pages: [1]   Go Down
Author Topic: Problems with SE-10 PIR Motion Sensor  (Read 1314 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 40
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey guys.
I'm developing a project that concerns the detection of Human presence inside a room.
For this I am using an Arduino with a SE-10 PIR Motion Sensor http://www.sparkfun.com/products/8630.
Although the easy way to put all the stuff working,the results obtained are not the expected.
For example this morning I made a test, where I put the PIR sensor inside a box, to not detect any kind of motion.
Unexpectedly the results were the following:
In 1275 iterations, it had detected motion for 140 times, what represents in the end an error % of 10%!!!

To let you know I am using an open collector scheme with a pullup resistor of 10kohms (http://bildr.org/2011/06/pir_arduino/),  that sends the values to an arduino (supplies the sensor with 5V).

Because I am thinking to use both sensors in my master thesis project, this problem is really worrying.

Thus can somebody help me?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

have you accounted for the 1-2 seconds it takes the pir to "warm up" in your code? (like adding a delay in void setup?) also, in my experience with a PIR (mine is a different model, but perhaps this is still your problem), the pin is pulled low for several seconds, so if your code loops several times in a second, the int that is are counting the times the alarm was tripped could be going up more than you intend it to (perhaps the pir was only tripped once, but your code looped 140 times before the pir pin returned to high).
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 40
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is my code (sorry for some names in portuguese smiley )
I put some lines to know about the error produced...

Code:
int calibrationTime = 60;        

int pirPin1 = 2; //digital 2

int LED1 = 4;
int n_detecoes=0;
int n_iteracoes=0;
int per_detecoes=0;

  
void setup()
{
  Serial.begin(9600);
  pinMode(pirPin1,INPUT);

  pinMode(LED1,OUTPUT);

  digitalWrite(LED1,LOW);

  //give the sensor some time to calibrate
  Serial.println("Sensor Calibration in Progress");
  Serial.println("------------------------------");
  for(int i = 0; i < calibrationTime; i++){
    Serial.print(".");
    digitalWrite(LED1, HIGH);
    delay(250);
    digitalWrite(LED1, LOW);
    delay(250);
  }

  Serial.println("");
  Serial.println("Sensor Calibration Completed");
  Serial.println("Sensor Reading Active");
  delay(50);
  
}

void loop()
{
  int pirVal1 = digitalRead(pirPin1);
  
  if(pirVal1 == LOW)
  {
    //was motion detected
    Serial.print(pirVal1);
    Serial.print(';');
    
    n_detecoes=n_detecoes+1;
    Serial.print(n_detecoes);
    Serial.print(';');
    
    digitalWrite(LED1,HIGH);
    delay(2000);
  }
    else
    {
    Serial.print(pirVal1);
    Serial.print(';');
    Serial.print(n_detecoes);
    Serial.print(';');

    
    digitalWrite(LED1,LOW);
    delay(2000);
    }
    
    n_iteracoes +=1;
    Serial.print(n_iteracoes);
    Serial.print(';');
    per_detecoes =(n_detecoes*100)/n_iteracoes;
    Serial.print(per_detecoes);
    Serial.println(';');
}
« Last Edit: April 28, 2012, 04:24:42 am by xaral » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

aha! i am a rather inexperienced coder, but think i have found a problem. if i am not mistaken the first line inside your loop "int pirVal1 = digitalRead(pirPin1);" should be "pirVal1 = digitalRead(pirPin1);" and you should add "int pirVal1 = 0;" to where you have defined the rest of your variables at the top.  i'm not sure if this is causing your "big" problem, but I've done the same thing before, and it does mess everything up
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 170
Posts: 12451
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


please modify your post, select the code  and press the # button (looks so much better).

Quote
I'm developing a project that concerns the detection of Human presence inside a room.
PIR sensors in the first place detect movement, not presence (although these two are tightly coupled.

Once visited a company who had PIR in meeting rooms and if we just sat on the tables it took 2 minutes before lights went out. (immediately people started waving smiley
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 40
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey Rob! Your totally right. I made the mistake using the word presence, but I know that this sensor just capt movement... Sorry for the mistake smiley-wink

About the code Teddy I'm not sure if the position of the definition of int variable ca affect the final result...
I will try on Monday to use your suggestion on my work

 Muito Obrigado  smiley-grin
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yeah, i have no idea why it seems to mess it up, but in my experience, EVERYTHING has been messed up when i've done that.
Logged

Ontario, Ohio
Offline Offline
Full Member
***
Karma: 1
Posts: 205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

As far as motion sensor go, I have a couple parallax motion sensors, and I've beat myself up trying to find a way to make them accurate let alone precise. If you want to spend the money there are industrial grade motion sensors out there that are very reliable. The question is: Do you want to spend the money, and can you adapt them to arduino?
« Last Edit: April 30, 2012, 04:00:32 pm by TeslaIaint » Logged

Ontario, Ohio
Offline Offline
Full Member
***
Karma: 1
Posts: 205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

But you could also use a simple filter in your program like a mode/median filter similar to how people use them for ultra sonic detectors.
Average the readings.
« Last Edit: April 30, 2012, 04:01:29 pm by TeslaIaint » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 40
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Unhappily I don't have more money to spend on material, so I must work with the stuff I already bought smiley

Concerning master thesis and arduinos just google it and you will find a lot of thesis that use arduino as microcontroller over the world. Of course this PIR sensor's don't have the best quality, but as far as sparkfun sell them I thought they had the minimum quality acceptable...

At this moment I'm thinking to use something like mode/median filter, the question is: will this filter erase also the true values, when somebody is moving? How the code will know wich values are true and false? Thanks for you help Tesla smiley-wink
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 40
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Happily a colleague suggest me to put the sensor in a dark room, instead of put it in a box. Seems that it sensibility isn't good for small spaces...

There's another problem now. Some of my movements in front of the sensor was not detected...

 smiley-money  smiley-money
Logged

Ontario, Ohio
Offline Offline
Full Member
***
Karma: 1
Posts: 205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, they are not reliable. You could average the readings or you could use two, average those readings, etc.
Logged

Pages: [1]   Go Up
Jump to: