• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here:Home » Arduino 12 LED Meter (Bar Graph) With Potentiometer for Various Projects

By Abhishek Ghosh June 24, 2023 10:08 am Updated on June 24, 2023

Arduino 12 LED Meter (Bar Graph) With Potentiometer for Various Projects

Advertisement

There are various ways to create a LED Meter or Bar Graph with a few square LEDs of three colours and demonstrate the function with a potentiometer. There is nothing new with this idea since official documentation of Arduino already has one example of bar graph. However, not all of them are practical to use with every project. The sensors in real often do not generate a voltage (or PWM signal) as a potentiometer does. Some projects have no proper license mentioned and that may create issues to re-use in other projects.

This project itself does not need complicated components. One breadboard, one potentiometer, a few jumper wires, any Arduino IDE compatible board including Arduino UNO, four red LEDs, four yellow LEDs and four green LEDs will do the job.

Twelve LEDs are used because we can use the same code Arduino UNO and ESP8266.

Advertisement

---

Arduino 12 LED Meter Bar Graph With Potentiometer for Various Projects

There are rectangular LEDs available in shops which sell electronic components. They are great to build something like a VU meter. Rest is the sketch used in this project:

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Released under GNU GPL 3.0
// written by Abhishek Ghosh
// see @ thecustomizewindows.com
 
int pin[12] = {13,12,11,10,9,8,7,6,5,4,3,2};
int PotVal = 0;
int ledPower = 0;
int ledNumber= 0;
 
void setup()
{
  for(int i=0; i<12; i++) {
    pinMode(pin[i], OUTPUT);
    Serial.begin(9600);
  }
  
}
 
void loop()
{
  PotVal = analogRead(A5);
  ledNumber = floor((PotVal+1) / 80);
  ledPower = ((PotVal+1)%80)-1;
  Serial.print(PotVal);
  
  for(int i=(sizeof(pin)-1); i>=0; i--)
  {
    Serial.println(i);
    if(i<=ledNumber){
    analogWrite(pin[i], ledPower);
      ledPower = 255;
    } else {
    analogWrite(pin[i], 0);  
    }
    
    delay(2);
  }
}

The meaning and logic of the sketch are probably obvious. The digit 80 came from trial and error (for the potentiometer). If you change it to a higher value such as 256 then the number of LEDs functioning will become lower in number. The ledPower is 255 because we are handling PWM. That is nicely explained in this Arduino document:

Arduino’s PWM frequency at about 500Hz, the green lines would measure 2 milliseconds each. A call to analogWrite() is on a scale of 0 – 255, such that analogWrite(255) requests a 100% duty cycle (always on), and analogWrite(127) is a 50% duty cycle (on half the time) for example.

Probably you will ask the meaning of sizeof() and floor(). sizeof is a commonly used operator in the C. It can compute the size of its operand. sizeof can be applied to integer, floating-point, structure, union, etc.

In C++, floor() and ceil() return integer values. In other words, floor() and ceil() (ceiling) delivers the rounded-off value from a fraction. floor() is lower and ceil() is the upper. If 38.76 is the fraction, after applying the floor, it will become 38 and after applying the ceiling, it will become 39. In high school math, physics and chemistry, we use only the ceiling. Using floor() and ceil() requires some judgement. If the number of LEDs is more, using floor() and ceil() to display temperature as a bar graph will not make the result useless.

The code in this guide will produce the effect you can see by clicking the “Simulate” button.

Facebook Twitter Pinterest

Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to Arduino 12 LED Meter (Bar Graph) With Potentiometer for Various Projects

  • Nginx WordPress Installation Guide (All Steps)

    This is a Full Nginx WordPress Installation Guide With All the Steps, Including Some Optimization and Setup Which is Compatible With WordPress DOT ORG Example Settings For Nginx.

  • WordPress & PHP : Different AdSense Units on Mobile Devices

    Here is How To Serve Different AdSense Units on Mobile Devices on WordPress With PHP. WordPress Has Function Which Can Be Used In Free Way.

  • LED Bar Graph Progress Test : Arduino & Transistors

    Here is Circuit and Code to Create LED Bar Graph Progress Test Project. We Have Shown the Project With Arduino and Als Only With Components Like Transistors.

  • Difference Between Arduino Uno and Arduino Mega

    What is the Difference Between Arduino Uno and Arduino Mega? Do We Need Arduino Mega Despite Having Arduino UNO?

performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

Get new posts by email:

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (24.3K Followers)
  • Twitter (5.8k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • Hybrid Multi-Cloud Environments Are Becoming UbiquitousJuly 12, 2023
  • Data Protection on the InternetJuly 12, 2023
  • Basics of BJT TransistorJuly 11, 2023
  • What is Confidential Computing?July 11, 2023
  • How a MOSFET WorksJuly 10, 2023
PC users can consult Corrine Chorney for Security.

Want to know more about us?

Read Notability and Mentions & Our Setup.

Copyright © 2023 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy