How to Drive a 7 Segment Display with HCF4511

How to Drive a 7 Segment Display with HCF4511 © GPL3+

How to drive a seven segment display using only four pins.

  • 8,956 views
  • 0 comments
  • 8 respects

Components and supplies

About this project

1. What is a Seven Segment Display?

A seven-segment display (SSD), or seven-segment indicator, is a form of electronic display device for displaying decimal numerals that is an alternative to the more complex dot matrix displays.

Seven-segment displays are widely used in digital clocks, electronic meters, and other electronic devices for displaying numerical information.

In a simple LED package, typically all of the cathodes (negative terminals) or all of the anodes (positive terminals) of the segment LEDs are connected and brought out to a common pin; this is referred to as a "common cathode" or "common anode" device. Hence a 7 segment plus decimal point package will only require nine pins (though commercial products typically contain more pins and/or spaces where pins would go) in order to match standard IC sockets.

An SSD can be driven using Arduino pins for each LED or using an ad-hoc driver like the HCF4511. In this way you need only 4 Arduino pins instead of 8!

2. HCF4511

HCF4511B is a BCD to 7 segment decoder driver able to drive LEDs and other displays directly.

3. The First Example

As you can see in the datasheet of the HCF4511, in order to drive the display properly and view numbers from 0 to 9, it is necessary to give a specific binary sequence in the input ABCD, where A represents the LSB (Least Significant Bit) and D the MSB (Most Significant Bit).

This first example shows how to increment the numbers that you see on the display when a button (attached to pin A0) is pressed.

4. Schematic

The schematic used is taken from the datasheet and allows you to drive the display correctly. Arduino pins 2, 3, 4 and 5 are used as A, B, C and D input of the HCF4511. When the button is pressed, a counter is increased and subsequently converted in binary. This corresponds to an increment of the number shown on the display.

5. The Code

As you can see the code is very simple. Every time the button is pressed, the counter will be increased and the number's converted to binary!

/*
  Example of how to drive a seven segment display using HCF4511 or similar
 This sketch drive the display in order to show a number from 0 to 9 everytime a button connected to A0 is pressed.
author: Arturo Guadalupi 
 */
//Declaration of Arduino pins used as HCF4511 inputs
const int A=2;
const int B=3;
const int C=4;
const int D=5;
void setup() {
  pinMode(A0, INPUT);
  pinMode(A, OUTPUT); //LSB
  pinMode(B, OUTPUT);
  pinMode(C, OUTPUT);
  pinMode(D, OUTPUT); //MSB
}
int count = 0; //the variable used to show the number
void loop() {
  if (digitalRead(A0) == LOW) //if button is pressed
    {
    count++; 
    delay(200); //the delay prevent from button bouncing
    if (count == 10) //we want to count from 0 to 9!
      count = 0;
    to_BCD(); //convert to binary
    }
   
  if (count == 10)
    count = 0;
  
}
void to_BCD()
{
    if (count == 0) //write 0000
	{
      digitalWrite(A, LOW);
      digitalWrite(B, LOW);
      digitalWrite(C, LOW);
      digitalWrite(D, LOW);
    }
    
    if (count == 1) //write 0001
	{
      digitalWrite(A, HIGH);
      digitalWrite(B, LOW);
      digitalWrite(C, LOW);
      digitalWrite(D, LOW);
    }
    
    if (count == 2) //write 0010
	{
      digitalWrite(A, LOW);
      digitalWrite(B, HIGH);
      digitalWrite(C, LOW);
      digitalWrite(D, LOW);
    }
    
    if (count == 3) //write 0011
	{
      digitalWrite(A, HIGH);
      digitalWrite(B, HIGH);
      digitalWrite(C, LOW);
      digitalWrite(D, LOW);
    }
    
    if (count == 4) //write 0100
	{
      digitalWrite(A, LOW);
      digitalWrite(B, LOW);
      digitalWrite(C, HIGH);
      digitalWrite(D, LOW);
    }
    
    if (count == 5) //write 0101
	{
      digitalWrite(A, HIGH);
      digitalWrite(B, LOW);
      digitalWrite(C, HIGH);
      digitalWrite(D, LOW);
    }
    
    if (count == 6) //write 0110
	{
      digitalWrite(A, LOW);
      digitalWrite(B, HIGH);
      digitalWrite(C, HIGH);
      digitalWrite(D, LOW);
    }
    
    if (count == 7) //write 0111
	{
      digitalWrite(A, HIGH);
      digitalWrite(B, HIGH);
      digitalWrite(C, HIGH);
      digitalWrite(D, LOW);
    }
    
    if (count == 8) //write 1000
	{
      digitalWrite(A, LOW);
      digitalWrite(B, LOW);
      digitalWrite(C, LOW);
      digitalWrite(D, HIGH);
    }
    
    if (count == 9) //write 1001
	{
      digitalWrite(A, HIGH);
      digitalWrite(B, LOW);
      digitalWrite(C, LOW);
      digitalWrite(D, HIGH);
    } 
}

