You will learn how to control a servo motor, to rotate between 0 to 180 degrees.
Software Discovery: Libraries
Other Discovery: Servo motors, Decoupling capacitor
Qty Part Qty
1 Servo motor
1 Capacitor [470μF]
Software Discovery: Libraries
Other Discovery: Servo motors, Decoupling capacitor
Qty Part Qty
1 Servo motor
1 Capacitor [470μF]
Resources: |
|
|
Lets get Coding! Sweep 1 - Angle control #include <Servo.h> // invoke servo library Servo myservo; // create servo object to control a servo void setup() { myservo.attach(6); // attaches the servo on pin 6 to the servo object } void loop() { myservo.write(0); // starting angle delay(2000); // duration of sweep myservo.write(90); // ending angle delay(2000); // duration of sweep } | Sweep 2 - Angle and Duration control #include <Servo.h> // invoke servo library Servo myservo; // create servo object to control a servo int pos = 0; // variable to store the servo position void setup() { myservo.attach(6); // attaches the servo on pin 6 to the servo object } void loop() { for(pos = 0; pos < 124; pos += 1) // goes from 0 degrees to 124 degrees { // in steps of 1 degree myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } for(pos = 124; pos>=1; pos-=1) // goes from 124 degrees to 0 degrees { myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } } |