Mood dial on an Arduino Uno
Turn the potentiometer on A0 and the servo on pin 9 turns to match: map() stretches 0 to 1023 onto 0 to 179 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.
Build it as the Starter Projects Kit: the parts in numbered bags and a booklet that checks every step. Free.
The code
The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.
// Mood dial: turn a potentiometer and a servo points to match.
//
// potentiometer one end -> 5V, the other end -> GND, middle (wiper) -> A0
// servo brown -> GND, red -> 5V, orange -> pin 9
//
// The knob is a voltage divider: the wiper slides from 0 V to 5 V, and A0
// reads that as 0 to 1023. map() stretches 0..1023 onto the servo's 0..179
// degrees, and the horn follows the knob. Tape an arrow to the horn and a
// card of faces behind it, and it tells people how your day is going.
//
// A real servo jolts the 5 V line every time it starts to move. A 100 uF
// capacitor across the supply near the servo, as the kit book suggests, keeps
// that jolt from wobbling the knob's reading.
#include <Servo.h>
Servo pointer;
int lastAngle = -1;
void setup() {
pointer.attach(9);
Serial.begin(9600);
Serial.println("Mokxi Uno: mood dial");
}
void loop() {
int knob = analogRead(A0);
int angle = map(knob, 0, 1023, 0, 179);
pointer.write(angle);
if (angle != lastAngle) {
lastAngle = angle;
Serial.print("knob ");
Serial.print(knob);
Serial.print(", angle ");
Serial.println(angle);
}
delay(15);
}
Parts list
4 parts, plus the jumper wires. Every one is in the editor's parts bin.
- 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 1; Hobby servo pin GND
- Arduino Uno R3 pin 9; Hobby servo pin PWM
- Arduino Uno R3 pin 5V; Potentiometer pin 3; 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.