Full Adder (1-bit)
Full Adder (1-bit) is a runnable microcontroller simulation example on SensBench — open the wired circuit, inspect the code, and compile real firmware in your browser, no install needed. Last updated Aug 14, 2026.
FREE SIMULATOR EXAMPLE · INTERMEDIATE
Full Adder (1-bit)
This example computes a 1-bit full adder on the Arduino Uno: three buttons are A, B and the carry-in, and the sketch prints the sum and carry-out for every combination. It is the exact arithmetic cell inside every CPU’s adder, reduced to buttons and LEDs.
| Board | Arduino Uno (ATmega328P) + logic / power circuit |
|---|---|
| Difficulty | intermediate |
| Category | circuits |
| Libraries | None — just the Arduino core |
| Runs in | Sensbench browser simulator — free, no account |

The exact circuit you get when you open this example — already wired, ready to run.
The sketch
// 1-bit full adder in software
void setup() {
Serial.begin(9600);
pinMode(2,INPUT_PULLUP); pinMode(3,INPUT_PULLUP); pinMode(4,INPUT_PULLUP);
pinMode(5,OUTPUT); pinMode(6,OUTPUT);
}
void loop() {
bool a=!digitalRead(2), b=!digitalRead(3), cin=!digitalRead(4);
bool sum = a ^ b ^ cin;
bool cout = (a&b) | (cin&(a^b));
digitalWrite(5, sum);
digitalWrite(6, cout);
Serial.print("A="); Serial.print(a); Serial.print(" B="); Serial.print(b);
Serial.print(" Cin="); Serial.print(cin); Serial.print(" Sum="); Serial.print(sum);
Serial.print(" Cout="); Serial.println(cout);
delay(300);
}
How it works
Three buttons on pins 2-4 supply A, B and Cin (inverted from the pull-up wiring), and the loop computes the sum with a ^ b ^ cin — XOR counts the odd number of HIGH inputs — and the carry with (a&b) | (cin&(a^b)). Pins 5 and 6 drive the sum and carry LEDs, and the serial line prints the full truth-table row.
The 300 ms polling turns the three buttons into a slow-motion truth table: press combinations and read the printed row. A=1, B=1, Cin=0 gives Sum=0, Cout=1 — the 1+1=10 moment where binary addition produces a carry, exactly like decimal 5+5=10 produces a tens digit.
Before you build it for real
The software XOR solution hides what hardware gates must handle: a physical full adder is built from many gates with propagation delays, and the carry output arrives later than the sum — the classic carry-propagation delay that limits every ripple-carry adder’s speed (the reason real CPUs use lookahead carry). The pull-up inversion applies to all three inputs: forget the ! on any one and that bit reads backwards in the truth table. And one full adder is just one bit position — chaining to a real byte-wide adder multiplies the delay, which is the step from this example to actual computer arithmetic.
Get the parts
Related examples
FAQ
Why three inputs for adding two bits?
Adding two bits can produce a carry — the third input (Cin) is the carry coming in from the previous bit position. The full adder sums A + B + Cin, producing a 1-bit sum and a carry out. Chain these cells together and you have a multi-bit binary adder — the exact structure inside every CPU’s arithmetic unit.
What does the Cout formula mean?
Cout = (A AND B) OR (Cin AND (A XOR B)) — a carry results if both A and B are set, or if one of them is set while a carry is coming in. The formula looks intimidating but is just the English sentence “at least two of the three inputs are on” written in boolean algebra.