Components Required

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

Introduction

A relational operator is an operator that tests some kind of relation between two entities. The result of the relational operator is either true or false.

evive Notes Icon
Note: In programming, true is represented by the value 1 and false is represented by the value 0.

There are 6 relational operators in Arduino IDE:

Relational OperatorsOperator SymbolExample
Greater than>currentYear > 2015
Less than<2015 < currentYear
Greater than or equal to>=currentYear >= 2017
Less than or equal to<=2017 <= currentYear
Equal to ==centuryYear == 2000
Not equal to!=centuryYear != 1999

Greater than (>)

It returns true if number 1 is greater than number 2. If number 1 is equal to or less than the second number, it returns false. Given below is an example:

The result of the operation will be:

Is 7 greater than 4: 1 

Is 7 greater than 10: 0

Less than (<)

It returns true if number 1 is less than number 2. If number 1 is equal to or greater than the second number, it returns false. Given below is an example:

The result of the operation is:

Is 7 less than 4: 0

Is 7 less than 10: 1

Greater than or equal to (>=)

It returns true if number 1 is greater than or equal to number 2. If number 1 is less than the second number, it returns false. Given below is an example:

int Result1;
int Result2;

The result of the operation is:

Is 7 greater than or equal to 10: 0

Is 7 greater than or equal to 7: 1

Less than or equal to (<=)

It returns true if number 1 is less than or equal to number 2. If number 1 is greater than the second number, it returns false. Given below is an example:

The result of the operation is:

Is 7 less than or equal to 4: 0

Is 7 less than or equal 7: 1

Equal to (==)

It returns true if number 1 is equal to number 2, otherwise, it returns false. Given below is an example:

The result of the operation is:

Is 7 equal to 10: 0

Is 7 equal to 7: 1

Not equal to (!=)

It returns false if number 1 is equal to number 2, otherwise, it returns true. Given below is an example:

The result of the operation is:

Is 7 not equal to 10: 1

Is 7 not equal to 7: 1