4-bit Adder | OLED Display

by Kartik Gupta in Circuits > Arduino

40 Views, 1 Favorites, 0 Comments

4-bit Adder | OLED Display

IMG_8265.png

In this project, we build a 4-bit binary adder entirely from logic gates on a breadboard and then interface it with an Arduino Uno to display the result in decimal on an OLED screen.

Unlike most Arduino calculators that perform math in software, all addition is done in hardware using XOR, AND, and OR gates. The Arduino’s job is only to read the binary inputs and outputs and display the result clearly through an OLED display, just like a real calculator.

This project demonstrates:

  1. Digital logic design
  2. Binary-to-decimal conversion
  3. Hardware–software interfacing
  4. Practical debugging of floating inputs and carry bits


Supplies

image_2026-01-21_193834536.png

Core Components

  1. 1× Arduino Uno
  2. 2× Full-size breadboard
  3. 1× 0.96" OLED display (SSD1306, I2C)

Logic ICs (Adder)

To build 3 full adders and 1 half adder:

  1. 2× 74HC86 (Quad XOR gate)
  2. Each full adder needs 2 XOR
  3. 3 full adders = 6 XOR gates
  4. 1 half adder = 1 XOR Gate
  5. Each IC has 4 XOR → 2 chips
  6. 2× 74HC08 (Quad AND gate)
  7. Each full adder needs 2 AND
  8. 3 full adders = 6 AND gates
  9. I half adder = 1 AND GATE
  10. Each IC has 4 AND → 2 chips
  11. 1× 74HC32 (Quad OR gate)
  12. Each full adder needs 1 OR
  13. 3 full adders = 3 OR gates
  14. Each IC has 4 OR → 1 chip

Total logic ICs: 5

Switches (Inputs)

  1. 8× switches (DIP or slide)
  2. 4 for Number A
  3. 4 for Number B

Resistors

Pull-Down Resistors (VERY IMPORTANT)

  1. 8× 10kΩ resistors
  2. One for each input bit

Optional Debug LEDs

  1. 5× 330Ω resistors
  2. 5× LEDs
  3. (S0–S3 + Carry)

Wiring

  1. ~30–40 jumper wires
  2. Inputs → gates
  3. Gates → gates
  4. Outputs → Arduino
  5. Power & ground rails

Power

  1. 1× USB cable (Arduino → computer)

Theory - How a 4-bit Adder Works

image_2026-01-21_190523649.png

A 4-bit adder adds two binary numbers, each 4 bits long:

Half Adder

A half adder adds two bits with no carry-in.

  1. Sum = A ⊕ B
  2. Carry = A · B

Because the least significant bit (LSB) has no incoming carry, it only needs a half adder.

Full Adder

A full adder adds:

  1. Bit A
  2. Bit B
  3. Carry-in from the previous stage

Equations:

  1. Sum = A ⊕ B ⊕ Cin
  2. Carry = (A · B) + (Cin · (A ⊕ B))

Each full adder is built using:

  1. 2 XOR gates
  2. 2 AND gates
  3. 1 OR gate

Ripple-Carry Structure

A 4-bit adder is built using:

  1. 1 Half Adder (bit 0)
  2. 3 Full Adders (bits 1, 2, 3)

The carry “ripples” from the LSB to the MSB:

Half Adder → Full Adder → Full Adder → Full Adder

Build the 4-Bit Adder on a Breadboard

image_2026-01-21_190812638.png

2.1 Power the Breadboard

  1. Connect 5V from the Arduino to the breadboard power rail
  2. Connect GND from the Arduino to the ground rail
  3. Power all ICs from these rails

2.2 Build the Half Adder (Bit 0)

  1. Inputs: A0 and B0
  2. Use:
  3. 1 XOR gate → Sum S0
  4. 1 AND gate → Carry C1

Test:

  1. 0 + 0 → Sum 0, Carry 0
  2. 1 + 1 → Sum 0, Carry 1

2.3 Build the Full Adders (Bits 1–3)

Each full adder:

  1. XOR A and B
  2. XOR result with Carry-In → Sum
  3. AND A and B
  4. AND Carry-In and (A ⊕ B)
  5. OR the two AND results → Carry-Out

