PIR sensor not very ... sensitive

Hi all,
This is my first time working on anything like this, so this may be a stupid question.

I’m making a motion-sensing alarm to alert me when my sleep-walking daughter gets out of bed. I followed the instructions from here:

It works good ( the led lights up and I receive notifications on my phone), but the motion sensing seems very temperamental. Sometimes it only fires if I hold my hand right over the sensor and move away, but other times it seems to detect movement from several feet away. The sensor I bought is from here:

Could I be missing something obvious that would let the device mostly work, but just not very well?

Thank for any help.

I don’t see the required pull-up resistor - neither in “person” on the board nor in code as INPUT_PULLUP.

The SparkFun docs do state this

The easiest first try would be to alter the pinMode() statement in your setup() function to this

  pinMode(inputPin, INPUT_PULLUP); 

Another reason why publishing might be a bit flaky is that there is no code that would enforce the publishing rate limit of max 1 per second.
You could just add a “dumb” delay(1010) directly after the Particle.publish() statement.

Thanks ScruffR. I changed the code to use the INPUT_PULLUP, but didn’t see any real difference in temperament. I’m going to try playing around with delays to see if that reduces the false positives, and if that doesn’t work, try and do a counter where “if > x events in < y time, then publish”.

If that doesn’t work I may try an accelerometer instead of the PIR, and hand it from my daughter’s door. I’d probably need to figure out how to use a rechargable battery too in that case.

Lots to learn!

I did an experiment with using an accelerometer with a Photon and Power Shield, powering by a rechargeable LiPo battery. It worked well and lasted 3 weeks per charge in my test.

Thanks rickkas7. That looks perfect if I need to head that route. I may have to do some hunting around for a full wire-diagram for the accelerometer (as I don’t quite follow the instructions on your github page) but I think it provides pretty much all the details I’d need.

I just reread the code and the info in SparkFun, but something confuses me there.
SparkFun says

But the code says

void readTheSensor() {
  val = digitalRead(inputPin);
}

void reportTheData() {

  // if the sensor reads high
  // or there is now motion
  if (val == HIGH) {

    // the current state is no motion
    // i.e. it's just changed
    // announce this change by publishing an eent
    if (pirState == LOW) {
      // we have just turned on
      Particle.publish("designingiot/s15/motion");
      // Update the current state
      pirState = HIGH;
      setLED( pirState );
    }
  } else {
    if (pirState == HIGH) {
      // we have just turned of
      // Update the current state
      pirState = LOW;
      setLED( pirState );
    }
  }
}

So if I read the code correct you’ll only publish after the movement has happened and “silence” was reestablished.
I’d rather publish on first LOW and lock against another publish till there was at least some time of “silence” (HIGH) to rearm for the next FALLING edge.
And mentioning FALLING edge also brings up using interrupts rather than polling :wink:

When I said

I hoped the weak 40k internal pull-up might do, but if not adding a stronger external 10k pull-up (towards 3V3 and possibly reverting to INPUT) might help.

But then some of the comments of users on the SparkFun page don’t sound very reassuring :confused:

I bought one of those for a project that I didn’t get around to doing. I tested it when I got it and it worked OK.

I’ve just now plugged it in to a Core and it’s still working. It detects me at 2 or 3 metres, I’m using INPUT_PULLUP, and simply lighting the D7 led for testing purposes.

I would follow ScruffR’s advice about a silence period between publishing alerts. My D7 led goes on and off several times as I walk across the room.

1 Like