Help with motion sensor interrupt?

First project on a photon and I’m having a minor issue with my motion sensor interrupt. For some reason “motion detected” gets published twice every time I trigger the motion sensor, no matter how long a delay I put in. For example right now I have a delay of 5 seconds in the code. Triggering this once will always result in the light staying on for 10 seconds and two “Motion Detected” lines being published to the dashboard. Any idea how to fix this?

The motion sensor is here:


// -----------------------------------------
// Publish Motion Detection
// -----------------------------------------

// Pin Assignments
int boardLed = D7; // On board LED
int motionSensor = A0; // Motion sensor signal pin

// Variable Assignments
bool motionDetect=false;

void setup() {
  pinMode(boardLed,OUTPUT); // on-board LED is output
  pinMode(motionSensor, INPUT);
  attachInterrupt(motionSensor, ISR, FALLING);

void loop() {
    if(motionDetect==true) {
        Spark.publish("Motion Detected");

void ISR(void) {

Just to be on the safe side, variables that get set by interrupts or other out of order instructions, should be declared volatile

volatile bool motionDetect = false;

Also the docs for your detector state

So you either have an external pull-up in place, or you need to do this

  pinMode(motionSensor, INPUT_PULLUP);

Interesting, when I switch from my external pullup to an internal and change the variable to volatile, I get a continuous triggering of the alarm.

What ext pull-up have you been using? Maybe stick with that one and forgett the internal one (might be to weak - 40-50k).
How have you wired the sensor?

Also try adding feedback blink in your ISR to see if the interrupt actually fires that often - like this

  digitalWriteFast(boardLed, !pinReadFast(boardLed));

while commenting out the blink in your loop().

Also try this with and without noInterrupts().

And try a different sensor pin.

Have you got any means to check the PIR output - e.g. oszillograph?