Lesson 98-9: LED Voltage Level Meter Using Arduino or walking light with potentiometer
This project shows you how to build a voltage level meter that uses five LEDs as a bar-graph display, driven entirely by an Arduino and a single potentiometer. As you rotate the knob, the Arduino reads the changing voltage on an analog pin and lights up one LED per volt, so the row of lights literally "walks" up and down with the knob. It is one of the clearest ways to understand analog input, because you can see the analog-to-digital conversion happening in real time as a physical light bar.
The practical value here goes well beyond a light show. Once you understand how to map a measured voltage to a set of outputs, you can reuse the exact same pattern for real instrumentation. For example, you could build:
- A battery charge indicator that shows remaining capacity of a 12 V or USB power bank as a row of LEDs.
- A water tank level gauge, where a float sensor outputs a voltage proportional to depth.
- A temperature bar display using an analog temperature sensor such as the LM35.
- A signal-strength or audio-level meter for a radio receiver or amplifier.
- A simple sensor readout for any 0–5 V analog transducer (pressure, light, position).
- A bench-test voltage probe for checking power rails without a multimeter screen.
Because the thresholds are calculated as percentages of the board voltage, the same code works on 5 V boards like the Uno and Mega and on 3.3 V boards with only a one-line change.
Hardware and Components
The parts list is deliberately minimal, and everything is explained in the early part of the video (in video at 01:54). You will need:
- One Arduino board (Uno, Nano, or Mega).
- Five LEDs, ideally of a single color so the bar reads clearly, though mixed colors work fine.
- Five current-limiting resistors. The tutorial uses 1 kΩ resistors, but anything from roughly 300 Ω to 1 kΩ will work; higher values simply make the LEDs dimmer (in video at 05:33).
- One potentiometer. Both a rotary knob type and a slide type are demonstrated (in video at 02:19).
- A breadboard and jumper wires.
A quick note on the LED itself, since it matters for wiring: an LED is a diode, so it only conducts one way. The flat side of the plastic body, and the shorter leg, is the cathode (negative). The longer leg is the anode (positive). The tutorial walks through this symbol and physical shape in detail (in video at 02:39).
The resistor value is not arbitrary. An LED drops roughly 2 V, and the small 3 mm and 5 mm types draw about 10 mA. With a 5 V supply, the remaining 3 V must be dropped across the resistor, so Ohm's law gives R = 3 V / 0.01 A = 300 Ω. That is the value for maximum brightness; using 1 kΩ is a safe, slightly dimmer choice (in video at 04:41).
Wiring Guide
The LED section of the wiring is identical to the earlier walking-light project: each LED anode connects to its own digital pin, and each cathode goes through a resistor to a common ground rail. In the tutorial the LEDs are wired to pins 7, 6, 5, 4, and 3 (in video at 43:04).
The potentiometer is the only new part. Its two outer pins go to the two power rails — one outer pin to ground and the other to 5 V (or 3.3 V if you are measuring a 3.3 V system). The middle pin, called the wiper, is the output and must connect to analog pin A0 (in video at 43:30). The wiper is what produces the variable voltage: as you turn the knob, the wiper slides along a resistive track and the voltage it presents changes smoothly between the two rails.
One important detail: if you remove the potentiometer while the circuit is running, the analog pin is left floating and the LEDs will flicker randomly. That behavior is demonstrated in the video (in video at 48:52) and is a good reminder that an analog input always needs a defined voltage source.
Code Explanation
The code is short and most of it is straightforward, so this section focuses only on the parts you will want to change. All of these settings sit at the top of the sketch.
Pin definitions. These tell the Arduino which pins the LEDs and the potentiometer are connected to. If you wired your LEDs differently, change these numbers to match — the order matters, because LED1 is the lowest threshold and LED5 the highest.
const int potPin = A0;//define a pin to connect potentiometer
const int LED1 = 7;
const int LED2 = 6;
const int LED3 = 5;
const int LED4 = 4;
const int LED5 = 3;
Board voltage. This is the single most important value to get right. It is the reference against which every threshold is calculated. Set it to 5.0 for an Uno or Mega, and to 3.3 for a 3.3 V Nano or similar board. If you leave it wrong, every LED will switch at the wrong voltage (in video at 44:19).
float boardVoltage= 5.0;//for UNO and MEGA 5.0V for Nano either 5V or 3.3V
Serial voltage display. Set this to true to print the measured voltage to the Serial Monitor at 9600 baud, which is extremely useful while calibrating. Set it to false to silence the output once everything works.
boolean showVoltage = true;//true or false to read voltage in serial monitor
How the conversion works. The Arduino's analog-to-digital converter returns a number from 0 to 1023, because it is a 10-bit converter (210 = 1024 steps). The code scales that raw number into a real voltage using the board voltage as the reference. This is the line to remember if you ever move to a 12-bit board such as the Due, where you would divide by 4095 instead.
int sensorValue = analogRead(A0);
float voltage = sensorValue * (boardVoltage / 1023.0);
The threshold logic. Rather than hard-coding voltages, each step is expressed as a percentage of the board voltage. At 95% or above, all five LEDs light; above 80% only four; and so on down to 20%, where a single LED lights. This percentage approach is what makes the sketch portable between 5 V and 3.3 V boards without rewriting the comparisons.
if (voltage >= boardVoltage*0.95)
{
digitalWrite(LED1, HIGH);
digitalWrite(LED2, HIGH);
digitalWrite(LED3, HIGH);
digitalWrite(LED4, HIGH);
digitalWrite(LED5, HIGH);
}
Because the code uses else if, exactly one branch runs per pass through the loop, so only the correct number of LEDs is ever on at once. The 50 ms delay at the end of each loop keeps the display from flickering.
Live Project and Demonstration
With the sketch uploaded, open the Serial Monitor at 9600 baud and turn the knob slowly. The printed voltage and the LED bar track each other closely: at roughly 1 V one LED is lit, at 2 V two are lit, and so on up to about 4.8 V where all five are on (in video at 47:37). The readings land within a few hundredths of a volt of the expected value, which is excellent for a 10-bit converter.
If the steps look slightly uneven, it is usually the resistors rather than the code. The tutorial notes that standard carbon-film resistors carry a 10% tolerance, while blue metal-film types are typically 1% and give noticeably tighter, more accurate steps (in video at 48:18).
You can also swap the rotary potentiometer for a slide potentiometer and get the same behavior with a linear feel, which is a nice option if you plan to mount the meter in a panel (in video at 49:07).
If you want to move the light manually instead of with a knob, that is covered in Lesson 98-8: Walking Light with Push Button and LEDs with Arduino. And if you simply want the LEDs to walk on their own timer, see Lesson 98-7: Walking Light Using Arduino and 5 LEDs.
Related projects from this video
- Lesson 98-1: How to Turn On and Off an LED with Arduino
- Lesson 98-2: How to Turn On and Off an LED Using a Push Button with Arduino
- Lesson 98-3: How to Turn On/Off a Toggle LED Using a Push Button with Arduino
- Lesson 98-4: Fading an LED Light Using Arduino: Brightness Control
- Lesson 98-5: Fade Light When a Button Is Pressed Using Arduino
- Lesson 98-6: Seesaw LED Game with Arduino
- Lesson 98-7: Walking Light Using Arduino and 5 LEDs
- Lesson 98-8: Walking Light with Push Button and LEDs with Arduino
- Lesson 98-10: Arduino Traffic Light
Chapters
- [00:00] Overview of the 10 LED projects
- [02:29] LED basics, symbols, and resistor calculation
- [42:25] Introduction to the LED voltage level meter
- [43:04] Wiring the LEDs and potentiometer
- [43:54] Explaining the voltage bar code
- [44:19] Setting the board voltage reference
- [46:00] Threshold logic and percentage steps
- [47:14] Demonstration: reading voltage with the LED bar
- [48:18] Resistor tolerance and accuracy
- [49:07] Using a slide potentiometer
This code has not been parsed yet. Please return to the admin panel to parse it.
Things you might need
-
AmazonSunFounder Arduino Learning Kit on AliExpresss.click.aliexpress.com
-
Amazon
-
Amazon
-
Amazon
Resources & references
-
DocumentationDocumentation for SunFounder 3 in 1 IoT/Smart Car/Learning Kitdocs.sunfounder.com
-
External
-
External
-
External
Files📁
Arduino Libraries (zip)
-
SunFounder's 3-in-1 Smart Car learning kit source code
3in1-kit-main-v2.zip12.80 MB
User’s Manual
-
SunFounder 3-in-1 Arduino Smart Car assembly manualThis document shows step by step assembly of SunFounder 3-in-1 Arduino Smart Car
SunFounder_car_assembly_manual.pdf1.20 MB