It adds the two numbers and shows the answer.
Arduino
The brain
arithmetic expressions with variables
Add two int variables and print the sum on Serial.

Boxes that do math!
Two number boxes get added together, and the answer pops up on the screen.
Every calculator app keeps numbers in boxes before adding them up.
The problem
We want to change two numbers and see the answer update by itself.
Think of it like
It's like two jars of marbles — pour them together and count the total.
It adds the two numbers and shows the answer.
Arduino
The brain
Two number boxes
numberA and numberB hold the two numbers you want to add — change them in the Code lab.
int numberA = 12; int numberB = 8;
Add them together
sum is a third box that holds the answer of the adding.
sum = numberA + numberB;
Show the whole sum
Shows 12 + 8 = 20 on the screen, waits two seconds, then adds again.
Serial.print(numberA);
Serial.print(" + ");
Serial.println(sum);Then loop back to step 1
Follow these steps in order. Match the wires to the colors shown.
Place Arduino
Place the Arduino (uno) on the breadboard.
Arduino placed — ready to add!
The three boxes
int numberA = 12; int numberB = 8; int sum = 0;
numberA and numberB are the two numbers to add, and sum holds the answer.
Add them up
Serial.print(numberA);
Serial.print(" + ");
Serial.print(numberB);
Serial.print(" = ");
Serial.println(sum);
delay(2000);
}Each loop adds the two numbers and shows the whole sum on the screen.
int numberA = 12;
int numberB = 8;
int sum = 0;
void setup() {
Serial.begin(9600);
Serial.println("Simple Calculator — change A and B in Code lab");
}
void loop() {
sum = numberA + numberB;
Serial.print(numberA);
Serial.print(" + ");
Serial.print(numberB);
Serial.print(" = ");
Serial.println(sum);
delay(2000);
}
Q1. What is a variable?
Q2. Why use a sum box instead of just adding once?
Try different math — change int numberA = 12 to int numberA = 20.
Hint: Line 1.
Change the second number — set int numberB = 8 to int numberB = 15.
Hint: Line 2.
A line-by-line tour of the sketch — the same steps as in Robot Gurukul Studio.
Program overview
Big idea
Every Arduino program has a top part, a setup() part that runs once, and a loop() part that runs again and again.
In this project
We keep two numbers in boxes, add them, and show the answer on the screen.
Tip
Read from the top to the bottom. Tap any word or line if you need help!
int numberA = 12; int numberB = 8; int sum = 0;
setup()
Big idea
setup() runs one time when the board turns on.
In this project
It opens the message screen and says hello.
Why here
Things we do only once go inside setup().
void setup() {
Serial.begin(9600);
Serial.println("Simple Calculator — change A and B in Code lab");
}loop()
Big idea
loop() runs again and again, forever.
In this project
This is where the two numbers get added and the answer is shown.
Why here
Things that repeat go inside loop().
void loop() {
sum = numberA + numberB;
Serial.print(numberA);
Serial.print(" + ");
Serial.print(numberB);
Serial.print(" = ");
Serial.println(sum);
delay(2000);
}
Try this: Change a number inside loop(), then press Run to see what happens.
delay
Big idea
delay means wait. Nothing else happens while it waits.
In this project
It waits two seconds before showing the answer again.
Why here
Right after we show the answer.
delay(2000);
begin
Big idea
Serial.begin opens a message screen so the board can talk to the computer.
In this project
It lets us print the answer.
Why here
It goes in setup() once, before we print anything.
Serial.begin(9600);
Big idea
Serial.print writes words or a number on the screen and stays on the same line.
In this project
It writes the first number on the same line as the rest of the sum.
Why here
In loop() so the whole sum shows on one line.
Serial.print(numberA);
println
Big idea
Serial.println writes on the screen and then jumps to a new line.
In this project
It prints a friendly hello when the board turns on.
Why here
So each message gets its own line.
Serial.println("Simple Calculator — change A and B in Code lab");