PIR sensor

im using two PIR Sensors for my project and when i have the code uploaded the sensors trigger motion or heat when nothing is in front of them. what can I do to fix this problem?

what can I do to fix this problem?

Start with posting a wiring diagram of your setup, links to all used hardware and the complete code you uploaded to the Arduino. Also it often help if you tell us what kind of Arduino you're using.

using an arduino uno

code:
int ledred = 2;
int pirsensor = 7;
int pirStateA = LOW;
int valA = 0;
int pirsensor2 = 4;
int pirStateB = LOW;
int valB = 0;

int count = 0;

void setup() {
pinMode(ledred, OUTPUT);
pinMode(pirsensor, INPUT);
pinMode(pirsensor2, INPUT);

Serial.begin(9600);

}

void loop() {

valA = digitalRead(pirsensor);
if (valA == HIGH) {
digitalWrite(ledred, HIGH);
if (pirStateA == LOW) {
Serial.println("Object Enter");
count ++;
Serial.println("People count");
Serial.println(count);

pirStateA = HIGH;
}
}

else {
digitalWrite(ledred, LOW);
if (pirStateA == HIGH){

Serial.println("Walk Through");

pirStateA = LOW;
delay(50);
}

}

valB = digitalRead(pirsensor2);
if (valB == HIGH) {
if (pirStateB == LOW) {
Serial.println("People Exit");
count -- ;
Serial.println("remeaning heads");
Serial.println(count);

pirStateB = HIGH;
delay(50);
}
}
else {
if (pirStateB == HIGH){

Serial.println(" Walk Out!");
pirStateB = LOW;
}
}

if (count = 0)
{digitalWrite(ledred, LOW);}

else{
digitalWrite(ledred, HIGH);

}

}

You have to post a link to the PIR sensors as already requested.

This does not work without an external pull up resistor if they are open collector types :

 pinMode(pirsensor, INPUT);    
 pinMode(pirsensor2, INPUT);

Also, with some cheap sensors, it can also depend on what sort of load these are switching. A large load being switched off by one sensor can cause enough electrical noise to trigger the other one on.

here is the link to the PIR sensor

i tried the external pull resistor but no luck

If the sensors appear to be unstable, try the following:

  1. Create a simplified sketch (one sensor) which just switches a led when the sensor is actively detecting something.
  2. Power the sensor using the 3.3 volt Uno pin.

to see if that helps. Also experiment with the jumpers on the sensor.

PIR sensors ofcourse don't work without a fresnel lens (or slit).

I hope you don't expect that two PIRs next to each other can detect direction of movement.
Leo..