sorry for the newbie question.
this will be basic for you guys.
i'm using a PIR sensor which should control a relay,
when the PIR is low the relay is (close) high
when the PIR is high the relay should (open) then have a delay of 100 ms
and close again. until the PIR is high again.
the problem i have is that the PIR is continuously sending state data also when the PIR detects a presence sends constantly "high" data for a couple of seconds. my problem is that whenever the PIR is high some of my code is looping.
help!
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == LOW)
digitalWrite(ledPin, HIGH);
if (buttonState == HIGH)
digitalWrite(ledPin, LOW);
delay(1000);
digitalWrite(ledPin, HIGH);
}
the problem i have is that the PIR is continuously sending state data
No, it isn't. You are continually asking for the data. Big difference.
So, what you are looking for is a transition from LOW to HIGH. To get that, you need to store the current state, at the end of loop, as the previous state. Then, after reading the current state, determine if the current and previous states are the same. If not, and the current state is "there is motion", do something with the relay.
Do you have a button connected to the Arduino, or a PIR. If it is a PIR, why don't your variable names reflect that?