4 Bit Adder With the Output Displayed in Binary and Decimal on an LCD Display

by 711245 in Circuits > Arduino

163 Views, 0 Favorites, 0 Comments

4 Bit Adder With the Output Displayed in Binary and Decimal on an LCD Display

Screenshot 2024-01-25 153654.png
Screenshot 2024-01-25 152350.png

The project I made is a 4-bit adder with the output being converted from binary to decimal, and then both units being displayed on a 16x2 LCD. To briefly explain how it works, we can add 2 binary numbers each of 4 bits, hence the name 4-bit adder. Say you input 0110 + 1101, this means we want to add 13 to 6, and so the LCD would display the following:

Binary: 10011

Decimal: 19

0110 + 1101 is 10011 and 6 + 13 is 19. The max equation we can input is 1111 + 1111 which is 11110 in binary and 30 in decimal. A 4-bit adder utilizes 4 things, 1 half adder and 3 full adders. The way it works is simple, each full adder has a sum alongside a carry value, this is because when we add in binary, we only have 0s and 1s, and to not remove a value completely from the equation, we must carry it on to the next digit. Because of this, the carry value from each full adder moves on to the next until there are none left. When this happens, the last carry will be the 5th output. Each of the sums and carry will be connected to analog pins on an Arduino to be able to write code which works with the sums and carry to be converted and displayed accordingly on the LCD.


Supplies

Understand Logic Gates

Screenshot 2024-01-25 145142.png
Screenshot 2024-01-25 145204.png
Screenshot 2024-01-25 145225.png
Screenshot 2024-01-25 145254.png

Logic gates are quite simple to understand. The photo above shows the schematic of an XOR, AND, and OR chip. Each gate, except for the NOT gate which we will not be using, has 4 gates inside each chip. Each gate has 2 inputs and 1 output as seen above. Power is found at the top left-most pin and ground is found at the bottom right-most pin. If I say to connect one thing to an XOR, AND, or OR, you need to connect the wire to any of the gates, however, if I say to connect one thing to an XOR, AND, or Or and connect something else to the same XOR, AND, or OR, both wires should be going to the same gate. So both wires should be right next to each other. The output is found after the second input on each gate. If I say to connect the XOR, AND, or OR to something, you need to connect the output to the input of whatever is mentioned. Choose easy-to-reach gates as we will be using lots of wires, also colour coding the wires would be a wise choice for optimal readability since the breadboard can get hard to read at times. Common mistakes include connecting wires to outputs when meant to be connected to inputs. We will have breaking point checks throughout the project so if your project is not functional, you can easily go back and figure out where the mistake was made. Another mistake is connecting wires to power and ground when meant to be connected to input and output. Remember that the top left is power and the bottom right is ground.

Setting the Breadboard

Screenshot 2024-01-25 133118.png

The first step in creating this project is to set the breadboard to work with. Firstly, connect 2, 4-bit dipswitches next to each other, then connect each bit to power. Secondly, place 5 logic gate chips in this order, XOR, AND, XOR, AND, OR, each connecting the top left pin to power and the bottom right pin to ground for each chip. 4 on each dipswitch will be our A0 and B0, followed by 3 being A1, B1, 2 being A2 B2 and finally 1 being A3, B3.

Half Adder

unnamed.jpg
Screenshot 2024-01-25 134241.png

The second step in completing this project is to connect the half-adder. To do so, click on the schematic shown above. connect A0 and B0 to an XOR gate, the output of this will be our first sum (S0), then connect A0 and B0 to an AND gate, this will be our first carry which we will connect to the first full adder in the next step. I will be using this schematic and it was found on 738675's profile

1st Full Adder

unnamed.jpg
Screenshot 2024-01-25 134313.png

Following the last step, connect the previous carry, or the output of the AND gate, to an XOR. Then connect A1 and B1 to a different XOR, the output of this XOR will be the second input of the XOR to which we connected our carry. The output of this is our second sum (S1). Next, connect A1 and B1 to an AND. Then connect the output of our previous carry, or the AND gate again to a different AND, the second input of this AND will be the output of the first XOR we connected A1 and B1 to. Finally, connect the output of the AND we connected A1 and B1 to, to an OR, the second input of this OR will be the output of the AND we connected our previous carry and the output of the first XOR we connected A1 and B1 to, the output of this OR will be our second carry. This step can be hard to understand but it is crucial, so I encourage you to follow the schematic rather than my explanation for a more in-depth understanding.

