Arduino IDE: Boolean or Logical Operators

About This Tutorial
This tutorial discusses what are logic operators and the different types of logic operators in Arduino IDE, such as the AND operator, OR operator, and NOT operator.
Tutorial Info
Programming Platform:
Difficulty:
Estimated Time (hrs):
2

Components Required

ImageComponentQuantityAvailable in Kit
evive1
USB A-B Cable1

Introduction

Logical operators evaluate either one or two relational or logical statements. There are 3 logical operators in Arduino IDE:

Logical OperatorOperator SymbolExample
OR||a || b
AND&&a && b
NOT!! a

Logic OR (||) Operator

Structure

(Statement 1) || (Statement2)

The logic OR operator results in true if either Statement1 or Statement2 or both are true. If both the statements are false, then it will result in false. Below is its truth table:

Statement1Statement2Statement1 || Statemen2
000
011
101
111

Below is an example showing how to use the logic OR operator:

Serial monitor output:

Result 1: 1

Result 2: 1

Result 3: 1

Result 4: 0

Logic AND (&&) Operator

Structure

(Statement 1) && (Statement2)

The logic AND operator gives true only if both Statement 1 and Statement2 are true. If either Statement1 or Statement2 or both are false, then it will result in false. Below if the truth table:

Statement1Statement2Statement1 || Statemen2
000
010
100
111

Below is an example showing how to use the logic AND operator:

Serial monitor output:

Result 1: 1

Result 2: 0

Result 3: 0

Result 4: 0

Logic NOT (!) Operator

Structure

! Statement

The NOT operator checks whether the Statement evaluates to 0 or not. If it is 0 it results in true; otherwise it results false. 

Below is an example showing how to use the NOT operator:

Serial monitor output:

Result 1: 0

Result 2: 1

This Helped
This didn't help
Share this Tutorial
Facebook
Twitter
Google+
Pinterest
Reddit
Print
Related Tutorials
Featured Projects

Leave a Reply

Close Menu
×

Cart