PIR always reading LOW

I have a PIR Motion Sensor for an Arduino Duemilanove 328 from Cool Components .co.uk.

It is connected using 3V3 to B+, ground to GND and Alarm to 220 ohm resistor to Digital In 2.

The code on the board is:

int ledPin = 13;                // choose the pin for the LED
int inputPin = 2;               // 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

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

void loop(){
  Serial.println(val);
  val = digitalRead(inputPin);  // read input value
  if (val == HIGH) {            // check if the input is HIGH
    digitalWrite(ledPin, HIGH);  // turn LED ON
    if (pirState == LOW) {
      // we have just turned on
      Serial.println("Motion detected!");
      // We only want to print on the output change, not state
      pirState = HIGH;
    }
  } else {
    digitalWrite(ledPin, LOW); // turn LED OFF
    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 code compiles and uploads correctly but regardless of motion the input constantly reads LOW.

Can anyone suggest where I'm going wrong?

Thanks, Chris

Do you have the jumper installed for 3.3V operation, as noted in the description of the product?:

http://www.coolcomponents.co.uk/catalog/product_info.php?cPath=36_57&products_id=312

Also, your pull up resistor (which I don't know if you have the right value, BTW) should be wired as:

3.3V to resistor to pin; then the output of the PIR to the pin - ie, something like:

V+ | 220 R | PIR--+---PIN OUT

Thank you for your reply cr0sh.

I’ve reworked the circuit using your suggestion and am now getting output!

However, the output is nonsense :slight_smile:

I’ve left the sensor sitting for up to 2 minutes in the hope that it was merely calibrating itself but after the 2 minutes the output isn’t any better.

An example of the output:

Motion detected!
1
1
1
Motion ended!
0
Motion detected!
1
Motion ended!
0
Motion detected!
1
Motion ended!
0
0
0

This repeats ad infinitum. Any suggestions?