Share this article
Improve this guide
How to effectively use the Not equal to operator in Arduino
2 min. read
Updated onOctober 4, 2023
updated onOctober 4, 2023
Share this article
Improve this guide
Read our disclosure page to find out how can you help Windows Report sustain the editorial teamRead more
Key notes
Single-boardmicrocontrollerArduinouses C/C++ programming language,which comprises sets of functions, values (variables and constants), and language structure elements.
Thenot equal toa structure is part of the comparison operators, alongsideequal to,less than,less than or equal to,greater than,greater than or equal to.The graphic sign is!=.
How do I usenot equal towith Arduino?
Not equal tois an element that compares onevariableon the left with avalueorvariableon the right of the operator.
It returns true when the two operands are not equal.
The syntax is usually the following:
x != y; // is false if x is equal to y and it is true if x is not equal to y
Whatnot equal tocondition does is to say thatif the current state doesn’t equal the previous state, then do this.
In the above example, you make a call forallvalues of x that are not equal to 2to be printed in the Serial Monitor, with a delay of 500ms, to allow you to click the button.
It’s recommended to comparevariablesof the same data type including the signed/unsigned type. Comparingvariablesof different data types is possible, but it could generate unpredictable results.
The Serial Monitor is not working on your Arduino? Try these solutions.
Note that theArduino IDEusesC++, but since the physical environment is limited, not all C/C++features can be used and theArduinoenvironment. As a result,Arduinohas helper functions (specific extensions) to enable you to use the hardware easily.
[wl_navigator]
Radu Tyrsina
Radu Tyrsina has been a Windows fan ever since he got his first PC, a Pentium III (a monster at that time).
For most of the kids of his age, the Internet was an amazing way to play and communicate with others, but he was deeply impressed by the flow of information and how easily you can find anything on the web.
Prior to founding Windows Report, this particular curiosity about digital content enabled him to grow a number of sites that helped hundreds of millions reach faster the answer they’re looking for.
User forum
0 messages
Sort by:LatestOldestMost Votes
Comment*
Name*
Email*
Commenting as.Not you?
Save information for future comments
Comment
Δ
Radu Tyrsina