Raspberry Pi Pico - 10 Segment LED Bar Graph

1×Raspberry Pi Pico W
1×Raspberry Pi Pico Alternatively,
1×Micro USB Cable
1×10 Segment LED Bar Graph
10×220 Ω Resistor
1×Breadboard
1×Jumper Wires
1×Recommended: Screw Terminal Expansion Board for Raspberry Pi Pico

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 .

In this guide, we will learn to set up and use the 10 Segment LED Bar Graph with the Raspberry Pi Pico. We will cover the following details:

https://newbiely.com/images/cover/raspberry-pi-pico-10-segment-led-bar-graph.jpg

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): connect to GP0–GP9 via 220Ω resistors
  • Cathode pins (K1–K10): connect to GND (0 volts)

Wiring Diagram

Each anode pin of the LED bar graph must be connected to its GPIO pin through a 220Ω resistor to limit the current and protect both the LED and the Raspberry Pi Pico.

LED Bar Graph Raspberry Pi Pico Pin
A1 (Anode 1) GP0 (via 220Ω)
A2 (Anode 2) GP1 (via 220Ω)
A3 (Anode 3) GP2 (via 220Ω)
A4 (Anode 4) GP3 (via 220Ω)
A5 (Anode 5) GP4 (via 220Ω)
A6 (Anode 6) GP5 (via 220Ω)
A7 (Anode 7) GP6 (via 220Ω)
A8 (Anode 8) GP7 (via 220Ω)
A9 (Anode 9) GP8 (via 220Ω)
A10 (Anode 10) GP9 (via 220Ω)
K1–K10 (Cathodes) GND (0 volts)

Raspberry Pi Pico Code - 10 Segment LED Bar Graph

""" This Raspberry Pi Pico MicroPython code was developed by newbiely.com This Raspberry Pi Pico code is made available for public use without any restriction For comprehensive instructions and wiring diagrams, please visit: https://newbiely.com/tutorials/raspberry-pico/raspberry-pi-pico-10-segment-led-bar-graph """ from machine import Pin import time NUM_SEGMENTS = 10 LED_PIN_NUMS = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] leds = [Pin(p, Pin.OUT) for p in LED_PIN_NUMS] def print_bar(lit_count): bar = '*' * lit_count + ' ' * (NUM_SEGMENTS - lit_count) print('Bar: [' + bar + ']') for led in leds: led.value(0) while True: for i in range(NUM_SEGMENTS): leds[i].value(1) print_bar(i + 1) time.sleep(0.1) time.sleep(0.5) for i in range(NUM_SEGMENTS - 1, -1, -1): leds[i].value(0) print_bar(i) time.sleep(0.1) time.sleep(0.5)

Please follow these instructions step by step:

  • Ensure that Thonny IDE is installed on your computer.
  • Ensure that MicroPython firmware is installed on your Raspberry Pi Pico.
  • If this is your first time using a Raspberry Pi Pico, refer to the Raspberry Pi Pico - Getting Started tutorial for detailed instructions.
  • Wire the components according to the provided diagram.
  • Connect the Raspberry Pi Pico to your computer using a Micro USB cable.
  • Launch the Thonny IDE on your computer.
  • On Thonny IDE, select MicroPython (Raspberry Pi Pico) Interpreter by navigating to Tools Options.
  • In the Interpreter tab, select MicroPython (Raspberry Pi Pico) from the drop-down menu.
  • Ensure the correct port is selected. Thonny IDE should automatically detect the port.
  • Copy the above code and paste it to the Thonny IDE's editor.
  • Save the script to your Raspberry Pi Pico by:
    • Click the Save button, or use Ctrl+S keys.
    • In the save dialog, select Raspberry Pi Pico.
    • Save the file as main.py
  • Click the green Run button (or press F5) to run the script.
  • Watch the LED bar animate on your breadboard.
  • Check the message in the Shell at the bottom of Thonny.

Thonny Console Output

Shell x
>>> %Run -c $EDITOR_CONTENT
MPY: soft reboot Bar: [* ] Bar: [** ] Bar: [*** ] Bar: [**** ] Bar: [***** ] Bar: [****** ] Bar: [******* ] Bar: [******** ] Bar: [********* ] Bar: [**********] Bar: [********* ] Bar: [******** ] Bar: [******* ] Bar: [****** ] Bar: [***** ] Bar: [**** ] Bar: [*** ] Bar: [** ] Bar: [* ] Bar: [ ]
MicroPython (Raspberry Pi Pico) • Board CDC @ COM29 ≡

If you name your script main.py and save it to the root directory of the Raspberry Pi Pico, it will automatically run each time the Pico is powered on or reset. This is useful for standalone applications that need to start running immediately upon power-up. If you name your script another name other than main.py, you will need to manually run it from Thonny's Shell.

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!