I'm using an LDR here in this script. My script outputs a value to the variable lockedValue once in my script and then maximum and minimum values are calculated based on the lockedValue. I also have a third variable that updates with the LDR called updatedValue and I'm creating a range where if the updatedValue goes above or below the max and min, the if statement triggers. Right now, the values are all printing correctly to console and the min and max values are correct in relative to the lockedValue but the if statement doesn't trigger as it should be. Here's the range code minus the trigger for lockedValue.
int lockedValue = 0; //this value triggers from a sensor once
int updatedValue = 0; //this value is constantly pulled from sensor
int Minimum = 0;
int Maximum = 0;
void loop() {
Minimum = lockedValue - 10; //minimum value is calculated
Maximum = lockedValue + 10; //maximum value is calculated
Serial.println("====================");
Serial.println(lockedValue);
Serial.println(updatedValue );
Serial.println(Minimum);
Serial.println(Maximum);
if(updatedValue >= Minimum || updatedValue <= Maximum) {
Serial.println("Trigger");
}
}
And then see #6 again , where it also says "With coding problems, if possible post a "minimal" sketch that demonstrates the problem - not hundreds of lines of code."
So post complete code in the sense that it must be a sketch that compiles and runs, and shows the problem, but doesn't require other hardware like in your case the rfid and pir.
I get that you were trying not to clutter things, but there's no way anyone can run or comment on a sketch that isn't complete.
I'm going to hazard a guess that the problem's to do with the delays.
12Stepper:
And then see #6 again , where it also says "With coding problems, if possible post a "minimal" sketch that demonstrates the problem - not hundreds of lines of code."
So post complete code in the sense that it must be a sketch that compiles and runs, and shows the problem, but doesn't require other hardware like in your case the rfid and pir.
I get that you were trying not to clutter things, but there's no way anyone can run or comment on a sketch that isn't complete.
I'm going to hazard a guess that the problem's to do with the delays.
Ah sorry about that.
sterretje:
From the opening postMinimum equals -10, Maximum equals +10.
Pick a number for updatedValue and check the outcome of the if; use e.g. -20, 0 and +20. The result will always be true.
You probably want a logic AND (&&) instead of a logic OR (||).
Shouldn't i be using the logic OR(||) since it can either be max or minimum instead of logic AND(&&) ?