Showing 4 Bit Binary Addition Through a 7 Segment Display

Introduction: Showing 4 Bit Binary Addition Through a 7 Segment Display

This project takes a four-bit adder which is normally displayed in binary through the usage of leds and instead uses the 7447 seven segment decoder and Arduino to compliment each other in their translation of the output of the binary adder into being displayed in base ten on seven-segment displays. This project is engaging in the sense that you create a 4 bit adder calculator whose results can easily be observed, alongside being expanded on to include 4 bit adder subtractor calculations.

Supplies

All of these materials can be found on Tinkercad, however if you wanted to physically construct the project this would be the cost of the components:

Step 1: Understanding the Theory: Binary Addition

From our maths lessons at school, we learned that each number column is added together starting from the right-hand side and that each digit has a weighted value depending upon its position within the columns.

When each column is added together a carry is generated if the result is greater or equal to 10, the base number. This carry is then added to the result of the addition of the next column to the left and so on, simple school math’s addition, add the numbers, and carry. The adding of binary numbers is exactly the same idea as that for adding together decimal numbers but this time a carry is only generated when the result in any column is greater or equal to “2”, the base number of binary. In other words 1 + 1 creates a carry. Binary Addition follows these same basic rules as for the denary addition above except in binary there are only two digits with the largest digit being “1”. So when adding binary numbers, a carry out is generated when the “SUM” equals or is greater than two (1+1) and this becomes a “CARRY” bit for any subsequent addition being passed over to the next column for addition and so on.

When two single bits are added together, the addition of “0 + 0”, “0 + 1” and “1 + 0” results in either a “0” or a “1” until you get to the final column of “1 + 1” then the sum is equal to “2”. But the number two does not exist in binary however, 2 in binary is equal to 10, in other words, a zero for the sum plus an extra carry bit.
Then the operation of a simple adder requires two data inputs producing two outputs, the Sum (S) of the equation and a Carry (C) bit as shown. The output of binary addition can be represented by combining an XOR and AND gate.

The full adder is a logical circuit that performs an addition operation on three binary digits and just like the half adder, it also generates a carry out to the next addition column. Then a Carry-in is a possible carry from a less significant digit, while a Carry-out represents a carry to a more significant digit. In many ways, as shown by the featured truth table, the full adder can be thought of as two half adders connected together, with the first half adder passing its carry to the second half adder as shown.

We have seen above that single 1-bit binary adders can be constructed from basic logic gates. But what if we wanted to add together two n-bit numbers, then n number of 1-bit full adders need to be connected or “cascaded” together to produce what is known as a Ripple Carry Adder.


A “ripple carry adder” is simply “n“, 1-bit full adders cascaded together with each full adder representing a single weighted column in a long binary addition. It is called a ripple carry adder because the carry signals produce a “ripple” effect through the binary adder from right to left, (LSB to MSB). For example, suppose we want to “add” together two 4-bit numbers, the two outputs of the first full adder will provide the first place digit sum (S) of the addition plus a carry-out bit that acts as the carry-in digit of the next binary adder. The second binary adder in the chain also produces a summed output (the 2nd bit) plus another carry-out bit and we can keep adding more full adders to the combination to add larger numbers, linking the carry bit output from the first full binary adder to the next full adder, and so forth. An example of a 4-bit adder is featured above, and also resembles the project I made.

Step 2: Assembling the 4 Bit Adder

Now that you understand the theory, it's time to assemble a 4-bit adder. Before you begin building the 4-bit adder it is important that you plan out the entire layout of all your wiring, due to the limited space provided by one breadboard. In my project, I've avoided this problem by utilizing 3 breadboards in Tinkercad to maintain neatness. Once you have planned out your build it is highly recommended you build your adder bit by bit and test out the result after the completion of each bit. This largely due to troubleshooting and to make it easier to catch possible issues that can occur when building a 4-bit adder in one go. Testing can be done with LEDs. Looking at the diagram above when building, note that the project showcases a 4 bit ripple carry adder as discussed above. That is, we are cascading the carry-out bits into other 1 bit adders to fulfill our calculation. As long as you completely understand binary addition and the truth table of the basic full adder, making the 4 bit adder will be natural. If you are physically making the project, be wary about the dip switches requiring resistance to work properly and to ensure the state of the switch is properly controlled and correctly outputs ground or power when the switch is flipped.

Step 3: Understanding the CD4511 IC and 7 Segment Display

