deckle studioOpen in the editor

Arduino Uno: servo follows the potentiometer

Potentiometer sets the servo angle.

  • Arduino Uno
  • SG90 servo
Open in the simulatorNo account needed: press Simulate and it runs.

How it works

Potentiometer RV1 on A0 sets the angle of the SG90 servo on D9 (Servo library, 50 Hz pulses from Timer1). Turn the potentiometer during the simulation: the servo arm rotates in the schematic at its real speed (0.1 s / 60°).

Wiring

Each line is one connection (net) and the pins it joins.

NetPins
GNDA1 GNDM1 GNDRV1 2V1 −
5VA1 5VM1 5VRV1 1V1 +
POTA1 A0RV1 W
SIGA1 ~D9M1 SIG

Parts

Firmware

sketch.ino · 15 lines

// Pot on A0 sets the angle of the servo on D9 (0..180°)
#include <Servo.h>
Servo servo;

void setup() {
  Serial.begin(115200);
  servo.attach(9);
}

void loop() {
  int angle = map(analogRead(A0), 0, 1023, 0, 180);
  servo.write(angle);
  Serial.print(F("Angle: ")); Serial.println(angle);
  delay(50);
}
Open in the simulator

More examples: Arduino