Potentiometer-gesteuerter Servo
Steuern Sie den Servo mit einem Potentiometer.
Potentiometer-gesteuerter Servo ist eine kostenlose Arduino & IoT Academy-Lektion auf CoddyKit. Dies ist Lektion 4 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Arduino & IoT Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Arduino & IoT Academy-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
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. 🙌
Häufig gestellte Fragen
Ist die Lektion „Potentiometer-gesteuerter Servo“ kostenlos?
Ja — der vollständige Text von „Potentiometer-gesteuerter Servo“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Arduino & IoT Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Arduino & IoT Academy-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „Potentiometer-gesteuerter Servo“?
Steuern Sie den Servo mit einem Potentiometer. Du übst Arduino & IoT Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um Arduino & IoT Academy zu starten?
Keine Vorkenntnisse erforderlich. Arduino & IoT Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 4 von 4.
Wie lange dauert die Lektion „Potentiometer-gesteuerter Servo“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser Arduino & IoT Academy-Lektion Code schreiben und ausführen?
Ja. Jede Arduino & IoT Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- So kennt ein Servo seinen Winkel
- Die Servo-Bibliothek und attach
- Von 0 bis 180 schwenken
- Potentiometer-gesteuerter Servo