7 Segment display (with Arduino)

 7 Segment display (With Arduino)

Introduction

The 7-segment display is used a lot by companies and hobbyists  alike. It Is used in everyday items such as calculators, digital clocks,  and microwave ovens. This project will give you a short history of  the 7-segment display, teach you how to wire it up with an Arduino,  and also code it using the Arduino IDE.

Quick history of the 7-seg display

The 7-Segment display is one of the oldest displays that are still relevant today. It was invented back in 1903  by a Carl Kinsley. They were used to show telephone operators the number dialed in 1910. They only started to get used in every day items in the 1970, before this some most of the 7-segment displays used a filaments that illuminated when heated up. This lead to the invention of the New Alphabet which the limited range of characters available in the 7-segment display.

List of items needed

  • 1x Arduino Uno
  • 1x 7-Segment display
  • 1x breadboard
  • 8x 220ohm resistors
  • 12x jumper wires


Steps

  1. Wire up the 7-Segment display pins to the Arduino in the following order:
    • A to pin 8
    • B to pin 9
    • C to pin 3
    • D to pin 5
    • E to pin 4
    • F to pin 7
    • G to pin 6
    • DP to pin 2
    • COM to GND
(NOTE: You need to put a 220ohm resistor between all of the segments, the led will get damaged if you do not do this. to calculate the resistor value needed see Ohm's law.)

2. After wiring up the circuit you can start coding the pins to turn on the different segments of the display. To turn on this segments  individually you it can be coded just like a normal 2 pin LED, but with some extra steps we can simplify the process to to display numbers without the use of a extra library's. 

Code
// a= pin8; b= pin9; c= pin3; d= pin5; e= pin4; f= pin7; g= pin6; DP= pin2;
//array to save numbers
// can change depending on how it is wired up
int number_array[10][7] = {
  //in arry format segments will turn on as follow
  //{b, c, e, d, g, f, a}
  {1, 1, 1, 1, 0, 1, 1},//0
  {1, 1, 0, 0, 0, 0, 0},//1
  {1, 0, 1, 1, 1, 0, 1},//2
  {1, 1, 0, 1, 1, 0, 1},//3
  {1, 1, 0, 0, 1, 1, 0},//4
  {0, 1, 0, 1, 1, 1, 1},//5
  {0, 1, 1, 1, 1, 1, 1},//6
  {1, 1, 0, 0, 0, 0, 1},//7
  {1, 1, 1, 1, 1, 1, 1},//8
  {1, 1, 0, 0, 1, 1, 1},//9
};

void setup() {
  // put your setup code here, to run once:
 pinMode(2, OUTPUT);//DP
 pinMode(3, OUTPUT);//c
 pinMode(4, OUTPUT);//e
 pinMode(5, OUTPUT);//d
 pinMode(6, OUTPUT);//g
 pinMode(7, OUTPUT);//f
 pinMode(8, OUTPUT);//a
 pinMode(9, OUTPUT);//b

}

void loop() {
  // put your main code here, to run repeatedly:
  // the for loop only cycles thru 0 to 9
  for (int j = 0; j < 10; j++){
    //j can be changed for a value between 0 and 10 to choose the number you whant to display
    number_write(j);//This is the number you will display
    delay(1000);
  }
}

  void number_write(int num){
    //this part cycles thru the a row of the array and turns on all segment that are 1 and turns off all segments that are 0.
    int pin = 2;
    for (int i=0; i < 7 ; i++){
      digitalWrite(pin, number_array[num][i]);
      pin++;
    }
    digitalWrite(pin, number_array[num][0]);//Use if the b led is not turning on, else remove
  }

3. int number_array[10][7] = {
Figure 2.2
This line creates an array with 10 rows to store the numbers from 0 to 9 and 7 columns that store the the state of the 7 segments of the display it will be 1 if the segment is on and 0 if it is off. The order of the ones and zeros in the rows may change depending on the order you have wired up the segments and Arduino pins, the order used in the example is for the above mentioned connections.

4. pinMode(2, OUTPUT);
This tells the Arduino that the specific pin mentioned is an output pin and it cannot receive data it can only send data. (The order of the statement is as follow: pinMode(pin_number, OUTPUT ); This statement is case sensitive.)

5. void number_write(int num){
Void is a function used to simplify the main code, but in this case the void we created is to display the number that we selected. First you create a variable and set it equal to the lowest pin used, in our case pin number 2 (int pin = 2;). Then  you create a for loop that runs from the value 0 to 7 to read thru the number row you have selected and turns on all the 1's and turns off all the 0's.

6. void loop();
Lastly you can display your numbers with number_write(number here) with one 7-Segment display, you can display any number from 0 to 9 and also with some additional coding you can also display alphabet letters from A to Z.

Now that you have all of the information I would recommend that you try this project yourself, after you have successfully completed this, maybe try and figure out and code the display to show the Alphabet. I will leave some useful links below if you would like to download or copy my code.


USEFUL LINKS
  1. github - https://github.com/ITTechne/7-Segment-display-Arduino-
  2. Items used Amazon links (Non affiliate links)
    1. Arduino Uno
    2. 7 Segment display
    3. Breadboard
    4. 220ohm Resistor
    5. Jumper wires
    

Comments

Popular Posts