Before starting off with the physical construction of the project, I encourage you to research about the two fundamental components we will use (the CD4511 chip and the Seven Segment LED Displays) to establish a comfortable amount of theoretical knowledge.

That being said, I'll preface this paragraph by explaining the CD4511 chip. The CD4511 chip is essentially a BCD to 7-Segment decoder/driver IC, with which you can convert a binary number into a decimal number on the 7-segment display. For example, printing the number “2” on a 7-segment display will require giving 0010 to the input pins (A,B,C,D) of the CD4511 chip. We can see the A, B, C, D pins on the example diagram above. We can also imprint the numbers 0-9 on a single 7-segment display. Displaying a decimal number without the usage of this chipset will require 3 more pins from the Arduino, and the circuit will become more clustered, therefore it is beneficial to use these pins. Delving into the specifications of the other pins, pin 3 is the lamp test pin. This pin is active LOW. When HIGH, the lamp test is activated. This makes all the outputs HIGH, so if LEDs are attached to all of the outputs, all of the LEDs will turn on if this pin is HIGH. When LOW, this feature is not activated. It's simply to test all the outputs to check if they turn on. Pin 4 is the Blanking pin. This pin is active LOW. When LOW, all the outputs go LOW, so they'll all shut off, like a reset pin. When HIGH, this feature is not activated. Pin 5 is Latch Enable/STROBE and it has dual purposes depending on whether it's HIGH or LOW. When LOW, the pin is in strobe mode, meaning it strobes the output to a given device, which in this case is a 7 segment LED display. This mode is the mode we usually want it in for display purposes. So in normal operation, it's held LOW. When HIGH, it is store mode. So it simply stores latches or stores the data without transferring to a device. The other pins of the CD4511 chip will be directly connected to the 7 segment display. This concludes my explanation of the CD4511 chipset, I'll now move on to the 7 Segment LED Display.

A seven-segment display (SSD) is a widely used electronic display device for displaying decimal numbers from 0 to 9. They are most commonly used in electronic devices like digital clocks, timers, and calculators to display numeric information. As its name indicates, it is made of seven different illuminating segments arranged so that it can form the numbers from 0-9 by displaying different combinations of segments. Each of these segments can be referred to as the letters from A-G for simplification purposes. There are two types of 7 Segment LED Display's and the one we're interested in is the Common Cathode. In this, all the negative terminals (cathode) of all the 8 LEDs are connected together, named COM. And all the positive terminals are left alone. This makes wiring significantly easier as all that you are required to do is to use one of the 1000 Ohms resistors and connect one leg to the common terminal of each 7 Segment LED Display, and the other one on the ground. This will provide the functionality to all of the segments. If we were using the Common Anode version, we would need to use the resistors to power each of the segments, which is a painstaking process. The A-G pins on the display will be connected to the A-G pins of the CD4511 chip.

Step 4: Programming the Arduino

//Output Pins
//7447 Seven Segment Display Decoder-Twos Digit
int a1 = 8; 
int a2 = 11;
int a3 = 10;
int a4 = 9;
//7447 Seven Segment Display Decoder-Ones Digit
int b1 = 3;
int b2 = 6;
int b3 = 5;
int b4 = 4;

float voltage1, voltage2, voltage3, voltage4, voltage5;
int led1, led2, led3, led4, led5, baseten;
void setup()
{
//Setup
  Serial.begin(9600);
  pinMode(a1,OUTPUT); 
  pinMode(a2,OUTPUT); 
  pinMode(a3,OUTPUT); 
  pinMode(a4,OUTPUT); 
  pinMode(b1,OUTPUT); 
  pinMode(b2,OUTPUT); 
  pinMode(b3,OUTPUT); 
  pinMode(b4,OUTPUT); 
}

