Build a Slide Pot LED Meter and Servo with the Arduino UNO R4 WiFi (Plus a Free Kids' Guide)
Slide a lever and watch 96 LEDs fill up while a servo arm swings to match. This weekend project uses an Arduino UNO R4 WiFi, a linear slide potentiometer and a small hobby servo. It needs no soldering and no external LEDs, and the whole sketch is about 140 lines.
This guide has everything you need to build it: parts, wiring, the full code, calibration and troubleshooting. There is also a free, printable kids' guide that walks young makers through how the code works, with hands-on activities.
Download the kids' guide (PDF, 9 pages)
What It Does
The UNO R4 WiFi has a 12×8 LED matrix built into the board. As you move the slider, the matrix fills from left to right one column at a time, and the leading column fills from the bottom up, so all 96 LEDs are used. At the same time, a hobby servo on pin D9 turns to the matching angle:
- Slider at one end: all LEDs off, servo at 0°
- Halfway: the left 6 columns lit (48 LEDs), servo at 90°
- Other end: all 96 LEDs on, servo at 180°
slider ~37% slider ~71% slider 100% ████░░░░░░░░ ████████░░░░ ████████████ ████░░░░░░░░ ████████░░░░ ████████████ ████░░░░░░░░ ████████░░░░ ████████████ ████░░░░░░░░ ████████░░░░ ████████████ █████░░░░░░░ █████████░░░ ████████████ █████░░░░░░░ █████████░░░ ████████████ █████░░░░░░░ █████████░░░ ████████████ █████░░░░░░░ █████████░░░ ████████████
It's a simple project, but it covers the basics behind a lot of real electronics: reading an analog input, smoothing a noisy signal, mapping a value onto a display, and driving a motor to a position.
Parts You'll Need
- Arduino UNO R4 WiFi and a USB-C data cable. Our UNO R4 WiFi Starter Power Bundle includes the board plus a 9V clip, AA holder and DC barrel plug for running it away from your computer.
-
Linear slide potentiometer, any value from 1 kΩ to 100 kΩ (10 kΩ is typical). Use a linear taper, often marked
B(for exampleB10K). An audio/log taper (A10K) will fill unevenly. Our 10K Linear Slide Potentiometer Modules (2-pack) are a drop-in fit, and the Arduino Input Kit adds a joystick, rotary encoder and button for your next project. - Small hobby servo such as an SG90 or MG90S (3-wire, 5 V)
- Breadboard and 6 jumper wires. The pot and the servo both need 5V and GND, so they share the breadboard's power rails.
You don't need any external LEDs or resistors. The display is the matrix on the board itself.
Wiring
Disconnect USB while wiring. Run the board's 5V and GND pins to the breadboard rails, then connect the pot and servo there:
UNO R4 WiFi breadboard rails parts
----------- ---------------- -----
5V --------- + rail --+------------- slide pot end 1
+------------- servo red (+)
GND --------- - rail --+------------- slide pot end 2
+------------- servo brown/black (-)
A0 ----------------------------------- slide pot wiper
D9 ----------------------------------- servo orange/yellow (signal)
Slide Pot
A potentiometer has three connections: the two ends of its resistive track and the wiper, which moves with the slider. Wire the two ends across 5V and GND, and the wiper to A0.
| UNO R4 pin | Slide pot pin | Notes |
|---|---|---|
| 5V | End 1 of the track | Either end works; swapping ends reverses the fill direction |
| A0 | Wiper | The pin whose voltage changes as you slide |
| GND | End 2 of the track | The other end |
Finding the Pins on Your Slide Pot
Pin layouts vary between parts, so check yours before wiring:
-
Breakout modules (a pot on a small PCB, like ours) are usually labeled, e.g.
VCC/OTAorOUT/GND. ConnectVCC→ 5V,OTA/OUT→ A0, andGND→ GND. Some modules have two outputs (OTA/OTB) for a dual-gang pot; use either one. - Bare slide pots commonly have two pins at one end and one pin at the other, and one of the paired pins is the wiper. Others have all three pins in a row with the wiper in the middle.
- To find the wiper with a multimeter (resistance mode, pot unpowered): the two pins that read the full rated value (e.g. 10 kΩ) wherever the slider is are the ends. The remaining pin is the wiper; its reading to either end changes as you slide.
- Six-pin slide pots are dual-gang (two pots on one shaft). Use one set of three.
Putting the wiper on 5V or GND by mistake won't damage anything at these resistances, but the display won't respond correctly. Never connect 5V directly to GND.
Servo
Hobby servos have a 3-wire lead, usually in this order on the connector:
| Servo wire | Common colors | Connect to |
|---|---|---|
| Signal | Orange, yellow or white | D9 |
| + (power) | Red (the middle wire) | 5V rail |
| − (ground) | Brown or black | GND rail |
A note on power: one SG90/MG90S-class servo can run from the UNO's 5V pin while the board is on USB. Larger servos (MG996R and similar), or several servos, draw more current than USB can supply and will make the board reset or behave erratically. For those, power the servo from a separate 5–6 V supply (e.g. a 4×AA pack), connect that supply's − to the UNO's GND, and keep only the signal wire on D9. Do not connect the external supply's + to the UNO's 5V pin.
Upload and Try It
- Copy the sketch from the end of this post into a new Arduino IDE sketch and save it as
r4_slidepot_demo. - In Boards Manager, install Arduino UNO R4 Boards. Select Arduino UNO R4 WiFi and its port.
- Upload. The
Arduino_LED_Matrixlibrary comes with the board package andServocomes with the Arduino IDE, so there's nothing else to install. - Slide the pot from one end to the other. The matrix should go from fully dark to fully lit, and the servo should sweep through its range along with it.
Calibration and Settings
Many slide pots don't quite reach 0 V or 5 V at the ends, so the last few LEDs may not light, or may not turn off. To fix this:
- Open Serial Monitor at 115200 baud and send
c. The sketch printsraw=… smoothed=… leds=… servo=…five times a second. - Push the slider to each end and note the
rawvalue. - Set
POT_MINandPOT_MAXat the top of the sketch slightly inside those numbers and upload again. Sendcagain to stop the readings.
All the settings are constants at the top of the sketch:
| Constant | Default | Purpose |
|---|---|---|
POT_PIN |
A0 |
Analog pin connected to the wiper |
SERVO_PIN |
9 |
Pin connected to the servo signal wire |
SERVO_MIN_DEG |
0 |
Servo angle with the slider at the empty end |
SERVO_MAX_DEG |
180 |
Servo angle with the slider at the full end; swap the two to reverse only the servo |
POT_MIN |
20 |
Raw reading (0–4095) treated as empty |
POT_MAX |
4075 |
Raw reading treated as full |
REVERSE |
false |
Set true to flip the fill direction without rewiring |
SMOOTHING |
0.15 |
Moving-average factor; lower is steadier but slower |
HYSTERESIS |
0.6 |
LEDs the reading must move before the display changes; raise it if the edge flickers |
Troubleshooting
-
Display never changes: the wiper is probably not on A0. Recheck with the multimeter steps above. Send
c: ifrawstays near 0 or near 4095, A0 is tied to GND or 5V instead of the wiper. - Display jumps to full or empty halfway along: you may have a log-taper pot, or the wiper is on an end pin and one end is unconnected.
-
Fills the wrong way: swap the 5V and GND wires on the pot ends, or set
REVERSE = true. -
Edge LED flickers: increase
HYSTERESIS(e.g.1.0) or lowerSMOOTHING. Long, loose jumper wires pick up noise; keep them short. - Raw values are noisy or random: the GND wire is missing or loose, leaving A0 floating.
-
Servo doesn't move: check that the signal wire is on D9 and the servo's red and brown wires reach the 5V and GND rails. Send
c; ifservo=changes as you slide but the servo doesn't move, it's a wiring or power problem. - Board resets or matrix flickers when the servo moves: the servo is drawing too much current from USB. Use a separate servo supply as described above.
-
Servo buzzes or strains at the ends: many servos can't reach a full 0–180°. Narrow the range, e.g.
SERVO_MIN_DEG = 10andSERVO_MAX_DEG = 170.
Make It Permanent
Once it works on the breadboard, you can swap the jumper wires for something sturdier. Our Screw Terminal Shield + UNO R4 WiFi bundle stacks onto the board and breaks every pin out to a labeled screw terminal, so the slide pot and servo wires clamp down securely with no soldering.
The project also makes a great desk toy or classroom demo in a 3D-printed case. The UNO's mounting holes take M3 screws, so press M3 Durathread heat set inserts into the case's standoffs for strong, reusable threads that won't strip when you open it up to tinker. Not sure which size or style you need? See our Heat Set Insert Size Guide.
Building It With Kids
This project is a good first look at real code for young makers. One hand moves the slider and two things happen at once, so it's easy to see that the board is reading an input and controlling outputs.
The free kids' guide (PDF) is written for a child and a grown-up to read together. The grown-up handles the wiring and uploading while the child moves the slider, makes predictions and finds code names in the sketch. It covers:
- Your Arduino slider project: how the slider, board, lights and servo fit together, with empty, halfway and full examples.
- The parts and their wires: what a potentiometer and its wiper are, what pins like A0, D9, 5V and GND do, and safety rules for building together.
-
Read your first lines of code: libraries, named constants,
setup()andloop(), and what symbols like//,;and{ }do. -
Turn the slider into a number: following a reading from
analogReadthrough smoothing and scaling to a fraction from 0 to 1 ("how full is the cup?"). -
Choose which lights turn on: how two
forloops visit every LED and why counting starts at 0. - Tell the servo where to turn: degrees, rounding, and how the code keeps the arm from twitching.
-
Keep checking while you play:
millis(), hysteresis, and watching the hidden numbers in Serial Monitor. - Try being the programmer: hands-on activities, plus notes and answers for the grown-up.
Try Being the Programmer
The guide ends with three activities. Make a guess before you try each one, and save a copy of the sketch before changing it.
- Draw your prediction. The slider is one quarter of the way from empty to full. Which lights will be on, and what angle will the code ask the servo for?
-
Make the direction flip. Change
const bool REVERSE = false;totrue. What happens to the lights and the servo? Upload, try it, then change it back. -
Choose a smaller turn. Set
SERVO_MIN_DEG = 20andSERVO_MAX_DEG = 160. Which angle will the slider choose at each end? What about halfway?
Answers for grown-ups: (1) one quarter is 24 lights, the first three full columns, and a 45° servo target. (2) REVERSE flips the fraction used by both outputs, so the lights and the servo both change direction. (3) The ends become 20° and 160°; halfway is still 90°.
Safety first: unplug USB before changing wires, never join 5V straight to GND, and keep fingers clear of the moving servo arm.
The Code
Here is the complete sketch. Copy it into the Arduino IDE, save it as r4_slidepot_demo, and upload it to your UNO R4 WiFi.
// Slide pot level meter — Arduino UNO R4 WiFi
//
// Reads a linear slide potentiometer on A0 and fills the built-in 12x8 LED
// matrix in proportion to its position. The fill sweeps left to right one
// column at a time; the leading column fills bottom to top, so all 96 LEDs
// give 97 distinct levels (0 = all off, 96 = all on). A hobby servo on D9
// follows the same position, sweeping from SERVO_MIN_DEG to SERVO_MAX_DEG.
#include "Arduino_LED_Matrix.h"
#include <Servo.h>
// ---- Configuration ---------------------------------------------------------
const uint8_t POT_PIN = A0;
const uint8_t SERVO_PIN = 9;
// Servo angle at the empty and full ends of the slider. Narrow this range if
// your servo buzzes or strains at its end stops.
const int SERVO_MIN_DEG = 0;
const int SERVO_MAX_DEG = 180;
// Raw 12-bit readings at the two ends of travel. Many slide pots never reach
// exactly 0 or 4095; send 'c' in Serial Monitor to see the live raw value and
// set these to what you read at each end.
const int POT_MIN = 20;
const int POT_MAX = 4075;
// Set true if the display fills in the opposite direction to what you want.
const bool REVERSE = false;
// Smoothing factor for the exponential moving average (0..1). Lower values
// are steadier but lag more.
const float SMOOTHING = 0.15f;
// How far (in LEDs) the reading must move past the current level before the
// display changes. Prevents flicker when the slider sits on a boundary.
const float HYSTERESIS = 0.6f;
const unsigned long SAMPLE_MS = 5;
// ---- Display ---------------------------------------------------------------
const uint8_t ROWS = 8;
const uint8_t COLS = 12;
const uint8_t TOTAL_LEDS = ROWS * COLS;
ArduinoLEDMatrix matrix;
uint8_t frame[ROWS][COLS];
Servo servo;
int shownLevel = -1; // -1 forces the first draw
int servoAngle = -1;
float smoothed = 0;
bool streamRaw = false;
unsigned long lastSample = 0;
unsigned long lastPrint = 0;
void drawLevel(int level) {
for (uint8_t col = 0; col < COLS; col++) {
for (uint8_t row = 0; row < ROWS; row++) {
// Index LEDs column by column, bottom row first.
int index = col * ROWS + (ROWS - 1 - row);
frame[row][col] = index < level ? 1 : 0;
}
}
matrix.renderBitmap(frame, ROWS, COLS);
}
// Returns slider position from 0.0 (empty) to 1.0 (full).
float readFraction() {
int raw = analogRead(POT_PIN);
smoothed += SMOOTHING * (raw - smoothed);
float span = POT_MAX - POT_MIN;
float fraction = (smoothed - POT_MIN) / span;
fraction = constrain(fraction, 0.0f, 1.0f);
if (REVERSE) fraction = 1.0f - fraction;
return fraction;
}
void moveServo(float fraction) {
float target = SERVO_MIN_DEG + fraction * (SERVO_MAX_DEG - SERVO_MIN_DEG);
// Same hysteresis idea as the display: ignore sub-degree wobble so the
// servo doesn't twitch while the slider is still.
if (servoAngle < 0 || fabsf(target - servoAngle) > 1.0f) {
servoAngle = round(target);
servo.write(servoAngle);
}
}
void setup() {
Serial.begin(115200);
analogReadResolution(12);
matrix.begin();
servo.attach(SERVO_PIN);
smoothed = analogRead(POT_PIN);
float fraction = readFraction();
shownLevel = round(fraction * TOTAL_LEDS);
drawLevel(shownLevel);
moveServo(fraction);
Serial.println("Slide pot meter ready. Send 'c' to toggle raw readings.");
}
void loop() {
if (Serial.available()) {
char c = Serial.read();
if (c == 'c' || c == 'C') {
streamRaw = !streamRaw;
Serial.println(streamRaw ? "Raw readings on" : "Raw readings off");
}
}
unsigned long now = millis();
if (now - lastSample < SAMPLE_MS) return;
lastSample = now;
float fraction = readFraction();
float level = fraction * TOTAL_LEDS;
if (fabsf(level - shownLevel) > HYSTERESIS) {
shownLevel = constrain((int)round(level), 0, TOTAL_LEDS);
drawLevel(shownLevel);
}
moveServo(fraction);
if (streamRaw && now - lastPrint >= 200) {
lastPrint = now;
Serial.print("raw=");
Serial.print(analogRead(POT_PIN));
Serial.print(" smoothed=");
Serial.print((int)smoothed);
Serial.print(" leds=");
Serial.print(shownLevel);
Serial.print(" servo=");
Serial.println(servoAngle);
}
}
Have fun building, and if you take the project somewhere new, such as more servos, a different display pattern or a second slider, we'd love to hear about it.