Control a Servo Motor with a Potentiometer using Arduino (Code & Circuit)

Huge thanks to all the subscribers! My recent video on this project has already crossed 20,000 views. Since so many of you requested the details, I’m writing this post to share the full setup and code.

This project demonstrates how to control a Servo Motor using a Potentiometer. By rotating the potentiometer, the Arduino reads the analog signal and converts it into a precise angle for the servo, making it a perfect foundation for robotics projects.

Wiring Connections

Component Arduino Pin
Potentiometer (Center Pin) Analog A0
Potentiometer (Side Pin 1) 5V
Potentiometer (Side Pin 2) GND
Servo Signal (Orange/Yellow) Digital Pin 7
Servo VCC (Red) 5V
Servo GND (Brown/Black) GND

Arduino Code

#include<Servo.h> // add servo library Servo myservo; // create servo object to control a servo int pot=A0; // analog pin used to connect the potentiometer int pot_out; // variable to read the value from the potentiometer pin int value; // After mapping, we need a variable to store the data i.e value void setup() { pinMode(pot, INPUT); //Declaring A0 pin is our INPUT pin myservo.attach(7); //Servo is attaches to the pin 7 Serial.begin(9600); //initialise serial monitor } void loop() { pot_out=analogRead(pot); value= map(pot_out, 0, 1023, 0, 180); myservo.write(value); Serial.println(pot_out); }

Project Video

Popular posts from this blog

Formula to Get Country Flags in Google Sheets

Steps to Turn On Offline Access for Google Docs, Sheets and Slides