In this tutorial, we will learn how to control a 7 Segment Display. If you want to control the letter or number in the display, just have to use this tutorial.
Parts Required
To build the global setup you must have the following parts:
- ESP8266 NodeMCU v1.0;
- Micro-USB to USB cable;
- 7 Segment Display;
- 2x 10k ohm rasistor;
- Male to male jumper wires;
- 1 Breadboard;
Note: You do not need to have a NodeMCU board nor an ESP8266 to follow this tutorial. I am using this board because it is very famous and also because I will post future tutorials using wifi communications. In order to use other boards, you just have to change the pin number.
7 Segment Display

Seven segment displays are mostly used to display decimal numbers (0…9) in electronic displays. These displays use light-emitting diodes (LEDs) for each of the 7 segments. Therefore it is possible to display decimal numbers if the right segments are turned on. Figure 2 shows the pinout of a common 7 segment display to get a better understanding of how it works.

The different segments are connected with the corresponding pins on the edge or backside of the display. The 2 middle pins are the common pins and connected to a common cathode or common anode. This depends on the kind of 7 segment display you have. In most cases, you will have a common cathode display so that an LED turns on when the signal to the LED is HIGH and to common is connected to the ground. If you have an anode segment display the LED turns on when the signal is LOW.
Note that your display might have a dot point on the right side so that in total you have 10 pins to connect to your microcontroller.
It is very good to have a table, like figure 3, to know what pin to use to display a number.

For example, whenever you want to display the number 7, you must turn on the pins A, B and C. Do the same for the other numbers and letters.
Circuit

Follow figure 4 and connect the 7 Segment Display to the NodeMCU pins and GND pin (Black Wire) to common pin in series with a resistor, 1K ohm for example. Everything will be powered from your PC using micro-USB to USB cable. In this configuration, the LEDs in the display will be powered directly from the GPIO pin with 3.3V. It is low voltage level but it works. Let’s try it.
Coding
This example use a simple function, that when called turn os specific LEDs to make a number. We can use a library that already has some code done to make letters and numbers appear, but now we are making it pin by pin. This code just makes the numbers 2, 5 and 7, but you can continue making more numbers. Copy the main sketch below to your Arduino IDE project and save it. Have fun!!
// Tutorial on 7 Segement Display
const char A = 15;
const char B = 13;
const char C = 12;
const char D = 2;
const char E = 0;
const char F = 5;
const char G = 4;
const char DP = 14;
void setup() {
pinMode(A, OUTPUT); //Segment a
pinMode(B, OUTPUT); //Segment b
pinMode(C, OUTPUT); //Segment c
pinMode(D, OUTPUT); //Segment d
pinMode(E, OUTPUT); //Segment e
pinMode(F, OUTPUT); //Segment f
pinMode(G, OUTPUT); //Segment g
pinMode(DP, OUTPUT); //Dott point
}
void loop() {
two();
delay(1000);
five();
delay(1000);
seven();
delay(1000);
}
//Make the number seven
void seven(){
digitalWrite(A, HIGH);
digitalWrite(B, HIGH);
digitalWrite(C, HIGH);
digitalWrite(D, LOW);
digitalWrite(E, LOW);
digitalWrite(F, LOW);
digitalWrite(G, LOW);
digitalWrite(DP, LOW);
}
//Make the number tow
void two(){
digitalWrite(A, LOW);
digitalWrite(B, LOW);
digitalWrite(C, HIGH);
digitalWrite(D, LOW);
digitalWrite(E, LOW);
digitalWrite(F, HIGH);
digitalWrite(G, LOW);
digitalWrite(DP, HIGH);
}
//Make the number five
void five(){
digitalWrite(A, LOW);
digitalWrite(B, HIGH);
digitalWrite(C, LOW);
digitalWrite(D, LOW);
digitalWrite(E, HIGH);
digitalWrite(F, LOW);
digitalWrite(G, LOW);
digitalWrite(DP, HIGH);
}
You really make it appear really easy along with your presentation however I in finding this topic to be really one thing which I believe I
would never understand. It sort of feels too complicated and extremely broad for
me. I’m having a look forward to your next put up, I will attempt to get the grasp of it!
What’s up to every one, the contents present at this website are
genuinely amazing for people experience, well, keep up the nice work fellows.
What’s Taking place i am new to this, I stumbled upon this I have found
It absolutely helpful and it has aided me out loads.
I hope to give a contribution & assist other users like
its aided me. Great job.
We are a group of volunteers and opening a new
scheme in our community. Your site provided us with valuable info to work on. You’ve done an impressive job and
our whole community will be thankful to you.