A knob on A0 points the servo on pin 3, on an Arduino Uno
A potentiometer on A0 sets the angle of a servo on pin 3: the reading from 0 to 1023 becomes an angle from 0 to 180 degrees. The whole build, an Arduino Uno and 2 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.
Teaching? Assign it to your class in one click.
Beginner Runs in your browser. Free, and no account needed.
The parts retail for about $33. On Mokxi they're free.
The code
The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.
// A knob points a servo: A0 in, pin 3 out.
//
// servo signal -> pin 3 red -> 5V brown -> GND
// the knob's ends -> 5V and GND, its wiper -> A0
//
// map() scales the knob's 0 to 1023 into 0 to 180 degrees.
#include <Servo.h>
Servo horn;
void setup() {
horn.attach(3);
Serial.begin(9600);
Serial.println("Mokxi Uno: turn the knob to point the servo");
}
void loop() {
int angle = map(analogRead(A0), 0, 1023, 0, 180);
horn.write(angle);
delay(15);
}
Parts list
4 parts, plus the jumper wires. They retail for about $33; on Mokxi they're free.
- 1 × Arduino Uno R3
- 1 × Half breadboard
- 1 × Potentiometer
- 1 × Hobby servo
How it is wired
4 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.
- Ground: Arduino Uno R3 pin GND; Potentiometer pin 3; Hobby servo pin GND
- Arduino Uno R3 pin 3; Hobby servo pin PWM
- Arduino Uno R3 pin 5V; Potentiometer pin 1; Hobby servo pin VCC
- Arduino Uno R3 pin A0; Potentiometer pin 2
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.