I'm trying to control motor based on rain sensor and my own build anemometer. It should only controlling motor clockwise/CW for open the roof if there are no rain (indicated by value above 900) AND the wind speed below 4 km/h. If there are raining (analog value below 650) and/or wind speed above 4 km/h the motor should spin counterclockwise/CCW. I succeed to rotate the motor CCW if rain and/or high wind speed happen, but when the motor hit the limit switch for stopping the motor, motor only stop for maybe 2 seconds and then back rotating CW (open the roof), even the wind still above 4 km/h. The roof should be open only when there is no rain (analog value above 900) and the wind speed below 2 km/h. Here is my If Statement logic program:
if ((analogRead(rain) < 650 || (Wind > 4)){
motor_closed();
}
else if (analogRead(rain) < 650 && (Wind > 4)){
motor_closed();
}
else if (analogRead(rain) < 650 && (Wind < 2)){
motor_closed();
}
else if (analogRead(rain) > 900 && Wind > 4){
motor_closed();
}
else if (analogRead(rain) > 900 && Wind < 2){
motor_open();
}
Did I make mistake when using &&
boolean operator? Or its something else?
analogRead()
multiple times? Do you expect the result to change that quickly?