Arduino, how to type in two values in serialmonitor than sum them?

hey guys,

I want to typ in for example Variable1: "4" *pressing enter right after*, then type in Variable2: "3" *Pressing enter right after*

Now i want Arduino to store these variable and then sum them: Variabl1 + Variable 2.


You could try something like this:

char incomingByte;

int addend1;

int addend2;

int check = 0;

void setup() {



void loop() {

if (Serial.available() > 0) {

incomingByte = Serial.read();

if (check == 0) {

Serial.println("addend 1");

addend1 = incomingByte-'0';

check = 1;

} else if (check == 1) {

Serial.println("addend 2");

addend2 = incomingByte-'0';

Serial.print("Answer: ");

Serial.println(addend1 + addend2);

check = 0;




This will only add one digit numbers together because when you type something into the serial monitor like the number 10 it will receive it as two different characters. To fix this you will have to tell it to receive all the characters then put it in addend1.

Have a look here http://www.arduino-hacks.com/converting-integer-to-character-vice-versa/.