2 Bit Adder - Decimal Converter

by 716453 in Circuits > Arduino

22 Views, 1 Favorites, 0 Comments

2 Bit Adder - Decimal Converter

Untitled presentation.jpg

Hello, in this instructable I will take you through the creation of a 2-bit adder which with the help of code turns into binary output into a decimal output as well. This 2-bit adder is very easy to create and an overall very simple project but it gets the job done and meets all the criteria.

This project has been created to combine 2 different units from this semester, it takes 2 aspects of our Logic Gates unit through using IC Gates as well as converting binary to decimal, but then also takes aspects from the microcontroller unit through the use of code which is where the conversion between numbers actually takes place

Supplies

1x Arduino UNO

1x Large Solderless Breadboard

3x Logic Gates

○ 1x AND Chip

○ 1x XOR Chip

○ 1x OR Chip

3x LEDs

1x Dipswitch (4 inputs)

4x 10k Ohm Resistors

3x 330 Ohm Resistors


These are all the components that are needed to get started with building this 2-bit adder, if you need any of these components each one has been hyperlinked with a purchase link to buy the component for yourself. Obviously there are workarounds with using other components instead, but the 3 components which are 100% needed are the AND, XOR & OR IC Gates as these are what make a 2-bit adder what it is.

Understanding the 3 Gates

Screenshot 2024-06-18 014316.jpg

As I have mentioned already a 2-bit adder uses 3 specific gates to conduct its function.

These include an OR, AND, & XOR gate, all of which can be seen in the picture above.

To use each one of these IC Gates one must understand how exactly to wire each gate, luckily that is very simple as each gate is wired the exact same except for a NOT gate which is a gate that is basically inverted you could say but in this project, a NOT gate will not be used. In terms of now wiring these gates, each gate is equipped with 4 unique respective gates on each chip, meaning that one AND chip has 4 AND gates that can be used and the same goes for the others. To wire a gate one must first connect the chip to power, which is the top left pin as well as ground which is the bottom right pin but make sure the chip is the right way by reading the writing on the chip, ensuring that it is easily readable. After this, the chip is basically ready to go but diving into its basics let's look at how to exactly to use it. When using an IC Gate it can take a total of 2 inputs for each gate and spits out 1 output. Each pin has its own function which is why it is very important to look at the pin layout above to make sure that each input is going into the right spot and that you are getting your output from the correct area as well. When creating this 2-bit adder make sure to place the gates in such a way so that it is easy for you to work around them, this is different from person to person but you can make your decision based on the schematic coming up.

Creating the 2-Bit Adder

kHh5j.png
Copy of 2-Bit adder.png
download.jpg

Now comes the step of actually building the circuit.

Building this circuit is fairly straightforward as you are taking 4 different inputs that come from the dipswitch and just wiring them to different gates respectively. Obviously, based on your past experiences and overall skill level this can differ from person to person.

So how do you build this 2-bit adder, the first step would be to set up your breadboard the way that I did this can be seen in the Tinkercad screenshot above, where I placed my inputs (Dipswitch) on the far left, followed by my 3 IC Gates and then sandwiched by my outputs (Binary Code) of 3 LEDs. The placement of these LEDs does not matter as of yet but when wiring and connecting them to the IC Gates the order does matter as they have to be in the order of most significant to least significant but I will let you know about that as we get there. Once your breadboard is ready, you want to make the simple connection of power and ground to each of the components placed, this includes ground through the 330 Ohm resistors to the LEDs, pwr & gnd to the 3 gates, and power to the top of the dipswitch and ground through the 4 10k resistors on the bottom of the dipswitch. Once these simple connections have been made we can move on to the actual wiring of the 2-bit.

In a 2 bit there are obviously 2 different bits A (A0, A1) and B(B0, B1), The way I have these ordered in the dipswitch is A0, B0, A1, B1

Now to start off you first want to connect A0 and B0 as inputs of the XOR gate, after that you have one output that is already ready so you want to take the output from the XOR and connect it to the far right LED as this is the least significant digit. After that gate, you want to then use the same inputs of A0 and B0 but this time connect them to the inputs of an AND gate and for that output, we will get back to later. Before using the AND's output you want to take A1 and B1 and connect them to a different XOR gate and the output from this then goes back into another XOR gate and then again into a new AND gate. This is where the output from the AND gate comes back in as the output of the XOR combines in a new XOR with the output of the AND to create the second digit of the 2-bit adder, meaning that the output of this new and final XOR gate goes to the middle LED. From the same output of the AND gate which was fed to the XOR, that same output goes into another AND gate with the output from the XOR (The output that was fed back into itself). The output of these 2 finally ends up going to the OR gate. Before continuing into the OR gate there is one final AND gate left and this one contains inputs from A1 and B1 from which the output from these goes over to the OR gate, the same gate which is already being used. Now finally, we are at the OR gate with 2 inputs already there meaning we have 1 final output left, and this output is our carry value, making it the most significant digit meaning it is the leftmost LED. Now if these steps were followed a 2-bit adder should have been created but before we are done we have to connect the 3 outputs that are going to the LED to the Arduino as well as this is what will allow the creation of the decimal conversions, they can be connected to any pins but the ones which I had used were 2, 4 and 13.


With that you can check if your 2-bit adder is working correctly using the truth table above but other than that we have officially created a 2-bit adder.

Code

Once the 2-bit adder has been wired and the 3 outputs have been connected to the Arduino the only thing left to do is create the code. The code is very simple in this case as we are taking a binary number with 3 digits and just converting them into decimals and because it can only be a total of 3 binary numbers together the highest decimal you can get would be 7 but due to all LEDs never being on all together as seen by the truth table the highest decimal place would be 6. The original plan for the project was to connect an LCD screen to the Arduino as well and display both decimal and binary on that LCD. Due to the LCDs not being readily available for use, I had to work around this idea and instead used LEDs to show off the binary and printed the decimal on the serial monitor. All of this can be seen in the code below and an LCD screen can still easily be implemented if needed

Downloads