Digital servo’s are used for a number of applications for example RC toys, drones, biped robots for joint movement. Servo’s range in sizes and prices
When working with servo’s we are using Pulse Width Modulation(PWM) for controlling the servo. In the video below we can see that there three positions set on circular arrows. When we look at the straight ahead or 90 degree position our PWD is set at cycle rate of 1.5ms. If this cycle rate changes to a rate of 1ms the position of our servo moves to the 0 degree position. If this cycle rate changes to a rate of 2ms the position of our servo moves to the 180 degree position.
Lets look at a simple program for moving the servo from position 0 to 90 then to 180.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
#include <Servo.h> SERVO=8; // Assign the variable SERVO to pin 8 on the Arduino Servo myServo; // Assign Servo to myServo void setup() { myServo.attach(SERVO); } void loop() { myServo.digitalWrite(0); // Move the servo to position 0 degree's delay(5000); // 5 second delay myServo.digitalWrite(90); // Move the servo to position 90 Degree's delay(5000); // 5 second delay myServo.digitalWrite(180); // Move the servo to position 180 Degree's delay(5000); // 5 second delay } |