user37269: 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?

user-1: I ran a test with your original code, with rain and wind varying over all the range:
(rain, wind) -> action
------------------------
(600, 1) -> motor_closed
(600, 2) -> motor_closed
(600, 3) -> motor_closed
(600, 4) -> motor_closed
(600, 5) -> motor_closed
(650, 1) -> 
(650, 2) -> 
(650, 3) -> 
(650, 4) -> 
(650, 5) -> motor_closed
(700, 1) -> 
(700, 2) -> 
(700, 3) -> 
(700, 4) -> 
(700, 5) -> motor_closed
(750, 1) -> 
(750, 2) -> 
(750, 3) -> 
(750, 4) -> 
(750, 5) -> motor_closed
(800, 1) -> 
(800, 2) -> 
(800, 3) -> 
(800, 4) -> 
(800, 5) -> motor_closed
(850, 1) -> 
(850, 2) -> 
(850, 3) -> 
(850, 4) -> 
(850, 5) -> motor_closed
(900, 1) -> 
(900, 2) -> 
(900, 3) -> 
(900, 4) -> 
(900, 5) -> motor_closed
(950, 1) -> motor_open
(950, 2) -> 
(950, 3) -> 
(950, 4) -> 
(950, 5) -> motor_closed

So your logical expression reduces to this:
if (analogRead(rain) < 650 || Wind > 4) {motor_close();}
else if (analogRead(rain) > 900 and Wind == 1) {motor_open();}

It's that what you want? 
What's that "limiting switch"? May be it's a physical problem (like installing sensor under de roof)

37269: <p>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:</p>

<pre><code>if ((analogRead(rain) &lt; 650 || (Wind &gt; 4)){
  motor_closed();
}

else if (analogRead(rain) &lt; 650 &amp;&amp; (Wind &gt; 4)){
  motor_closed();
}

else if (analogRead(rain) &lt; 650 &amp;&amp; (Wind &lt; 2)){
  motor_closed();
}

else if (analogRead(rain) &gt; 900 &amp;&amp; Wind &gt; 4){
  motor_closed();
}

else if (analogRead(rain) &gt; 900 &amp;&amp; Wind &lt; 2){
  motor_open();
}
</code></pre>

<p>Did I make mistake when using <code>&amp;&amp;</code> boolean operator? Or its something else?</p>
 -1: <p>I ran a test with your original code, with rain and wind varying over all the range:</p>

<pre><code>(rain, wind) -&gt; action
------------------------
(600, 1) -&gt; motor_closed
(600, 2) -&gt; motor_closed
(600, 3) -&gt; motor_closed
(600, 4) -&gt; motor_closed
(600, 5) -&gt; motor_closed
(650, 1) -&gt; 
(650, 2) -&gt; 
(650, 3) -&gt; 
(650, 4) -&gt; 
(650, 5) -&gt; motor_closed
(700, 1) -&gt; 
(700, 2) -&gt; 
(700, 3) -&gt; 
(700, 4) -&gt; 
(700, 5) -&gt; motor_closed
(750, 1) -&gt; 
(750, 2) -&gt; 
(750, 3) -&gt; 
(750, 4) -&gt; 
(750, 5) -&gt; motor_closed
(800, 1) -&gt; 
(800, 2) -&gt; 
(800, 3) -&gt; 
(800, 4) -&gt; 
(800, 5) -&gt; motor_closed
(850, 1) -&gt; 
(850, 2) -&gt; 
(850, 3) -&gt; 
(850, 4) -&gt; 
(850, 5) -&gt; motor_closed
(900, 1) -&gt; 
(900, 2) -&gt; 
(900, 3) -&gt; 
(900, 4) -&gt; 
(900, 5) -&gt; motor_closed
(950, 1) -&gt; motor_open
(950, 2) -&gt; 
(950, 3) -&gt; 
(950, 4) -&gt; 
(950, 5) -&gt; motor_closed
</code></pre>

<p>So your logical expression reduces to this:</p>

<pre><code>if (analogRead(rain) &lt; 650 || Wind &gt; 4) {motor_close();}
else if (analogRead(rain) &gt; 900 and Wind == 1) {motor_open();}
</code></pre>

<p>It's that what you want? </p>

<p>What's that "limiting switch"? May be it's a physical problem (like installing sensor <strong>under</strong> de roof)</p>
