
Today, Arduino It is categorized as one of the most relevant elements of a remarkable number of projects developed by the creatorsDesigners and enthusiasts of the maker world are an important part of DIY culture. Because, It provides the necessary characteristics for these projects to deliver high quality as a result..
Thus, Arduino characterized by simplify the process of working with microcontrollersFurthermore, its software is cross-platform, supporting the different motherboard models it jumps across. They are extremely economical And apart from that, its hardware It is flexible, extensible, and open sourceTherefore, without advanced knowledge and without much investment, people can work with arduino.
For its part, one of the most prominent elements in the programming environment Arduino, are the famous OperatorsHowever, many users are unaware of their purpose in hardware programming, and that is why we will explain it in detail here. What are they, what types are there, and what is each one used for in Arduino?.
What are operators in Arduino and what are they used for in hardware programming?
While it is true, an operator Arduino It is defined as a program element that It is applied to one or more operands in a given instruction or expression.Thus, it consists of a symbol that represents an operation and tells the compiler what needs to be done. based on logical or mathematical manipulations.
In that sense, Arduino operators are those who serve to be able to perform basic operations (addition, subtraction, multiplication and division), just like, Boolean operations (true and false), comparison operations, etc.Therefore, these operators are essential when working with Arduino software, since they allow for the possibility of to execute code segments performing some arithmetic operation, counters, comparisons, etc..
Therefore, in short, the operators in Arduino are elements that They facilitate the manipulation of data when you want to program any hardware in that environment and also, They allow you to establish the conditions that will control the flow of the specific program.Generally, the following operators are found in the IDE language: arithmetic, bitwise, comparison, composite, boolean, and pointers (or pointer access).
Types of operators in Arduino programming: What are all the existing ones?
As we mentioned before, the Arduino IDE It has several types of operators when it comes to programming board-based hardware. arduino. Which, Besides distinguishing them, it is worthwhile to know them in detail.
Therefore, in this section of the post, we will define what each type of operator in Arduino programming consists of:
Arithmetic operators
These are Arduino operators that offer the possibility of working with basic operationsIn other words, the arithmetic operators added in the programming environment refer to addition, subtraction, multiplication, division, modulo, and assignmentTherefore, they have the ability to return the sum, difference, product, quotient, or remainder of two operands.
Therefore, these operators are essential for Perform mathematical calculations on Arduino in order to carry out a specific taskHowever, by default, when combining two operators of this type, it is possible to obtain another type of operator. as a new feature. Whether it's, an accumulator or counter (to accumulate a value in a variable on each iteration within a loop or to perform a loop iteration counter).
For its part, in order to perform any arithmetic operation, The type of data that has been defined must be taken into account. (float, int, double, etc.). Otherwise, the operation will overflow as long as the result is larger than what can be stored in the data type.
Bitwise operators
In this case, we are talking about operators who They simplify the handling of one or more digits of a binary numberTherefore, the use of bitwise operators in Arduino is intended to manipulate each bit individually to handle much more precise states. Taking into account that these operations They involve performing calculations with binary numbersas well as making comparisons or negations, performing right or left shifts, etc.
Therefore, they are operators who demonstrate the ability to perform calculations at the bit level of the variables contained in the Arduino programIn this way, they help to solve a wide range of common programming problems or malfunctions, and thanks to this, they are extremely effective.
Comparison operators
As their name suggests, these operators They are used to make comparisons between valuesThat is, they are suitable for comparing two expressions and as a result, generally, They return a Boolean value that represents the relationship of their values.
In that sense, there are operators to be able to compare numerical values, as well as, for compare strings and even objectsOn the other hand, comparisons of one constant or variable with another in Arduino are frequently used. in conditional structures (of the if, while, etc. type) to test whether a condition is true or false. In addition, also They can be used without any specified comparison structure.
Compound operators
In this case, the operators are responsible for combining or linking an arithmetic operation with a specific assigned variable. In this way, they have the power to perform a mathematical operation based on one variable or constant with anotherThanks to this, by simply combining arithmetic operators, it is possible establish new functionalities for the variables.
Now, in general, compound operators are used in loopsin Arduino. So, with these, it will be possible Count the number of times a loop with a for loop performs or even, accumulate a value of a certain variable in each iteration of the loop.
Boolean operators
These are also known as “logical operators” and they refer to those that allow comparing two variables with each other or, failing that, with constants. Therefore, usually, They are a way of comparing two specific expressions.
Now, generally speaking, this type of operator in Arduino They are characterized by returning a value "TRUE" o "FAKE"depending on which operator is being used. In addition, three Boolean operators are distinguished that almost always They are used in "if" type statementsThese are the following: AND (&&), OR (||) and NOT (!).
Pointer access operators
En arduino, They are also called “leading operators” And, in most cases, they are used to work directly with a memory address. Thanks to this, the Arduino IDE and associated programs They will show much greater efficiency.In addition, it will be more practical for users.
Therefore, these types of Arduino pointers are very useful for users who are starting out in Arduino programming and encounter a high level of complexity. Because, They offer remarkable simplicity. and they have free access to them at any time. However, if these are not used properly, You will get an inconsistent program as a result.
List of all Arduino operators and what each one is used for
Now, beyond knowing what types of Arduino operators exist and how each one is defined, it is valuable to know which operators make up these types and what are they used for.
Therefore, below you will find the operators that make up each classification mentioned above:
Arithmetic operators
They are categorized as the most basic of all in Arduino and refer to the following operators:
- + (sum)This is one of the four main arithmetic operations and, in this case, it is an operator that It influences two operands to produce the sum between themTaking into account that, if said operands are of type floating or double and the variable stored in the sum is an integer, then only the integral part will be saved (while the fractional part is lost).
- – (subtraction)Another of the most common arithmetic operations, which, unlike addition, operates on two digits in order to to generate the difference between the second and the firstConsidering that, by default, the subtraction operation may overflow if the result is less than what can be stored in the data type.
- * (multiplication)In this case, the main operator is the asterisk (*) and it focuses on operating on two operands to produce a result the product or multiplication of bothTherefore, the multiplication operation may overflow if the result is greater than what can be stored in the data type.
- / (division)Naturally, this is the fourth main arithmetic operation. Here, the operator influences two operands in order to... generate their division as a resultIn such a case, if one of the numbers is of the floating-point or double type, floating-point mathematics will be used for the calculation.
- = (assignment operator)By default, in Arduino, the assignment operator is responsible for telling the microcontroller that Evaluate or check any expression found on the right-hand side of the equal sign and also instructs it to store it in the variable to the left of the equals sign. For this, the variable to the left of the "=" It must contain the value stored in it, and if it is not large enough for this, the value stored in the variable will be inconsistent.
- % (remainder)While it's true that it's not the same arithmetic operator as subtraction, which deals with... Calculate the remainder whenever one integer is divided by another.Taking into account that, in order to carry out the remaining operation, it is necessary to use the percentage symbol (%). Thus, it is considered a useful function to convert a variable within a certain range.
Bitwise operators
On the other hand, the following are also distinguished various bitwise operators in Arduino.
As with everything, it is essential to know what they are in detail, and here we specify each one:
- & (bitwise AND)This is an operator that works on each bit position of the surrounding expressions independently, and to do so, it relies on a specific rule that states “If both input bits are 1, the resulting output will be 1, and otherwise, the output will be 0.”Thus, one of its most common uses is to select one or more particular bits from an integer value (known as “masking”).
- >> (right bit shift)This makes the bits of the left operand can move to the rightbased on the number of positions specified by the right operand. Now, the syntax it uses is “x >> y”Therefore, the behavior depends on the exact data type of x (the highest bit in x can be 1).
- << (left bit shift)Unlike the previous one, the operator “<<” takes care of move the bits of the left operand to the leftDepending on the number of positions specified by the right operand. In this case, when changing a value X by Y bits (x << y), the leftmost bits in x will be automatically lost.
- ^ (bitwise XOR): It consists of an operator that is specified with the caret symbol (^) and results in a “0” when the input bits are the same. Therefore, if those bits are different, This function provides a 1This operator is typically used when toggling some of the bits of an integer expression. That is, when changing from 1 to 0 or from 0 to 1.
- ~ (NOT bit by bit)In this case, it is characterized as being an operator that applies to a single operand to its rightFurthermore, it sometimes changes each bit to its opposite (for example, 1 becomes 0 and 0 becomes 1). Besides this, it provides encodings for positive and negative numbers (which is called “complement to two”).
- | (bitwise OR)It generally operates independently on each bit in its two surrounding integer expressions. In that way, results in a 1 if one or both input bits are 1 Otherwise, it will be a 0. This is used with the vertical bar symbol.
Comparison operators
Now, it's time to Detail which are the main comparison operators that are handled in arduino.
Below is a detailed list of these elements:
- > (greater than)It focuses on comparing the variable on the left with the value located to the right of the operator. If the operand on the left is greater than the operand on the right, the function will return TRUETo do this, the operator relies on the fact that positive numbers are greater than negative numbers, primarily. When comparing variables of different data types, the results will be unpredictable.
- > = (greater than or equal to)In this case, it returns TRUE as long as the left-hand operand is greater than or greater than or equal to the operand on the rightTherefore, it is also advisable to compare variables that correspond to the same type of data.
- < (less than)It is effective at comparing a variable on the left with the value on the right of the operator. Once this comparison is made, it will return TRUE if the operand on the left... is smaller (or less) than the operand located to the rightThis is based on the premise that negative numbers are less than positive numbers.
- <= (less than or equal to)Simply put, it's an operator used to compare the value on the left with the value on the right of the operand, to determine if this is less than or equal to the operand located on the right and in that case, it will return TRUE as a result.
- == (equal to): It is another comparison operator that basically deals with defining whether the variable on the left is equal to the value on the right of the operatorTo obtain effective results, it is essential to compare two variables of the same data type. While it is possible to compare different variables, This could cause inconsistent results.
- ! = (not equal to)Like all comparison operators, this one also compares the variable on the left with the value or variable on the right of the operator. If They are not the same., automatically, the function in question will display TRUE as a result.
Compound operators
Since these are operators that deal with combining or linking an arithmetic operation with a specific variable, they also They have several functions that are based on mathematical operations.
To find out what they are, we invite you to read the following list:
- + = (composite sum)This is generally an operator in Arduino that allows you to add one variable to another variable or constant. It uses the following syntax: “x += y;” in which both X and Y allow enter the same data types (int, float, double, byte, short and long).
- ++ (increment)As its name suggests, it is a function that has the ability to increase or augment the value of a variable by 1 To do this, it only allows certain data types (int and long). As a result, it provides either the original value or the recently incremented value of the variable used.
- – = (compound subtraction)It is considered convenient in order to be able to Perform the subtraction of a constant or a variable from a specified variableTherefore, given that its correct structure is “x ≠ y”It allows the input of two data types that can be of different types (int, float, double, byte, short and long).
- — (decrement)This refers to an operator that performs the opposite of increment (++), since, reduces the value of a variable by 1Therefore, it returns the original or recently decremented value of the variable.
- * = (compound multiplication)It is defined as a shortcut method that is appropriate for performing multiplication between one variable and another variable or constant. To use it, It is necessary to use the structure “x *= y;”.
- / = (compound division)It is used to effectively divide one variable by another constant or variable. Regarding its structure, we specify that is “x /= y;”Therefore, in the case of Y, it will have to be a variable or constant other than zero.
- % = (composite remainder)Specifically, it is an operator that uses the structure “x %= divisor;” and under it, it is classified as an appropriate shorthand method for calculate the remainder when one integer is divided by another to then assign it back to the variable in which the calculation was performed. It is important to note that the compound remainder operator does not work with floats under any circumstances.
- & = (Compound bitwise AND): With the goal of forcing particular bits in a variable to the LOW state (to 0), this operator It is used with a variable and a constant, in most casesWhich is also known as “reset” or “erase” bits Regarding Arduino programming, in this case, it's advisable to use the binary formatter with constants, since bits will be processed in a bitwise operation.
- ^ = (Composite bitwise XOR)This is generally an operator used with a variable and a constant, thus allowing invert or alternate particular bits in a specific variableAs in the previous case, it is appropriate to use the binary formatter with constants.
- | = (Compound bit OR)If you want to set particular bits within a variable, you can use this function. with a variable and a given constantThis, using the syntax “x |= y;” in which both digit X and digit Y must belong to some specific data types to reveal optimal functioning (char, int and long).
Boolean operators
While it is true, this type of operator They allow you to compare two variables with each other. and even with constant.
Therefore, to make such comparisons, it is important to know what solutions exist, and below we list three of them:
- && (AND): It is the operator that returns “TRUE” o "TRUE" as long as the first condition and together with the second condition are specifically metThanks to this, it can be used within the condition of an if statement.
- || (OR)Unlike the previous Boolean operator, OR deals with returning “TRUE” o "TRUE" when the first O and the second condition are metOtherwise, it will return a negative result. Therefore, it is also used in if statements.
- ! (NOT)If no applied condition is met, this type of Boolean operator will automatically be used. will return the result of “TRUE” or “TRUE”.
Pointer access operators
Basically, as far as the pointers or pointer access operators in ArduinoOnly two of them are being handled.
That's why, below, we'll tell you what they're both about:
- & (reference operator): It is the reference and is defined as one of the main functions that are used with pointers in programming arduino, Specifically. In this way, It simplifies the code and the manipulation of certain data structuresIn addition to this, in some cases, the & symbol is also used as a reference declarator to pass arguments to functions.
- * (dereference operator): Also know as “indirection operator”This is an operator that focuses on dereferencing and is therefore specifically used with pointers in arduino. In that sense, the function mostly deals with return the value of the object specified by the operand.




















