Analog Input to servo motor using Arduino

The servo motors are used in many applications, this motor works with input pulse and rotation depends on input pulse duration. Here the rotation of variable resistor imitate by the rotation of servo motor.(A servo is a rotary actuator)




In this project variable resistor connected with analog input pin A0 and the servo motor pulse pin connected with digital pin D9, this pin can give pwm pulse.

Range of variable resistor is converted into digital value and the corresponding pulse width modulation (PWM) pulse is given to servo motor through digital pin D9. Hence we can get rotation from servo motor while we vary resistor value.
Analog-Input-Servo

Circuit diagram

Analog-Input-Servo-circuit

 

Analog Input to servo arduino sketch code

[code]

#include <Servo.h>

Servo myservo;

int potpin = 0;
int val;

void setup()
{
myservo.attach(9);
}

void loop()
{
val = analogRead(potpin);
val = map(val, 0, 1023, 0, 180);
myservo.write(val);
delay(15);

}

[/code]

 



Components List

S.No Name Quantity
1. Arduino uno 1
2. Variable resistor 1
3. servo motor 1
4. Connecting wires as required

2 Comments

  1. Shashi January 22, 2016 Reply
    • adminAuthor January 25, 2016 Reply

Add a Comment

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