PIR

Hello,

I have just started playing about with a PIR sensor, however, all I am getting printed out on the serial monitor is 'motion' even when there is not. This is my first time playing with one of these, and I have tried to keep the code as simple as possible (for my own benefit too) but something has gone wrong. Maybe someone can spot what I am sure is a silly mistale on my part.

int val = 0;
int inputPin = 2;
int pirState = LOW;

void setup()
{
  Serial.begin(9600);
  pinMode(inputPin, INPUT);
}

void loop()
{
  val = digitalRead(inputPin);
  if (val == HIGH)
  {
    Serial.println("Motion");
    delay (5000);
  }
  else if (val == LOW)
  {
    Serial.println("No Motion Detected");
    delay(5000);
  }
}

Thanks
Seán

First, simplify:

if (val == HIGH)
  {
    Serial.println("Motion");
    delay (5000);
  }
  else 
  {
    Serial.println("No Motion Detected");
    delay(5000);
  }

Second, are you sure, your PIR provide high when triggered? May be it's opposite.

First, simplify:

const int inputPin = 2;

void setup()
{
  Serial.begin(9600);
  pinMode(inputPin, INPUT);
}

void loop()
{
  int val = digitalRead(inputPin);
  if (val == LOW) {
    Serial.print("No ");
  }

  Serial.println("Motion Detected");
  delay(5000);
}

Hello,

Thanks for that! I will try those suggestions out this evening!

Thanks again.

Seán

KE7GKP:
Exactly what is the nature of the output from your PIR sensor? Is it open-collector? Is it active high or active low? We have no clue without some identification of the sensor.

It is the Parallax PIR Sensor (555-28027), and the data sheet says it is active high. Thats why my logic was if a HIGH signal was received on the digital input, then that would signify motion, but it just doesn't seem to be working out that way.

As for the pull-down resistor, the documentation doesn't say it is needed, but I will give it a go!

Thanks for all the advice from everyone!

Seán