Components Required

Image Component Quantity Available in Kit
evive 1
USB A-B Cable 1

Introduction

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

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

OR Logic Operator

Structure of OR logic operator:

(Statement 1) || (Statement2)

The OR logic operator gives true if Statement1 or Statement2 or both are true. If both the statements are false, then it will give false. Given below if the truth table:

 

Statement1Statement2Statement1 || Statemen2
000
011
101
111

Given below is an example of OR logic operator:

 

The serial monitor output is:

Result 1: 1

Result 2: 1

Result 3: 1

Result 4: 0

AND Logic Operator

Structure of AND logic operator:

(Statement 1) && (Statement2)

The AND logic operator gives true if both Statement 1 and Statement2 are true. If Statement1 or Statement2 or both are false, then it will give false. Given below if the truth table:

 

Statement1Statement2Statement1 || Statemen2
000
010
100
111

Given below is an example of AND logic operator:

The serial monitor output is:

Result 1: 1

Result 2: 0

Result 3: 0

Result 4: 0

NOT Logic Operator

Structure of NOT logic operator:

! Statement

The NOT operator checks whether the statement evaluate to 0 or not. If it is 0 it give true, otherwise false. Given below is an example of NOT logic operator.

The serial monitor output is:

Result 1: 0

Result 2: 1