Test 2 Bit Adder

FODUTC9LRT854VD.png

This is the first breaking point of the project. If you followed all the steps up to now, you should have made a 2-bit adder. Connect the 2 sums and the carry each to LEDS. The carry should be the leftmost digit, so the leftmost LED. S0 should be connected to the rightmost LED and S1 connected to the middle. We will have 3 outputs since this is a 2-bit adder. Connect power and ground and switch A0, B0 and A1, B1. If the LEDs light up appropriately, then you are safe to continue to the next step. If the LEDS are not working, try to remove the dipswitches and connect the inputs directly to ground and power. This will act as our 0s and 1s. Refer to the 2-bit adder truth table in the photo above.

Second Full Adder

Screenshot 2024-01-25 135639.png

The steps from now on will be quite repetitive so if you do not have a full understanding, I suggest going back and reviewing. Connect the previous carry to an XOR as we did with the last full Adder. Similarly, connect A2, and B2 each to an XOR and the output of this will be the second output of the first XOR, this will be our 3rd sum, (S2). Then connect A2 and B2 to an AND then connect the output of the AND to an OR. Connect the output of the previous OR, or the carry, to an AND, the second input of this will be the output of the XOR we connected A2 and B2 to. The output of this AND will be the second input of the OR we connected to before with the output of the AND from A2 and B2, the output of this OR is our new carry.

Third and Last Full Adder

Screenshot 2024-01-25 140333.png
unnamed.jpg

This is the last step of the 4-bit adder, it is the same as the previous step, however, the output of the OR will be our final carry. Connect the previous carry to an XOR as we did with the last full Adder. Similarly, connect A3, and B3 each to an XOR and the output of this will be the second output of the first XOR, this will be our 4th sum, (S3). Then connect A3 and B3 to an AND then connect the output of the AND to an OR. Connect the output of the previous OR, or the carry, to an AND, the second input of this will be the output of the XOR we connected A3 and B3 to. The output of this AND will be the second input of the OR we connected to before with the output of the AND from A2 and B2, the output of this OR is the final carry.

Test 4 Bit Adder

FSQU1XKLRT85643.png

This is the final breaking point of the project. If you followed all the steps up to now, you should have made a 4-bit adder. Connect the 4 sums and the carry each to LEDS. S0 should be connected to the rightmost LED, S1 connected to the 2nd LED, S2 connected to the 3rd LED, S3 connected to the 4th LED, and the carry connected to the 5th LED. We will have 5 outputs since this is now a 4-bit adder. Connect power and ground and play with the switches. If the LEDs light up appropriately, then you are safe to continue to the next step. Again, if the LEDS are not working, try to remove the dipswitches and connect the inputs directly to ground and power. This will act as our 0s and 1s. Refer to the 4-bit adder truth table above.

Connect Sums and Carry to Arduino

Screenshot 2024-01-25 153114.png

Now instead of connecting each sum and carry to LEDS, connect them to analog pins on the Arduino. The sums and pins I connected to are:

S0 - 3

S1 - 5

S2 - 6

S3 - 9

C - 10

Connect the LCD

Screenshot 2024-01-25 141236.png

We are almost done, simply connect the LCD to power and ground on the beadboard, then connect the SCL and SDA pins to the SCL and SDA pins on the Arduino. The two pins are the last two highest pins. SCL is the highest and SDA is right below that.

Code

The only thing left to do is write code to communicate with the LCD. I've attached a file which you can use. I encourage you to write your own and use this as a reference since it uses so many If statements. I've also attached an incomplete program which does not use many If statements, however, it does not function properly, I encourage you to fix the code and adjust it to any ideas you have. The functional and complete code was found on DN - 652671's profile.

For Future Features

The display can be fully customized to your liking. I recommend thinking of new ways or new ideas to be displayed. An idea I had but couldn't complete was to display the inputs as well. For example, if the input was 0110 + 1101, the LCD would display the following:

0110 + 1101 = 10011

6 + 13 = 19

This is only one idea and there are many more to be created so have fun with the creation.