[SOLVED]RadioShack PIR Sensor never gives values

I am using a Radioshack PIR with Gnd -> Gnd , VOC -> 3v3 OUT->D6 and even with code as simple as

int inputPin = D6;              // choose the input pin (for PIR sensor)

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

void loop(){
  Serial.println(digitalRead(inputPin));
}

and I try to connect to serial monitor I keep getting the red flash and it disconnects me. Any idea what could be happening?

You may want to try powering it with Vin (5V).

Hmm, not entirely sure why that wouldn’t work. You could try giving it some time to calibrate before polling it. Could you try this code:

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

int inputPin = D6;              // choose the input pin (for PIR sensor)
int pirState = LOW;             // we start, assuming no motion detected
int val = 0;                    // 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("PIR_SENSOR_TRIGGERED!");
      // We only want to print on the output change, not state
      pirState = HIGH;
      RGB.control(true);
      RGB.color(0,255,0);
      delay(2500);
      RGB.control(false);
    }
  } 
  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;
    }
  }
}

It’ll output over Serial, will blink the onboard LED and will send out a SSE. Should give you some visual confirmation. @BulldogLowell’s suggestion is also worthwhile trying, although the sensor should work with 3.3V as well, according to the datasheet, but you never know…
Let me know if that worked for you.

@Moors7
Silly question but where is the 5V pin? I do not have this connected to a breakout board rather a bread board.

if connected over USB, the Vin pin will supply 5V :slight_smile:

1 Like

Gotcha will try when I get home
:smile:

I had a similar experience with an Seeed pir. Specs say 3-5vdc, but it wasn’t at all stable @ 3V.

Ok so 5v and the code above by @Moors7 worked like a charm. Sorry, my photon was getting the famous “cannot compile code” error.

1 Like