If Statement:

  • The if statement in arduino code is the same way in which we use in english language. The if statement checks if the code written in the condition is true, then the statements written in it will not be executed.

Example:

If (a>b)  digitalWrite(LEDpin, HIGH);

Here, two variables a and b are compared, if a is greater than b, then LEDpin is dumped with HIGH.

Else If Statement:

  • The else if statement in arduino code checks if the code written in the if condition is false,and the condition written in the else if statement is true, then the statements written in the else if statements is executed.

Example:

If (a>b) {
 digitalWrite(LEDpin, HIGH);
}
else if (b<a) {
digitalWrite(LEDpin, LOW);
}

Here, two variables a,b are compared if a is greater than b, then LEDpin is dumped with HIGH. Else if b is greater than a, then LEDpin is dumped with LOW.

Else Statement:

  • The else statement in arduino code checks if the code written in the if condition is false, then the statements written in the else statements is executed.

Example:

if (a>b) { 
digitalWrite(LEDpin, HIGH);
}
else (b<a) {
digitalWrite(LEDpin, LOW);
}

Here, two variables a,b are compared if a is greater than b, then LEDpin is dumped with HIGH. Else LEDpin is dumped with LOW.

Next Post:Loops in Arduino IDE

Previous Post:Intro to Serial Monitor

Categories: Arduino

1 Comment

Arduino Tutorials:Loops in Arduino IDE /C lang - projectsflix · January 3, 2021 at 6:00 pm

[…] Previous Post:If conditions in Arduino IDE […]

Leave a Reply