void loop() 
{
 //reads output 1 though 5
 led1 = analogRead(A1);
 led2 = analogRead(A2);
 led3 = analogRead(A3);
 led4 = analogRead(A4);
 led5 = analogRead(A5);
 
 //changing values to voltage
 voltage1 = led1 * (5.0/1023.0);
 voltage2 = led2 * (5.0/1023.0);
 voltage3 = led3 * (5.0/1023.0);
 voltage4 = led4 * (5.0/1023.0);
 voltage5 = led5 * (5.0/1023.0);
 baseten = 0; 
 //Uses the voltage level of the output of the four bit adder to deterimal the decimal value being outputed
 if (voltage1 > 0)
     baseten += 1;
 if (voltage2 > 0)
    baseten += 2;
 if (voltage3 > 0)
    baseten += 4;
 if (voltage4 > 0)
    baseten += 8;
 if (voltage5 > 0)
    baseten += 16;
  
//Outputs the decimal value for tenths place on the seven segment display
  if (baseten < 10)
  {
    digitalWrite(a1,LOW);
    digitalWrite(a2,LOW);
    digitalWrite(a3,LOW);
    digitalWrite(a4,LOW);
  }
  else if (baseten < 20)
  {
    digitalWrite(a1,HIGH);
    digitalWrite(a2,LOW);
    digitalWrite(a3,LOW);
    digitalWrite(a4,LOW);
    baseten = baseten - 10;
  }
  else if(baseten < 30)
  {
    digitalWrite(a1,LOW);
    digitalWrite(a2,HIGH);
    digitalWrite(a3,LOW);
    digitalWrite(a4,LOW);
    baseten = baseten - 20;
  }
  else if(baseten < 40)
  {
    digitalWrite(a1,HIGH);
    digitalWrite(a2,HIGH);
    digitalWrite(a3,LOW);
    digitalWrite(a4,LOW);
    baseten = baseten - 30;
  }
//Outputs the decimal value for ones place on the seven segment display

  if (baseten < 1)
  {
    digitalWrite(b1,LOW);
    digitalWrite(b2,LOW);
    digitalWrite(b3,LOW);
    digitalWrite(b4,LOW);
  }
  else if (baseten < 2)
  {
    digitalWrite(b1,HIGH);
    digitalWrite(b2,LOW);
    digitalWrite(b3,LOW);
    digitalWrite(b4,LOW);
  }
  else if (baseten < 3)
  {
    digitalWrite(b1,LOW);
    digitalWrite(b2,HIGH);
    digitalWrite(b3,LOW);
    digitalWrite(b4,LOW);
  }
  else if (baseten < 4)
  {
    digitalWrite(b1,HIGH);
    digitalWrite(b2,HIGH);
    digitalWrite(b3,LOW);
    digitalWrite(b4,LOW);
  }
  else if (baseten < 5)
  {
    digitalWrite(b1,LOW);
    digitalWrite(b2,LOW);
    digitalWrite(b3,HIGH);
    digitalWrite(b4,LOW);
  }
   else if (baseten < 6)
  {
    digitalWrite(b1,HIGH);
    digitalWrite(b2,LOW);
    digitalWrite(b3,HIGH);
    digitalWrite(b4,LOW);
  }
  else if (baseten < 7)
  {
    digitalWrite(b1,LOW);
    digitalWrite(b2,HIGH);
    digitalWrite(b3,HIGH);
    digitalWrite(b4,LOW);
  }
  else if (baseten < 8)
  {
    digitalWrite(b1,HIGH);
    digitalWrite(b2,HIGH);
    digitalWrite(b3,HIGH);
    digitalWrite(b4,LOW);
  }
  else if (baseten < 9)
  {
    digitalWrite(b1,LOW);
    digitalWrite(b2,LOW);
    digitalWrite(b3,LOW);
    digitalWrite(b4,HIGH);
  }
  else if (baseten < 10)
  {
    digitalWrite(b1,HIGH);
    digitalWrite(b2,LOW);
    digitalWrite(b3,LOW);
    digitalWrite(b4,HIGH);
  }
  delay(30);
}

Shown above is the code for the program (note: using different pins for your project will result in slightly different code). The project utilizes the different voltage levels from the A1-->A5 pins as the inputs are switched to create a system to calculate the decimal value of the number. Once you have created the baseten and you have set it to 0, a series of if statements will be used to increment this value. The condition of these if statements will be your "voltage" variables having a value greater than 0. So because "voltage1" represents the 1s column for our binary output we would increment our "baseten" variable by 1 if we read a voltage of greater than 0. This train of thought continues for the rest of the values. Each 7 segment display is controlled by a distinct group of output pins that correspond to either a one-digit or a tens digit. The outputs are digitally written high or low based on the baseten value, and that is based on the voltage of the A1 --> A5 pins.

Step 5: Completed!

If you executed the steps properly, then you should have composed a 4 bit adder calculator whose results show up accurately on your 7 segment displays. This project does have its complexities despite it being elementary, make sure you understand the nuances of the 7 segment decoder chip and microcontroller/digital logic to be successful for this project.

Be the First to Share

    Recommendations

    • Audio Challenge

      Audio Challenge
    • Made with Math Contest

      Made with Math Contest
    • Reclaimed Materials Contest

      Reclaimed Materials Contest

    Comments