2 Bit Adder Binary and Decimal Calculator

by 752695 in Circuits > Arduino

14 Views, 0 Favorites, 0 Comments

2 Bit Adder Binary and Decimal Calculator

finished project.jpg

This project is a binary to decimal calculator from numbers 0 to 6 with a buzzer that makes it beep on the number 4.

Supplies

tinker parts.png

Place Components

Step 1 eng.jpg

First places your main components on the bread board like your gates, LEDS, and dipswitches. To make it easier on yourself places the gates in this order AND, XOR and OR. this will make it easier for you to follow my wiring. Make sure all gates are connected to power and ground and 330Ω resistors are connected to the cathode of the red LEDS. You can place the power on the dip switch on the bottom or top of it either or work. Make sure to use four 1KΩ resistors to the dip switch

components used:

red LEDS - 3

AND chip - 1

XOR chip - 1

OR chip - 1

Dip switch - 1

slide switch - 1

1KΩ resistor - 4

330Ω resistor - 3


Begin Wiring

Step 2 eng.jpg

Then begin to attach the wires from the dip switches to the gate. We will be wiring a two bit adder here.

Finish Two Bit Adder Wiring

step 3 eng.jpg

Finish two bit adder wiring and bring out another breadboard to put the buzzer and 7 segment display on. Attach two 10KΩ resistors to the 7 segment display. Also attach a 1KΩ resistor to the positive side of the buzzer while connecting the negative to the ground rail. Make sure to connect both breadboards together by placing a positive and negative wire on each as show on the first picture

Components used:

7 segment display - 1

buzzer - 1

10KΩ resistor - 2

7 Segment Display Wiring

finished project.jpg

Connect the 7 segment to the Arduino and you should be ready for the software side.

Tinkercad Diagram and Schematic

Screenshot 2026-01-28 132408.png
Screenshot 2026-01-28 121259.png
Screenshot 2026-01-28 132951.png

This circuit calculates and displays the sum of the two 2-bit binary numbers using basic logic gates and an Arduino, acting as a binary to decimal adder calculator. The DIP switches A1, A0, and B1, B0 provide two distinct 2-bit binary inputs. Depending on whether the resistors are connected to ground or 5V, these inputs are either logic HIGH or LOW. The binary numbers 0 through 6 are represented by these four binary digits. copy wiring if breadboard wiring not clear enough.


chip explanation:

First the AND chip is used to check when both inputs are on at the same time. If both inputs are HIGH the output will turn on, which is how a carry is created in binary addition. If one input is off then the output stays off. The OR chip is used to combine signals, so if either input is HIGH the output will turn on. This is used to pass a carry forward if any carry condition happens. Together the AND and OR chips make sure the binary addition works correctly and gives the right output.


two bit adder use case:

First off, the 2 bit adder works by adding two binary numbers, each of which is composed of two bits. The first bit in each number is added together to get the sum, and if the first bit in both numbers is a 1, a carry is generated. Then, the carry is added to the second bit in each number. The circuit checks the numbers and determines when to turn on the sum and when to carry over. Finally, the correct binary number is produced, which is the equivalent of the sum in base ten.



All the Code(copy and Paste)

int a = 2;


int b = 3;


int c = 4;


int d = 5;


int e = 6;


int f = 7;


int g = 8;


int sum = 0;


int buzzer = 11;




void setup(){


pinMode(buzzer, OUTPUT);


Serial.begin(9600);

pinMode(a, OUTPUT);


pinMode(b, OUTPUT);


pinMode(c, OUTPUT);


pinMode(d, OUTPUT);


pinMode(e, OUTPUT);


pinMode(f, OUTPUT);


pinMode(g, OUTPUT);


}


void zero(){

digitalWrite(a,LOW);

digitalWrite(b,LOW);

digitalWrite(c,LOW);

digitalWrite(d,LOW);

digitalWrite(e,LOW);

digitalWrite(f,LOW);

digitalWrite(g,HIGH);

}

void one(){

digitalWrite(a,HIGH);

digitalWrite(b,LOW);

digitalWrite(c,LOW);

digitalWrite(d,HIGH);

digitalWrite(e,HIGH);

digitalWrite(f,HIGH);

digitalWrite(g,HIGH);

}

void two(){

digitalWrite(a,LOW);

digitalWrite(b,LOW);

digitalWrite(c,HIGH);

digitalWrite(d,LOW);

digitalWrite(e,LOW);

digitalWrite(f,HIGH);

digitalWrite(g,LOW);

}

void three(){

digitalWrite(a,LOW);

digitalWrite(b,LOW);

digitalWrite(c,LOW);

digitalWrite(d,LOW);

digitalWrite(e,HIGH);

digitalWrite(f,HIGH);

digitalWrite(g,LOW);

}

void four(){

digitalWrite(a,HIGH);

digitalWrite(b,LOW);

digitalWrite(c,LOW);

digitalWrite(d,HIGH);

digitalWrite(e,HIGH);

digitalWrite(f,LOW);

digitalWrite(g,LOW);

}

void five(){

digitalWrite(a,LOW);

digitalWrite(b,HIGH);

digitalWrite(c,LOW);

digitalWrite(d,LOW);

digitalWrite(e,HIGH);

digitalWrite(f,LOW);

digitalWrite(g,LOW);

}

void six(){

digitalWrite(a,LOW);

digitalWrite(b,HIGH);

digitalWrite(c,LOW);

digitalWrite(d,LOW);

digitalWrite(e,LOW);

digitalWrite(f,LOW);

digitalWrite(g,LOW);

}


void loop(){




sum = 0;




Serial.println(analogRead(A0));


Serial.println(analogRead(A1));


Serial.println(analogRead(A2));




if (analogRead(A0) > 0)


sum = sum + 1;


if (analogRead(A1) > 0)


sum = sum + 2;


if (analogRead(A2) > 0)


sum = sum + 4;




Serial.println(sum);


if (sum == 0) {


zero();


noTone(11);

delay(1000);


}


else if (sum == 1) {


one();


noTone(11);


delay(1000);


}


else if (sum == 2) {


two();


noTone(11);


delay(1000);


}


else if (sum == 3) {


three();


noTone(11);


delay(1000);


}


else if (sum == 4) {


four();


noTone(11);


delay(1000);


}


else if (sum == 5) {


five();


tone(11, 1000);

delay(1000);


}


else if (sum == 6) {


six();


noTone(11);


delay(1000);


}




}