No. 3 – Four digit seven segment display

Task: We want to show any number on the four digit seven segment display.

Required equipment: Arduino / cables / four digit seven segment display / 1K Ohm resistors

Sevseg

The display has 12 contacts on the back of it, six on the top and six on the bottom. Four of this contacts each belong to one of the digits. These four contacts can either be the type “Common Cathode” or “Common Anode”. Which type of display you have got, can be found out with the Code later on. The other eight contacts belong to the seven segments and the dot next to the digits.

The segments of displays with only one or two digits are individually controlled. Because four digits would mean fourth the cables and thus more mess with the wiring, these displays are working with “multiplexing”. This means if for example all four digits should be shown at once, they are actuated very fast one after another. This happens so fast, that to the human eye, it looks like all four digits are shown simultaneously.

Illustration of the four digit seven segment contacts:

Sevseg1

Setup:

Sevseg2

Programming:

In order to avoid a long and complicated code, we are going to need a library, which isn’t already installed in the arduino software. You can download this “SevenSeg” library from Dean Reading here: https://github.com/DeanIsMe/SevSeg .

It has to be added to the arduino software like the other libraries in previous tutorials. 

The easiest way to add it: Sketch > Include Library > Add .ZIP Library..

Code:


#include „SevSeg.h“ //Include the SevenSeg library

SevSeg sevseg; //Initialize a seven segment object

void setup() {

byte numDigits = 4; //Here we are defining how many digits our display has

byte digitPins[] = {2, 3, 4, 5}; //The digit pins are defined

byte segmentPins[] = {6, 7, 8, 9, 10, 11, 12, 13}; //The segment pins are //defined

sevseg.begin(COMMON_CATHODE, numDigits, digitPins, segmentPins); // In this line we can find out what kind //of display we have, or if you already know what kind of display you have, you can set it here. The //display only works if the right type is entered here. So just try both out (COMMON_CATHODE or //COMMON_ANDODE). If it is the wrong type all segments and digits light up at the same time

}

void loop() {

sevseg.setNumber(1234,3); //This is the part where you enter the number, you want to show on your display. //We used 1234 as an example. The number after the comma defines which dot should light up. The number 3 //means that the dot next to the first digit should light up. 0 after the comma would mean that the dot //next to the fourth digit should light up. If you want no dot to show, you can enter 4 after the comma.

sevseg.refreshDisplay(); // This part start the numbers on the displays

sevseg.setBrightness(90); //In this line you can define the brightness of your display. It is set with a //number from 0-100 in which 100 is the brightest possible. But 0 does not mean that the display is //complete dark. Only „sevseg.refreshDisplay();“ can control either there is something shown on the //display.

}


Now it should look like this:

SevSeg3

You can also try out some example codes from the sevseg library. You can find them here:
File > Examples > SevSeg-master