Modulo / Remainder in Arduino

ArduinoArduino BoardsArduino IDEArduino Programming Language

The modulo operator in Arduino is exactly the same as in C language, or most other languages for that matter. The operator is %. The syntax is: a % b and it returns the remainder when a is divided by b.


The following example illustrates the use of this operator −

void setup() {
   // put your setup code here, to run once:

void loop() {
   // put your main code here, to run repeatedly:


The Serial Monitor output is shown below. You can work out the remainders yourself and verify that the output is correct.

Updated on 31-May-2021 14:16:04