From the course: Learning Arduino: Pulse Width Modulation

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Controlling a servo with an analog input

Controlling a servo with an analog input - Arduino Tutorial

From the course: Learning Arduino: Pulse Width Modulation

Start my 1-month free trial

Controlling a servo with an analog input

- With just a few additions, I can control the angle of the servo with the potentiometer. In the Arduino IDE, I will select File, Examples, Servo, Knob. With the potentiometer attached to pin A zero, I will upload the code. This example should be familiar in form. This program uses the map function to scale the value red from the potentiometer, to a corresponding angle of rotation on the servo. As I adjust the position of the potentiometer, the servo moves in time. (servo makes buzzing sound) Notice the small buzzing sound I hear when I turn the servo all the way up. You may have also heard this buzzing noise when the servo reached the top and low end of the sweep program. This has to do with manufacturing standards. Some servos simply won't turn the full 180 degrees. This is why it's important to test your servo ahead of time and find the correct operational range for your particular device. If I were to simply add an arm to the end of the Arduino, you could see how I could control a…

Contents