Repeat this for:

  1. Bit 1 → produces S1 and C2
  2. Bit 2 → produces S2 and C3
  3. Bit 3 → produces S3 and COUT

2.4 Verify the Hardware Adder

Before using the Arduino:

  1. Test combinations like:
  2. 3 + 5 = 8
  3. 7 + 7 = 14
  4. 8 + 8 = 16
  5. Use LEDs if needed to check outputs


Connect Inputs to Arduino (Number a and B)

image_2026-01-21_193359862.png

Each input bit is connected to a digital input pin.


Number A

Bit Arduino Pin

A0 - D2

A1 - D3

A2 - D4

A3 - D5

Number B

Bit Arduino Pin

B0 - D6

B1 - D7

B2 - D8

B3 - D9


Important:

Each input must use a 10kΩ pull-down resistor to prevent floating values.

Connect Adder Outputs to Arduino

Adder Output Arduino Pin

S0 - D10

S1 - D11

S2 - D12

S3 - D13

COUT - A5


These pins allow the Arduino to read the actual hardware result.

Connect the OLED Display

OLED uses I2C communication:


OLED Pin Arduino Pin

VCC - 5V

GND - GND

SDA - A4

SCL - A5


Install libraries:

Adafruit_GFX

Adafruit_SSD1306

Arduino Logic (What the Code Does)

The Arduino:

  1. Reads A and B input bits
  2. Converts them from binary to decimal
  3. Reads the sum from the hardware adder
  4. Displays results on the OLED
  5. Prints values to Serial Monitor (for debugging)

The Arduino does NOT perform addition.

Downloads

Displaying the Result

OLED format:

A + B
SUM

Example:

13 + 12
25

This mimics a real calculator using pure hardware math.

Common Mistakes, Limitations, and Debugging Notes

1. Floating Bits (Unexpected +8 or +16 in the Output)

One of the most common behaviors observed is an unexpected extra value of 8 or 16 appearing in the displayed sum.

Why this happens:

  1. The 4-bit adder itself performs addition correctly.
  2. The issue occurs after the addition, during Arduino input reading and display.
  3. This is caused by a floating input pin, typically the carry-out (COUT) line.
  4. In some configurations, the carry-out must be connected to A0, which is primarily an analog pin, not a true digital input.

Because analog pins can float when used as digital inputs, the Arduino may occasionally read:

  1. A false HIGH → resulting in +8 or +16 being displayed

Important clarification:

This is not an arithmetic error.

The hardware adder’s logic is still correct only the displayed value is affected.

2. Why This Is Not a Design Flaw

This behavior is an inevitable limitation when:

  1. Using a limited number of Arduino Uno pins
  2. Interfacing external logic hardware with a microcontroller
  3. Repurposing analog pins as digital inputs

With more I/O pins or dedicated buffering hardware, this could be eliminated. However, within the constraints of the Arduino Uno, this behavior is expected and manageable.

3. How the Issue Is Managed

In practice, the floating behavior:

  1. Appears infrequently
  2. Can often be resolved by:
  3. Resetting the Arduino
  4. Reseating jumper wires
  5. Allowing the inputs to stabilize for a moment

This is a practical engineering workaround, not a theoretical failure.

4. Other Common Mistakes

Floating Input Switches

  1. Missing pull-down resistors can cause random input values.
  2. Always use 10kΩ pull-down resistors on all input bits.

Carry Chain Errors

  1. Incorrect wiring between carry-out and carry-in causes incorrect results near 8 or 16.
  2. Double-check carry propagation between adders.

Pin Naming Conflicts

  1. Avoid using reserved Arduino names like A0, B0.
  2. Use custom names (a0Pin, b0Pin) to prevent compilation errors.


Final Result

IMG_8265.png

You now have:

  1. A pure logic-gate 4-bit adder
  2. Arduino used as a binary decoder
  3. OLED calculator-style display
  4. A professional digital systems project


Conclusion

This project combines digital logic theory with embedded systems, proving that real arithmetic can be done entirely in hardware and simply interpreted by a microcontroller.

This is a high-quality engineering build, not just an Arduino sketch.