Trying to connect a motion sensor to the spark

I need to buy a motion sensor to control LEDs and i duno which sensor would be compatible with the spark
these are my list of options I’d appreciate it if some one share their opinion
http://www.active123.com/SESEN116A2B-PIR-Motion-sensor-module-Prodview.html


http://www.jameco.com/webapp/wcs/stores/servlet/Product_10001_10001_2082927_-1#

Thank you

I’m not sure if there’s a big operational difference between those. Personally, I just bought the cheapest I could find on aliexpress, was like $10 for 10 of them… They seem to work just fine. eBay has a bunch of those things as well.

so any of them will work on the spark with no problem ?!

If you look at the description, you’ll notice that all they do is switch a logical state. They go from HIGH -> LOW or LOW -> HIGH upon detected motion. You can easily check for this using digitalRead, or by using an interrupt. So yeah, you should be good with any of those. Like I said, Ebay has quite a few of them as well, for a much lower price. Worthwhile checking out, if you don’t mind the increased delivery time.

Yeah, like @Moors7 said, you can just buy a bunch of them cheap on eBay, and they should work fine. That’s what I did. You can get them much cheaper than those that you linked to. And yes, I’ve actually tried one with a Spark, and it worked fine.

Here’s some sample code:

/*
 * Connected sensor
 * Spark.publish() + PIR motion sensor = awesome
 * Thanks to Adafruit for the reference and inspiration
 */

int inputPin = D3;              // choose the input pin (for PIR sensor)
int pirState = LOW;             // we start, assuming no motion detected
int val = LOW;                  // variable for reading the pin status
int calibrateTime = 10000;      // wait for the thingy to calibrate

void setup() {
  pinMode(inputPin, INPUT);     // declare sensor as input
  Serial.begin(9600);
}

void loop(){
  if (calibrated()) {
    readTheSensor();
    reportTheData();
  }
}

bool calibrated() {
  return millis() - calibrateTime > 0;
}

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

void reportTheData() {
  if (val == HIGH) {
    if (pirState == LOW) {
      // we have just turned on
      Serial.println("Motion detected!");
      Spark.publish("my-motion");
      // We only want to print on the output change, not state
      pirState = HIGH;
    }
  } else {
    if (pirState == HIGH) {
      // we have just turned of
      Serial.println("Motion ended!");
      // We only want to print on the output change, not state
      pirState = LOW;
    }
  }
}

The PIR should have a couple of pots that you can adjust with a small screwdriver to change the motion sensitivity and the delay after a trigger before the PIR will allow a new state change.