ESP8266 NodeMCU – Simple 7 Segment Display control

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:

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

Figure 1

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.

Figure 2

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.

Figure 3

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.


Figure 4

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.


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() {

//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);  

3 thoughts on “ESP8266 NodeMCU – Simple 7 Segment Display control

  1. 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!

  2. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.