Arduino IDE: Boolean or Logical Operators

Arduino IDE 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

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

Share this Tutorial
Share on facebook
Facebook
Share on twitter
Twitter
Share on google
Google+
Share on pinterest
Pinterest
Share on reddit
Reddit
Share on print
Print
Related Projects & Tutorials
Interfacing Relay with evive
This tutorial explains interfacing of a relay module with evive for controlling high power circuits like AC bulb with help of evive.
All articles loaded
No more articles to load
Featured Projects
Space-Battle-Game on Scratch
Space Battle

This project will show you how to make a cool space battle game on your own in PictoBlox (Scratch-based programming) and play using your Smartphone!

All articles loaded
No more articles to load

Leave a Reply

Close Menu
×

Cart