Knob-Controlled Servo
Steer the servo with a potentiometer.
Knob-Controlled Servo is a free Arduino & IoT Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Arduino & IoT Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Steer with a Knob
Time to take control by hand. Turn a potentiometer and the servo follows in real time, like a tiny steering wheel. 🎛️
The Plan
The idea is simple: read the knob, convert that number into an angle, and write it to the servo, over and over inside loop().
Read the Knob
Use analogRead() on the pot's pin. It gives back a number from 0 to 1023 that follows how far you've turned the knob.
int val = analogRead(A0);The Range Mismatch
The knob speaks 0 to 1023, but the servo only understands 0 to 180. You need to convert between those two scales.
map() to the Rescue
The map() function rescales a number from one range into another. It's the perfect bridge from knob units to servo degrees.
int angle = map(val, 0, 1023, 0, 180);Send It to the Servo
Now feed that mapped angle straight into write(). The servo snaps to whatever position your knob is pointing at.
myServo.write(angle);The Whole Loop
Read, map, write: stack those three lines in loop() and the servo tracks your knob continuously.
void loop() {
int val = analogRead(A0);
int angle = map(val, 0, 1023, 0, 180);
myServo.write(angle);
}Let It Settle
Add a tiny delay() at the end of the loop. It gives the servo a moment to reach each position and smooths out the motion.
delay(15);Wire the Pot
The potentiometer's outer pins go to 5V and ground, and the middle wiper pin goes to analog pin A0. That gives a clean sweep of voltage.
Tame the Jitter
Analog readings wobble a little, so the servo may jitter. Reading several times and averaging, or ignoring tiny changes, calms it down.
Flip the Direction
Want the servo to turn the opposite way? Just swap the map output to go from 180 to 0 instead of 0 to 180.
int angle = map(val, 0, 1023, 180, 0);Quick Check
Let's connect the knob reading to a servo angle.
Recap
Read the pot, map 0 to 1023 into 0 to 180, then write that angle each loop. Now your hand directly steers the servo. 🙌
Frequently asked questions
Is the “Knob-Controlled Servo” lesson free?
Yes — the full text of “Knob-Controlled Servo” is free to read here on the web, and the Arduino & IoT Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Arduino & IoT Academy course, upgrade to CoddyKit PRO.
What will I learn in “Knob-Controlled Servo”?
Steer the servo with a potentiometer. You practise Arduino & IoT Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Arduino & IoT Academy?
No prior experience is required. Arduino & IoT Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Knob-Controlled Servo” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Arduino & IoT Academy lesson?
Yes. Every Arduino & IoT Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- How a Servo Knows Its Angle
- The Servo Library & attach
- Sweep from 0 to 180
- Knob-Controlled Servo