Servo Knob & Sweep
ESP32 DevKit (WROOM-32)·Arduino C++·Updated Jul 27, 2026·by FluxBench TeamIncludes Lab + Schematic + PCB
Analog in, motion out: a 10k potentiometer forms a real voltage divider into GPIO34 and the solver computes the wiper voltage live, so analogRead() maps the knob straight to an SG90 servo angle on GPIO25. Press the tactile button (GPIO14, internal pull-up) to toggle an auto-sweep mode that glides the horn 0-180-0 while a blue LED on GPIO26 signals sweep is active. Watch the horn track the knob in the Lab, then break the wiper wire and see the angle drop to zero. Bundled Lab bench, schematic and routed PCB included.
sketch.ino
// Servo Knob & Sweep - pot-controlled servo with an auto-sweep mode
// Turn the 10k pot to steer the horn; press the button to toggle auto-sweep.
#define PIN_POT 34
#define PIN_BTN 14
#define PIN_LED 26
#define PIN_SERVO 25
#include <ESP32Servo.h>
Servo horn;
int sweepMode = 0;
int sweepAngle = 0;
int sweepDir = 1;
int lastBtn = 1;
int tick = 0;
void setup() {
Serial.begin(115200);
pinMode(PIN_BTN, INPUT_PULLUP);
pinMode(PIN_LED, OUTPUT);
horn.attach(PIN_SERVO);
Serial.println("Servo Knob & Sweep - pot steers the horn, button toggles auto-sweep");
}
void loop() {
int btn = digitalRead(PIN_BTN);
if (btn == 0 && lastBtn == 1) {
sweepMode = 1 - sweepMode;
digitalWrite(PIN_LED, sweepMode);
if (sweepMode == 1) {
Serial.println("Auto-sweep ON (LED lit)");
} else {
Serial.println("Knob mode (LED off)");
}
}
lastBtn = btn;
int angle = 0;
if (sweepMode == 1) {
sweepAngle = sweepAngle + 5 * sweepDir;
if (sweepAngle >= 180) { sweepAngle = 180; sweepDir = -1; }
if (sweepAngle <= 0) { sweepAngle = 0; sweepDir = 1; }
angle = sweepAngle;
} else {
int raw = analogRead(PIN_POT);
angle = map(raw, 0, 4095, 0, 180);
}
horn.write(angle);
tick = tick + 1;
if (tick >= 20) {
tick = 0;
if (sweepMode == 1) {
Serial.print("sweep angle=");
} else {
Serial.print("knob angle=");
}
Serial.println(angle);
}
delay(50);
}Built with FluxBench.AI — the AI workbench for embedded projects.