Introduction
Here we will control a servo by rotating a 10k potentiometer, with Arduino Uno as controller. But before going through this tutorial, i suggest you go through this basic introductory article on Servos.
The 10k pot is connected to one of the analog pins and the servo is connected to one of the pwm pins of the arduino board.
A servo can be made to turn to any angle between 0 to 180 degrees by using Arduino’s inbuilt Servo library.
Here we map the analog reading between 0-1023 obtained from the 10k pot to an angle between 0 – 90 degrees, by using arduino’s inbuilt map() function and use the mapped value to run the servo. This makes the servo rotate in accordance with the rotation of the 10k pot.
Breadboard Setup

Note: A servo has three wires +VCC, GND and SIGNAL . Different servos use different color codes to indicate +VCC, GND and SIGNAL .

Schematic Diagram

Code
#include<Servo.h> Servo myServo; //Declaring a Servo object int servoPin = 10; //declaring a variable to store the pin number to which the servo is connected int potValue = 0; //declaring a variable to store potentiometer analog value int potPin = 0; //10k pot connected to pin 0 of analog port int servoPosition = 0; //declaring a variable to store the angle for servo rotation void setup() { // put your setup code here, to run once: myServo.attach(servoPin); //attaching the servo object to the servo pin } void loop() { // put your main code here, to run repeatedly: potValue = analogRead(potPin); //get the analog value of 10k pot servoPosition = map(potValue,0,1023,0,180); //map the analog value of the 10k pot from a value between 0 - 1023 to a value between 0 - 180 and store it in a variable myServo.write(servoPosition); //turn the servo by the angle value stored in servoPosition variable delay(100); }
good one sandhan daa..
LikeLiked by 1 person