Hi there,
wondering if anyone can help me with this problem...
I'm using a PIR sensor (link to the specific one I have below) to trigger two relays controlling a light and a speaker. I want the light to flash and the speaker to play sound when there is NO motion, and then to turn off when there is motion detected, and stay off until there is no motion again. This seems to be working fine some of the time, but sometimes (not always!) the sound and light come back on while there is still someone in front of the sensor. I have the jumper in the H position (repeatable mode I think), and I have the sensitivity potentiometer all the way clockwise (highest sensitivity) and the delay one all the way counter-clockwise (shortest delay).
if anyone has any ideas about what I might be doing wrong please help!
here's the code I'm using:
int light = 3;
int speaker = 4;
int pirSensorPin = 2;
int motionDetected = LOW;
void setup() {
pinMode(light, OUTPUT);
pinMode(pirSensorPin, INPUT);
pinMode(speaker, OUTPUT);
Serial.begin(9600);
delay(5000);
}
void loop(){
motionDetected = digitalRead(pirSensorPin);
if(motionDetected == LOW)
{
digitalWrite(speaker, HIGH);
digitalWrite(light, HIGH);
delay(300);
digitalWrite(speaker, HIGH);
digitalWrite(light, LOW);
delay(200);
}
digitalWrite(light, LOW);
digitalWrite(speaker,LOW);
}
and here's the sensor: