Arduino LED Bar Graph with a 4017 Counter and Potentiometer

In this tutorial I will show you how to drive a LED bar graph using an arduino and a potentiometer. This is fairly easy to do and a nice tutorial about it already exists on the arduino website. This tutorial will be different in that we will use a 4017 counter to save pins from the microcontroller. Additionally, I will demonstrate the concept of “persistence of vision”.

See below a video of the circuit in action.

If you are able to reproduce this project, have any question, correction, or suggestion, please, let me know by leaving a comment.

Hardware Required

  • Arduino board
  • (1) Rotary Potentiometer
  • (1) 4017 Decade Counter
  • Breadboard
  • Some wires


Arduino LED Bar Graph Driven with a 4017 Counter and a Potentiometer

(Click the image to enlarge)

This is how it works:

The 10 LEDs are wired to the outputs of the 4017 counter. There is no need to protect them with current limiting resistors because the maximum current per pin is 10 mA. The arduino controls the 4017 counter using just 2 digital pins: digital pin 2 is connected to the counter’s clock pin, and the digital pin 3 is connected to the counter’s reset pin. The arduino runs a program that reads the analog input from the potentiometer (returning a value between 0 and 1023). The value read is mapped to the range 0-9 and is used to decide the number of LEDs to turn on.

Using the counter we face the limitation of not being able to turn on more than one LED at the same time. To solve this, we quickly turn on/off the LEDs in succession, and thanks to the ”persistence of vision” effect, all the LEDs appear to be on at the same time.

Below is the picture of the circuit in real life.

Arduino LED Bar Graph with a 4017 Counter and Potentiometer

(Click the image to enlarge)


 * LED Bar Graph controlled with an external potentiometer.
 * A 4017 counter is used to save pins on the arduino.
 * The technique of "Persistence of vision" is used to turn on
 * many LEDs at the same time.
 * Developed by Leonel Machava
 * This code is release under the "MIT License" available at

/* Digital pin connected to the counter's clock pin */
int clockPin = 2;

/* Digital pin connected to the counter's reset pin */
int resetPin = 3;

/* Analog pin connected to the potentiometer wiper */
int potPin = 0;

void setup() {

void loop() {
  /* Read the analog value from the potentiometer. */
  int potValue = analogRead(potPin);

  /* Map the value to the range 0-9. */
  int n = potValue * 10 / 1024;

  /* Turn ON/OFF quickly the first n LEDs. The n LEDs
     will appear to be ON at the same time due to the
     "persistence of vision" effect. */
  for( int i = 0; i < n; i++ ) {


 * Sends a clock pulse to the counter making it advance.
void clock() {

 * Resets the counter making it start counting from zero.
void reset() {

Click here to download the source code (arduino_led_bar_graph_4017_pot.pde / 1.38 Kb)

If you like this article please share it by clicking one of the buttons below, follow me on twitter, or register on my RSS to receive article updates. Thanks!

Leave a comment ?


  1. AlexHolsgrove

    I’ve built the circuit, but the LED bar-graph seems to dim when each additional segment is lit. Using an Arduino Uno (AtMega328) and the HEF4017BP decade counter (Phillips)

    • Hello Alex.
      In theory the led bargraph shouldn’t dim when each additional segment is lit because they are not lit at the same time. They are multiplexed and due to the persistence of vision effect “they seem” to be lit at the same time.

      Double check your connections are correct. Please, let me know about your result.

  2. OK, that works, but if you had 20 LEDs could you string together 2 4017 counters and make it work as one longer bar graph for more precision? Or would 10 be the limit? And if 20 is possible, where’s the limit? Just wondering, this brought up some fascinating possiblities.

    • The circuit is not limited to 10 LEDs. You can string 2 or more 4017 counters. Just make sure you know how to cascade 2 or more 4017 counters.

  3. How does it go in reverse in this video ?

    I am trying with standard leds, and cant get reverse with my code:

    void loop() {

    int n = random(10);

    for (int i=-1; i<n; i++){


    I am programmer by the way, but electronics noob, is it possible that reverse aint working because something isn't connected ok ?

    • Sorry for my late reply.
      It is not easy to do that programatically using the constructed circuit. Why: (1) persistence of vision will get in your way. (2) the code you have provided does not help much to acomplish that.
      My code works because it reads the value of the pot in realtime and turns on the LEDs accordingly. So if at a given time the pot reads 8 then the first 8 LEDs will be lit. Later if the pot is gradually turned to 4 you will see the bargraph going in reverse ending up with 4 LEDs lit.

  4. How long did it take before this burnt out? You need the current limiting resistors. No question.

  5. Arduino LED Bar Graph with a 4017 Counter and Potentiometer | codeNtronix

  6. Hi, where can I buy this led bar graph?

  7. Unquestionably consider tyat that you stated. Your favourite
    reason appeared to be on the internet the easiest thing to be mindful of.
    I say to you, I definitely get irked while other
    folks consider concerns that they plainly don’t recognise about.
    You managed to hit the nail pon the top and outlined out the
    entire thing without having side-effects , other
    folks could take a signal. Will probbly be again to gett more.

  8. is implementing – Foreclosure Diaries, a documentary regarding the financial disaster and possesses blogged on foreclosure related issues for American Banker game stefen wisniewski oakland raiders road jersey 61
    nike mens nfl white the sites in most cases
    keep quote for you personally and lock the quote in for a couple of days.

  9. Very good article. I will be facing some of these issues as well..

  10. Right now it appears like Movable Type is the preferred
    blogging platform available right now. (from what I’ve read) Is
    that what you are using on your blog?

  11. Beatrice Dugan

    This site is just gret. I’ve ask these stuffs
    a great deal and I view it that is professional, easy to comprehend.
    I congratulate you for this article that I’ll tell to
    the people around. I request you to visit the page where each learner or learner can find results gpa levels.
    Thank you!

  12. Just want to sayy your article is as amazing. The clarity in your submit
    is just spectacular and thast i ould assume you are knowledgeable in this subject.
    Well togdther with yourr permission let me to snatch
    your feed to keep updated with coming near
    near post. Thanks a million and please continue the rewarding work.

  13. It in reality a great and useful piece of information. I glad that you shared this useful information with us. Please keep us up to date like this. Thanks for sharing.

  14. To determine internal swelling is difficult enough, therefore, consequently, they influence the body for a long time, which threatens the normal fetus. Fluids are dangerous because they break blood circulation. Similar picture leads to worsening feeding and the breath baby, created hypoxia.
    Fighting such a pathology should be done with the help of correction feeding and special exercises so that fluid does not stay tissues. If expectant mother is resting, then under the feet preferably put a cushion or pillow to improve the blood circulation of tired legs. Do not long time to sit or stand, as this leads to stagnation in the body. It is recommended that the knee-elbow position several times a day in order to increase blood flow.
    swollen feet after giving birth

  15. I do not know if it’s just me or if perhaps everybody else experiencing problems
    with your blog. It looks like some of the written text on your posts are running off the
    screen. Can somebody else please provide feedback and let me know if this is
    happening to them too? This could be a issue with my browser
    because I’ve had this happen previously. Many thanks

Reply to lefam ¬
Cancel reply

Notify me of followup comments via e-mail. You can also subscribe without commenting.

Trackbacks and Pingbacks: