Servo Motor Control with Arduino and Potentiometer

Introduction: Servo motors are versatile devices commonly used in robotics, automation, and various electronic projects. In this project, we’ll explore how to control a servo motor using an Arduino microcontroller and a potentiometer. By adjusting the potentiometer, we’ll be able to precisely control the position of the servo motor, opening up a wide range of possibilities for creating interactive mechanisms and gadgets.

Components Needed: Before we begin, let’s gather the components required for this project:

  1. Arduino board (e.g., Arduino Uno)
  2. Servo motor
  3. Potentiometer (e.g., 10k ohm)
  4. Jumper wires
  5. Breadboard
  6. USB cable (for connecting Arduino to computer)
  7. Power source (battery pack or external power supply)

Circuit Connection:

  1. Connect the Signal Wire of the Servo Motor to D9: Use a male-to-male jumper wire to connect the signal wire of the servo motor to digital pin 9 on the Arduino board. The signal wire is typically colored white or yellow and is connected to the control input of the servo motor.
  2. Connect One End of the Pot to the 5V Pin on the Arduino: Use a male-to-female jumper wire to connect one end of the potentiometer to the 5V pin on the Arduino board. This provides power to the potentiometer.
  3. Connect the Other End of the Potentiometer to the GND Pin on the Arduino: Use another male-to-female jumper wire to connect the other end of the potentiometer to the GND (ground) pin on the Arduino board. This completes the circuit and provides a reference voltage for the potentiometer.
  4. Connect the Wiper/Middle Pin of the Potentiometer to A0 on the Arduino: Use a male-to-female jumper wire to connect the wiper (middle pin) of the potentiometer to analog pin A0 on the Arduino board. The wiper is the moving contact of the potentiometer and is used to vary the resistance between the two outer pins.

Arduino Sketch: Now, let’s write the Arduino sketch to control the servo motor based on the position of the potentiometer:

#include <Servo.h>

Servo myservo;  // Create a servo object

int potPin = A0;  // Analog pin connected to the potentiometer
int potValue;     // Variable to store potentiometer reading

void setup() 
{
  myservo.attach(9);  // Attach the servo to digital pin 9
}

void loop() 
{
  potValue = analogRead(potPin);  
           // Read potentiometer value (0-1023)
  int angle = map(potValue, 0, 1023, 0, 180);  
           // Map potentiometer value to servo angle (0-180)
  myservo.write(angle);  
           // Set servo position based on potentiometer reading
  delay(15);  // Delay for smoother motion (optional)
}

Operation: Upload the Arduino sketch to the Arduino board and power it up. As you rotate the potentiometer knob, the servo motor will move to correspond to the position of the potentiometer. Turning the potentiometer clockwise will move the servo in one direction, while turning it counterclockwise will move the servo in the opposite direction.

Conclusion: Controlling a servo motor using an Arduino and a potentiometer is a simple yet powerful technique that can be applied to a wide range of projects. Whether you’re building a robotic arm, a camera gimbal, or an automated door lock, mastering servo motor control opens up a world of possibilities for creativity and innovation in electronics.

Leave a Reply

Your email address will not be published. Required fields are marked *