Hello Guys, first off I want to say I'm a Big noob in Arduino, i only recently started, but here is my problem:
I have two motion detectors that output a 1-Minute Signal when motion is detected, and I want to know how often these Detectors have been triggered, and store it as a variable. I hope you can help me. This is my current code that decides when an alarm should be triggered.
Not much point answering your question if you don't understand the difference between = and == because whatever code you write will not work. That's why I said "First you need to..."
Ok so I had a moment of clarity right now and wrote this code, that should probably work?
if (Arming == 1) {
Sensor1 = digitalRead(27);
Sensor2 = digitalRead(26);
if ((Sensor1 == LOW) || (Sensor2 == LOW)) {
digitalWrite(33, LOW);
state = 0;
alarmON();
}
if (state == 0) {
counter++;
state = 1; //this should ensure it only runs once per detection
}
Yes, the if function checks if sensor one or two have triggered, both triggering simultaneously is extremely unlikely. And then will increment one number, that's exactly what I need, as the sensors are on two completely different doors
State returns back to 0 so the counter gets incremented and state goes back to 1, so it doesn't trigger again until either is triggered? or am I stupid ? xD
I just realised, because the Sensor will output a signal for one minute when triggered, i need to make another if function that puts state to 0 when sensors are high. Sorry about my stupidity xD
because it would just keep adding until the signal goes away