In this lesson, you will learn how to control a servo motor using an Arduino.
You will add a "pot" to control the position of the servo.
#include <Servo.h>
int servoPin = 9;
Servo servo;
int angle = 0; // servo position in degrees
void setup()
{
servo.attach(servoPin);
}
void loop()
{
// scan from 0 to 180 degrees
for(angle = 0; angle < 180; angle++)
{
servo.write(angle);
delay(15);
}
// now scan back from 180 to 0 degrees
for(angle = 180; angle > 0; angle--)
{
servo.write(angle);
delay(15);
}
}
You can do it, too! Sign up for free now at https://www.jimdo.com