Arduino - 10 Segment LED Bar Graph

In this tutorial, we are going to learn:

About 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

Pinout

10 Segment LED Bar Graph pinout
  • Anode pins (A1–A10): each needs to be connected to a GPIO pin via a 220Ω resistor
  • Cathode pins (K1–K10): each needs to be connected to GND

Wiring Diagram

Connect the 10 Segment LED Bar Graph to Arduino Uno as shown in the table below.

Arduino LED Bar Graph Wiring Diagram

This image is created using Fritzing. Click to enlarge image

LED Bar Graph Arduino Pin
A1 (Anode 1) Pin 2 (via 220Ω)
A2 (Anode 2) Pin 3 (via 220Ω)
A3 (Anode 3) Pin 4 (via 220Ω)
A4 (Anode 4) Pin 5 (via 220Ω)
A5 (Anode 5) Pin 6 (via 220Ω)
A6 (Anode 6) Pin 7 (via 220Ω)
A7 (Anode 7) Pin 8 (via 220Ω)
A8 (Anode 8) Pin 9 (via 220Ω)
A9 (Anode 9) Pin 10 (via 220Ω)
A10 (Anode 10) Pin 11 (via 220Ω)
K1–K10 (Cathodes) GND

How To Program Arduino for 10 Segment LED Bar Graph

  • No library needed: LED Bar Graph uses only the built-in digitalWrite() function
  • Define pins: const int ledPins[10] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
  • Set each pin as output: pinMode(ledPins[i], OUTPUT);
  • Light a segment: digitalWrite(ledPins[i], HIGH);
  • Turn off a segment: digitalWrite(ledPins[i], LOW);
  • Print bar state: iterate the array, print * for lit segments and for off segments

Arduino Code - 10 Segment LED Bar Graph

Quick Steps

  • Connect Arduino to PC via USB cable.
  • Navigate to the Tools menu, select the right board and port.
  • Copy the above code and paste it to Arduino IDE.
  • Click Upload button on Arduino IDE to upload code to Arduino.
  • Observe the LED bar graph fill up segment by segment then empty back down in a repeating animation.
/* * Created by ArduinoGetStarted.com * * This example code is in the public domain * * Tutorial page: https://arduinogetstarted.com/tutorials/arduino-10-segment-led-bar-graph */ const int NUM_SEGMENTS = 10; const int ledPins[NUM_SEGMENTS] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; 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(9600); 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); }

Serial Monitor Output

Newbiely | Arduino IDE 2.3.8
──
File
Edit
Sketch
Tools
Help
Arduino Uno
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Uno' 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
Arduino Uno on COM15
2

Video Tutorial

We are considering to make the video tutorials. If you think the video tutorials are essential, please subscribe to our YouTube channel to give us motivation for making the videos.

The Best Arduino Starter Kit

※ OUR MESSAGES