From the course: Learning Arduino: Pulse Width Modulation

Unlock the full course today

Join today to access over 23,100 courses taught by industry experts.

Implementing basic servo control

Implementing basic servo control - Arduino Tutorial

From the course: Learning Arduino: Pulse Width Modulation

Implementing basic servo control

- Controlling a servo with the Arduino requires just a few steps. The servo I'm using in this example is a basic hobby servo. It can rotate up to 180 degrees. There is no speed control on this type of servo. You can only control the angle. The servo comes with a few attachments so you can connect it for various uses. in the Arduino IDE I will select Files, Examples, Servo, Sweep. This short example is very similar to the fade example we saw earlier. The servo will simply move from zero degrees to 180 degrees back and forth. On line 10 the servo library is included in the program. As you work with new components you may find that they come with their own libraries. You can read more about libraries on the Arduino website. On line 12 the program creates an object of type servo called myservo. In the setup function myservo is attached to pin 9. Finally down in the loop the program simply counts up to 180 and then down from 180. When the loop concludes the program starts over again. I'll…

Contents