Interfacing Servo Motor With Arduino Uno
Interfacing Servo Motor With Arduino Uno
#include <Servo.h>
int potPin = 0; // New Variable potPin has added
int servoPin = 9; //declare the Arduino pin to which the servo motor’s control pin is
connected.
Servo servo; //define multiple servos
void setup()
{
servo.attach(servoPin); //link the servo object to the control pin of our servo:
}
void loop()
{
int reading = analogRead(potPin);
int angle = map(reading, 0, 1023, 0, 180);
servo.write(angle); // update the servo’s position to the angle selected by the
potentiometer.
}