servo motor is a modified geared motor whose rotation can be controlled using micro-controller. One  can easily control  servo motor to desired degree of rotation, by using a potentiometer & arduino. most of us For should have basic knowledge about arduino pwm & analog input features.

components:

  1. 1x – Arduino board
  2. 1x – MG 995 Servo motor (you can use any model)
  3. 1x – 10k Potentiometer

Steps:

1. Connect the servo motor to the arduino UNO as the schematic (be aware of connecting 5v & gnd, orange one is the signal wire which should be connected to pin 9 )

2. connect the potentiometer correctly to arduino. Left & Right pin should be connected to VCC & GND respectively. The third pin (middle) should be connected to analog pin A0.

3. Compile the code & upload it to arduino.

 

Arduino Code:

#include<Servo.h>
Servo myservo; // create servo object to control a servo
int potpin = 0;    // analog pin0 to connect the potentiometer
int value;
void setup()
{
myservo.attach(9);  // attach the servo on pin 9
}
void loop()
{
value = analogRead(potpin); // reads the value of potentimeter (between 0 to 1023)
value = map(value,0,1023,0,180); //scale it for using with servo
myservo.write(value); // sets the servo position
delay(15); // waits 15 miliseconds
}

Leave a Reply

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