A 10 segment LED bar graph is basically ten LEDs lined up in a single package, handy for showing levels, progress, or just making a satisfying light show. Here you'll wire it up to an Arduino GIGA R1 WiFi and drive it straight from digitalWrite() calls, no library required, which makes it a nice first project for seeing how individual GPIO pins map to individual LEDs.
The full tutorial, with every detail and the line-by-line code explanation, is on our site: Arduino Giga R1 WiFi 10 Segment LED Bar Graph
What you need
- Arduino Giga R1 WiFi
- USB Cable Type-A to Type-C (for USB-A PC)
- USB Cable Type-C to Type-C (for USB-C PC)
- 10 Segment LED Bar Graph
- 220 Ω Resistor
- Breadboard
- Jumper Wires
- Screw Terminal Block Shield for Arduino Uno/Mega/Giga
- Sensors/Servo Expansion Shield for Arduino Mega/Giga
- Breadboard Shield for Arduino Mega/Giga
- Enclosure for Arduino Giga
- Power Splitter for Arduino Giga
- DIYables Sensor Kit (18 sensors/displays)
Wiring
The bar graph has anode pins (A1–A10) and cathode pins (K1–K10). Each anode connects to a GPIO pin on the GIGA R1 WiFi through a 220Ω resistor, which limits current so the LED doesn't burn out. All the cathode pins connect to GND. In this build the anodes land on pins 2 through 11, one pin per LED segment.
How it works
Each LED segment lights up when its anode pin is driven HIGH, since current can then flow from the pin through the LED and resistor to GND. Setting the pin LOW turns that segment off. Because every segment has its own dedicated pin, you control each LED independently, which lets you light them one at a time, all together, or in a sweeping pattern just by changing which pins are HIGH or LOW.
Code
The sketch stores the ten anode pin numbers in an array and sets them all as OUTPUT in setup(). In loop(), it lights the segments one by one from left to right with a short delay between each, then turns them off one by one from right to left, repeating continuously. A helper function also prints the current bar state to the Serial Monitor as a row of asterisks, so you can watch the pattern alongside the physical LEDs.
arduino-giga-r1-wifi-10-segment-led-bar-graph.ino
/*
* This Arduino Giga R1 WiFi code was developed by newbiely.com
*
* This Arduino Giga R1 WiFi code is made available for public use without any restriction
*
* For comprehensive instructions and wiring diagrams, please visit:
* https://newbiely.com/tutorials/arduino-giga/arduino-giga-r1-wifi-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);
}
Things that go wrong
If nothing lights up, double check the cathode pins are actually tied to GND and that each resistor sits between the anode and its Arduino pin rather than somewhere else in the circuit. If only some segments light, check that each anode is on the pin number the code expects, since a single swapped wire will light the wrong segment or none at all. Missing or wrong-value resistors can make LEDs unusually dim or risk damaging them.
Full tutorial
The complete tutorial - wiring diagram, code explanation and troubleshooting - is here: https://newbiely.com/tutorials/arduino-giga/arduino-giga-r1-wifi-10-segment-led-bar-graph

Top comments (0)