Arduino Servo Potentiometer usage

Using a potentiometer to turn a servo via an arduino uno, and some code.

Here is the video

#include <Servo.h> Servo myservo; // create servo object to control a servo int sensorPin = A0; // select the input pin for the potentiometer int servoPin = 13; // select the pin for the LED int sensorValue = 0; // variable to store the value coming from the sensor int val; void setup() { Serial.begin(9600); myservo.attach(servoPin); } void loop() { // read the value from the sensor: sensorValue = analogRead(sensorPin); Serial.println(sensorValue); val = map(sensorValue, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180) myservo.write(val); // sets the servo position according to the scaled value delay(15); }

Leave a comment