arduino math functions

Last Updated on December 2, 2017

The arduino can do mathematic functions between two numbers , simple example and syntax of mathematic operations are shown.

arduino-math-new

We can perform addition (+),subtraction (-), multiplication (x), division (/) etc… without any special library and get result in serial monitor.

Arduino Code

 

void setup() {
  int a = 5;
  int b = 8;
  int result;
  float result_fl;
  
  Serial.begin(9600);
  
  Serial.print("Addition (a + b): ");
  result = a + b;
  Serial.println(result);
  
  Serial.print("Subtraction (a - 2): ");
  result = a - 2;
  Serial.println(result);
  
  Serial.print("Multiplication (a * b): ");
  result = a * b;
  Serial.println(result);
  
  Serial.print("Int Division (b / 4): ");
  result = b / 4;
  Serial.println(result);
  
  Serial.print("Float Division (b / a): ");
  result_fl = b / a;
  Serial.println(result_fl);
  
  Serial.print("Remainder (12 % 6): ");
  result = 12 % 6;
  Serial.println(result);
}

void loop() {
}

Reference:
Arduino Arithmetic

AVR math




Leave a Reply

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