Arduino MKR WiFi 1010 - 10 Segment LED Bar Graph

In this tutorial, we are going to learn:

Arduino MKR WiFi 1010 and 10 Segment LED Bar Graph

Hardware Preparation

1×Arduino MKR WiFi 1010
1×Micro USB Cable
1×Optionally, DC Power Jack
1×10 Segment LED Bar Graph
10×220 Ω Resistor
1×Breadboard
1×Jumper Wires

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 .

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

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 MKR WiFi 1010 as shown in the table below.

The wiring diagram between Arduino MKR WiFi 1010 LED Bar Graph

This image is created using Fritzing. Click to enlarge image

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

How To Program Arduino MKR WiFi 1010 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] = {5, 6, 7, 8, 9, 10, 11, 12, 13, 14};
  • Set each pin as output: pinMode(ledPins[i], OUTPUT);
  • Light a segment: digitalWrite(ledPins[i], HIGH);
  • Turn off a segment: digitalWrite(ledPins[i], LOW);

Arduino Code - 10 Segment LED Bar Graph

Detailed Instructions

  • Connect Arduino MKR WiFi 1010 to PC via Micro USB cable.
  • Navigate to the Arduino IDE, then select the board and port.
  • Copy the above code and paste it into Arduino IDE.
  • Click the Upload button on Arduino IDE to upload code to Arduino MKR WiFi 1010.
  • Observe the LED bar graph fill up segment by segment, then empty back down in a repeating animation.
/* * This Arduino MKR WiFi 1010 code was developed by newbiely.com * * This Arduino MKR WiFi 1010 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-mkr/arduino-mkr-wifi-1010-10-segment-led-bar-graph */ const int NUM_SEGMENTS = 10; const int ledPins[NUM_SEGMENTS] = {5, 6, 7, 8, 9, 10, 11, 12, 13, 14}; 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 MKR WiFi 1010
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino MKR WiFi 1010' 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 MKR WiFi 1010 on COM15
2

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!