Understanding Arduino Math Operators

Getting Started with Arduino Math operators

In Arduino programming, you can use various math operators to perform arithmetic and logical operations on numeric values. These operators are similar to those found in many other programming languages. Here are some of the most commonly used Arduino math operators:

Addition (+):

The addition operator is used to add two or more numbers together.

int result = 5 + 3; // result will be 8

Subtraction (-):

The subtraction operator is used to subtract one number from another.

int result = 10 - 4; // result will be 6

Multiplication (*):

The multiplication operator is used to multiply two or more numbers.

int result = 6 * 7; // result will be 42

Division (/):

The division operator is used to divide one number by another.

float result = 15.0 / 2.0; // result will be 7.5

Modulus (%):

The modulus operator is used to find the remainder when one number is divided by another.

int remainder = 10 % 3; // remainder will be 1

Increment (++) and Decrement (–):

These operators are used to increase or decrease the value of a variable by 1, respectively.

int count = 5;
count++; // count is now 6
count--; // count is now 5 again

Assignment (=):

The assignment operator is used to assign a value to a variable.

int x = 10; // x is assigned the value 10

Compound Assignment Operators (+=, -=, *=, /=, %=):

These operators combine an arithmetic operation with assignment. They perform the operation and then assign the result back to the variable.

int total = 20;
total += 5; // equivalent to total = total + 5; (total is now 25)

Comparison Operators (==, !=, <, >, <=, >=):

These operators are used to compare two values and return a Boolean result (true or false).

int a = 10;
int b = 5;
bool isEqual = (a == b); // isEqual will be false


These operators are fundamental for performing mathematical and logical operations in Arduino sketches and are essential for controlling hardware based on sensor inputs and other conditions. You can use them to create complex algorithms and decision-making logic in your Arduino programs.

Happy Tinkering!


If you don’t already own any Arduino hardware, we highly recommend purchasing the Elegoo Super Starter Kit. This kit has everything you need to start programming with Arduino.

You can find out more about this kit here: Elegoo Super Starter Kit

Luke Barber

Hello, fellow tech enthusiasts! I'm Luke, a passionate learner and explorer in the vast realms of technology. Welcome to my digital space where I share the insights and adventures gained from my journey into the fascinating worlds of Arduino, Python, Linux, Ethical Hacking, and beyond. Armed with qualifications including CompTIA A+, Sec+, Cisco CCNA, Unix/Linux and Bash Shell Scripting, JavaScript Application Programming, Python Programming and Ethical Hacking, I thrive in the ever-evolving landscape of coding, computers, and networks. As a tech enthusiast, I'm on a mission to simplify the complexities of technology through my blogs, offering a glimpse into the marvels of Arduino, Python, Linux, and Ethical Hacking techniques. Whether you're a fellow coder or a curious mind, I invite you to join me on this journey of continuous learning and discovery.

Leave a Reply

Your email address will not be published. Required fields are marked *

Verified by MonsterInsights