Skip to main content

Interfacing 7 Segment LED with Arduino Uno


In this blog, we will be discussing interfacing 7 Segment LED display with Arduino Uno.
Basically, 7 segments LED display is available in two types:
1. Common Anode Type
2. Common Cathode Type

In this blog, we will be discussing interfacing common cathode type, but will provide code for both the cases.


Also, 7 Segment LED can be interfaced in two ways...
1. Without BCD to Seven Segment Encoder IC
     (...It uses 7 digital pins of Arduino)
2. With BCD to Seven Segment Encoder IC
     (...It uses 4 digital pins of Arduino)

In this blog, we will be discussing interfacing seven-segment LED without any IC.

# Module Data Sheet:

Peak Current:                 70mA
Current Consumption:   300mA/Segment
Colors:                           Red, Blue, Yellow, Green, and White

# Pin-Out:



CC = 0V ... GND
[a,b,c,d,e,f,g,DP] = indiviual leds

# Arduino Connection:




# Working:



The working is simple. There are 8 individual LEDs in 7 Segment LED display. With the ON and OFF of these LEDs various no. (0 to 9) can be shown on the display.

As discussed earlier there are two types of 7 Segment LED display:
1. Common Cathode Type



In this type, a HIGH signal from Arduino to [a,b,...g] pins and a COMMON GROUND is provided to the display.

2. Common Anode Type



In this type, a LOW signal from Arduino to [a,b,...g] pins and a COMMON Vcc is provided to the display.

To get the appropriate pattern of LEDs to display a Decimal no. we need to create a truth table for the same.




When an intermediate IC is used, it directly converts input binary to the required output with the help of logic gates.
If no IC is used pattern has to be generated with the help of programming.


# Arduino Code:

const int ZERO = 0x7E;
const int ONE = 0x30;
const int TWO = 0x6D;
const int THREE = 0x79;
const int FOUR = 0x33;
const int FIVE = 0x5B;
const int SIX = 0x5F;
const int SEVEN = 0x70;
const int EIGHT = 0x7F;
const int NINE = 0x7B;

//pins initialization
int pin[] = {2,3,4,5,6,7,8};


void setup(){
  
  Serial.begin(9600);
  //setting all pins as Output pins
  
  for(int i=0;i<7;i++)
  {
    pinMode(pin[i],OUTPUT);
  }

}


void loop(){
  for(int i=0;i<=9;i++)
  {
    switch(i)
    {
    case 0:
      display_it(ZERO);
      break;

    case 1:
      display_it(ONE);
      break;

    case 2:
      display_it(TWO);
      break;

    case 3:
      display_it(THREE);
      break;

    case 4:
      display_it(FOUR);
      break;

    case 5:
      display_it(FIVE);
      break;

    case 6:
      display_it(SIX);
      break;

    case 7:
      display_it(SEVEN);
      break;

    case 8:
      display_it(EIGHT);
      break;

    case 9:
      display_it(NINE);
      break;

    default :
      Serial.println("something went wrong");

    }
  }
}


void display_it(const int value)
{
  for(int i=2,j=0;i<=8;i++,j++)
  {
    digitalWrite(i,bitRead(value,j)); 

  }
  delay(1000);
}

# Applications:

1. Display device for Counters and Timers 

To download the code click here

To view the circuit and simulation click here

Comments

Popular posts from this blog

Interfacing 4x4 Matrix Keypad with Arduino Uno

In this blog, we will be discussing interfacing 4x4 Matrix Keypad with Arduino Uno. Matrix keypad basically consists of push buttons.  At a particular instant, if we know which push button is pressed, we can say which character was given by the user. # Module Data Sheet: Working Current:   30mA Working Voltage:   5-24V # Pin-Out: X1, X2, X3, X4 are rows. Y1, Y2, Y3, Y4 are columns. # Arduino Connection: # Working: The working is simple.  We know that at a time only one key will be pressed. So we have to check which key is pressed at that given time. There are 4 rows and 4 columns. We will first make Row R1 high. Then check whether C1, C2, C3 or C4 is high or not. If not we will proceed to the next row. For example... Let's say we found C2 to be high when R3 was high. => The key (3,2) was pressed i.e. Key '8' was pressed. This process will keep on repeating very fast. # Arduino Code: #include <Keypad.h>

Theory of Arduino Wire Library

In this blog, we will be discussing the Wire Library. Wire Library is used for communication between two boards in the I2C Communication Protocol. In Arduino Uno, the Analog Pins A4 and A5 are used for this purpose. A4 = SDA ( Data Bus ) A5 = SCL ( Clock Bus ) The basic functions used in the Wire Library are as follows... begin() requestFrom() beginTransmission() endTransmission() write() available() read() SetClock() onRecieve() onRequest() Now lets start discussing about these functions... 1.Wire.begin() or Wire.begin(Slave_Address) Wire.begin() intializes I2C communication as an Master Device. Wire.begin(Address) initializes I2C communication as a Slave Device. The Address is of 7 bit and thus at max, we can connect 127 devices in this protocol. The Address is generally specified in the datasheet. The address up to 8 is reserved by the manufacturer and thus can't be used.  2. Wire.requestFrom(Slave_Address, No. of bytes,'TRUE'/'FALS