ESP8266 - 10 Segment LED Bar Graph

1×ESP8266 NodeMCU ESP-12F
1×Alternatively, ESP8266 D1 Mini NodeMCU ESP-12F
1×Micro USB Cable
1×Alternatively, ESP8266 NodeMCU ESP-12E (Uno-form)
1×USB Cable Type-A to Type-C (for USB-A PC)
1×USB Cable Type-C to Type-C (for USB-C PC)
1×10 Segment LED Bar Graph
10×220 Ω Resistor
1×Breadboard
1×Jumper Wires
1×Recommended: Screw Terminal Expansion Board for ESP8266

Or you can buy the following kits:

1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

This tutorial instructs you how to use ESP8266 NodeMCU to control the 10 Segment LED Bar Graph display. In detail, we will learn:

ESP8266 NodeMCU NodeMCU and 10 Segment LED Bar Graph

Overview of 10 Segment LED Bar Graph

10 Segment LED Bar Graph
Number of Segments 10
LED Color Bright red
Forward Voltage ~2V per segment
Forward Current 20mA max per segment
Resistor Required 220Ω per segment

The 10 Segment LED Bar Graph Pinout

10 Segment LED Bar Graph pinout
  • Anode pins (A1–A10): must be connected to GPIO pins via 220Ω resistors
  • Cathode pins (K1–K10): must be connected to GND

※ NOTE THAT:

The ESP8266 NodeMCU operates at 3.3V logic levels. GPIO0 (D3), GPIO2 (D4), and GPIO15 (D8) are boot strapping pins — they affect the ESP8266 boot mode if held HIGH or LOW at power-up. Once the board has booted, they function as normal GPIO outputs. If you experience boot issues, verify these pins are not accidentally held to the wrong level at startup.

Wiring Diagram

Connect the LED bar graph to the ESP8266 NodeMCU as shown in the table below.

The wiring diagram between ESP8266 NodeMCU and NodeMCU and 10 Segment LED Bar Graph

This image is created using Fritzing. Click to enlarge image

See more in ESP8266's pinout and how to supply power to the ESP8266 and other components.

LED Bar Graph ESP8266 NodeMCU Pin
A1 (Anode 1) D0 / GPIO16 (via 220Ω)
A2 (Anode 2) D1 / GPIO5 (via 220Ω)
A3 (Anode 3) D2 / GPIO4 (via 220Ω)
A4 (Anode 4) D3 / GPIO0 (via 220Ω)
A5 (Anode 5) D4 / GPIO2 (via 220Ω)
A6 (Anode 6) D5 / GPIO14 (via 220Ω)
A7 (Anode 7) D6 / GPIO12 (via 220Ω)
A8 (Anode 8) D7 / GPIO13 (via 220Ω)
A9 (Anode 9) D8 / GPIO15 (via 220Ω)
A10 (Anode 10) D9 / GPIO3 / RX (via 220Ω)
K1–K10 (Cathodes) GND

How To Program ESP8266 NodeMCU for 10 Segment LED Bar Graph

  • The first step is to define the array of GPIO pin numbers connected to the LED bar graph anodes
  • Each pin must be configured as an output using pinMode()
  • To illuminate a segment, set the corresponding GPIO pin HIGH using digitalWrite()
  • To turn off a segment, set the pin LOW
  • No external library is required for this project

ESP8266 NodeMCU Code for 10 Segment LED Bar Graph

/* * This ESP8266 NodeMCU code was developed by newbiely.com * * This ESP8266 NodeMCU code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp8266/esp8266-10-segment-led-bar-graph */ const int NUM_SEGMENTS = 10; // D0(GPIO16), D1(GPIO5), D2(GPIO4), D3(GPIO0), D4(GPIO2), D5(GPIO14), D6(GPIO12), D7(GPIO13), D8(GPIO15), D9(GPIO3/RX) const int ledPins[NUM_SEGMENTS] = {16, 5, 4, 0, 2, 14, 12, 13, 15, 3}; void printBar(int litCount) { Serial.print("Bar: ["); for (int i = 0; i < NUM_SEGMENTS; i++) { Serial.print(i < litCount ? "*" : " "); } Serial.println("]"); } void setup() { Serial.begin(115200); for (int i = 0; i < NUM_SEGMENTS; i++) { pinMode(ledPins[i], OUTPUT); digitalWrite(ledPins[i], LOW); } } void loop() { for (int i = 0; i < NUM_SEGMENTS; i++) { digitalWrite(ledPins[i], HIGH); printBar(i + 1); delay(100); } delay(500); for (int i = NUM_SEGMENTS - 1; i >= 0; i--) { digitalWrite(ledPins[i], LOW); printBar(i); delay(100); } delay(500); }

Detailed Instructions

  • If this is the first time you use ESP8266, see how to set up the environment for ESP8266 in Arduino IDE.
  • Wire the components as shown in the diagram.
  • Connect the ESP8266 NodeMCU board to your computer using a USB cable.
  • Open Arduino IDE on your computer.
  • Select the correct board and port under ToolsBoard and ToolsPort.
  • Copy the code above and paste it into the Arduino IDE.
  • Click Upload to compile and upload the code to the ESP8266 NodeMCU.
  • Open the Serial Monitor (baud rate: 115200) to observe the output.

Serial Monitor Output

Newbiely | Arduino IDE 2.3.8
──
File
Edit
Sketch
Tools
Help
Nodemcu 1.0 (ESP-12E Module)
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Nodemcu 1.0 (ESP-12E Module)' on 'COM15')
New Line
9600 baud
Bar: [* ] Bar: [** ] Bar: [*** ] Bar: [**** ] Bar: [***** ] Bar: [****** ] Bar: [******* ] Bar: [******** ] Bar: [********* ] Bar: [**********] Bar: [********* ] Bar: [******** ] Bar: [******* ] Bar: [****** ] Bar: [***** ] Bar: [**** ] Bar: [*** ] Bar: [** ] Bar: [* ] Bar: [ ]
Ln 11, Col 1
Nodemcu 1.0 (ESP-12E Module) on COM15
2

Additional Knowledge

The ESP8266 exposes only approximately 11 usable GPIO pins, which is a significant constraint compared to the ESP32's 30+ available GPIOs. Several of those 11 pins carry boot-mode sensitivity (GPIO0, GPIO2, GPIO15), meaning the logic level present on those pins at power-up determines how the chip starts. This limits the number of output-heavy projects that can be implemented directly on the ESP8266 without peripheral assistance.

When more output channels are required than the ESP8266 can provide natively, a shift register such as the 74HC595 is a practical solution. A single 74HC595 delivers 8 output lines while consuming only 3 GPIO pins (data, clock, latch). Multiple 74HC595 chips can be daisy-chained to expand output capacity further without adding GPIO usage, making them well suited for driving LED arrays, bar graphs, or segment displays on pin-constrained platforms.

Video Tutorial

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!