Code

Code snippet #1Arduino
/*
  Example of how to drive a seven segment display using HCF4511 or similar

 This sketch drive the display in order to show a number from 0 to 9 everytime a button connected to A0 is pressed.
 
*/

//Declaration of Arduino pins used as HCF4511 inputs
const int A=2;
const int B=3;
const int C=4;
const int D=5;

void setup() {
  pinMode(A0, INPUT);
  pinMode(A, OUTPUT); //LSB
  pinMode(B, OUTPUT);
  pinMode(C, OUTPUT);
  pinMode(D, OUTPUT); //MSB

}

int count = 0; //the variable used to show the number

void loop() {
  if (digitalRead(A0) == LOW) //if button is pressed
    {
    count++; 
    delay(200); //the delay prevent from button bouncing
    if (count == 10) //we want to count from 0 to 9!
      count = 0;
    to_BCD(); //convert to binary
    }
   
  if (count == 10)
    count = 0;
  
}

void to_BCD()
{
    if (count == 0) //write 0000
	{
      digitalWrite(A, LOW);
      digitalWrite(B, LOW);
      digitalWrite(C, LOW);
      digitalWrite(D, LOW);
    }
    
    if (count == 1) //write 0001
	{
      digitalWrite(A, HIGH);
      digitalWrite(B, LOW);
      digitalWrite(C, LOW);
      digitalWrite(D, LOW);
    }
    
    if (count == 2) //write 0010
	{
      digitalWrite(A, LOW);
      digitalWrite(B, HIGH);
      digitalWrite(C, LOW);
      digitalWrite(D, LOW);
    }
    
    if (count == 3) //write 0011
	{
      digitalWrite(A, HIGH);
      digitalWrite(B, HIGH);
      digitalWrite(C, LOW);
      digitalWrite(D, LOW);
    }
    
    if (count == 4) //write 0100
	{
      digitalWrite(A, LOW);
      digitalWrite(B, LOW);
      digitalWrite(C, HIGH);
      digitalWrite(D, LOW);
    }
    
    if (count == 5) //write 0101
	{
      digitalWrite(A, HIGH);
      digitalWrite(B, LOW);
      digitalWrite(C, HIGH);
      digitalWrite(D, LOW);
    }
    
    if (count == 6) //write 0110
	{
      digitalWrite(A, LOW);
      digitalWrite(B, HIGH);
      digitalWrite(C, HIGH);
      digitalWrite(D, LOW);
    }
    
    if (count == 7) //write 0111
	{
      digitalWrite(A, HIGH);
      digitalWrite(B, HIGH);
      digitalWrite(C, HIGH);
      digitalWrite(D, LOW);
    }
    
    if (count == 8) //write 1000
	{
      digitalWrite(A, LOW);
      digitalWrite(B, LOW);
      digitalWrite(C, LOW);
      digitalWrite(D, HIGH);
    }
    
    if (count == 9) //write 1001
	{
      digitalWrite(A, HIGH);
      digitalWrite(B, LOW);
      digitalWrite(C, LOW);
      digitalWrite(D, HIGH);
    } 
}

Comments

Similar projects you might like

Arduino Bluetooth Basic Tutorial

by Mayoogh Girish

  • 454,628 views
  • 42 comments
  • 236 respects

Home Automation Using Raspberry Pi 2 And Windows 10 IoT

Project tutorial by Anurag S. Vasanwala

  • 285,487 views
  • 95 comments
  • 671 respects

Security Access Using RFID Reader

by Aritro Mukherjee

  • 229,393 views
  • 38 comments
  • 236 respects

OpenCat

Project in progress by Team Petoi

  • 195,888 views
  • 154 comments
  • 1,360 respects
Add projectSign up / Login