You are on page 1of 3

VANDERBILT UNIVERSITY

Department of Electrical Engineering and Computer Science

ES 140x EE Introduction to Engineering Fall 2021


Electrical Engineering Module
Prelab 7: Servos

Introduction
Pulse width modulation is one of the ways that we can control analog peripherals with a digital
signal from a microcontroller. We could control the speed of a motor by switching the potential
difference between 0 and 5V, but for relatively long switching times the response would be
unacceptable. However, if our switching time is sufficiently fast for the application, the response
appears as a smooth motion. Rather than burdening the microcontroller with the task of
switching the output, we will allow the PWM function to operate independently of the code. By
offloading the job of generating a repeating pulse to hardware, the software is freed up to do
other tasks.

In effect, a pulsed digital signal controls the amount of power delivered to a peripheral. The
signal duty cycle determines the power output. The longer duty cycle, the more power delivered
(under ideal, no load situations). In this manner we can control peripheral components such as
LEDs, motors, servos, electromagnets, and solenoids. In this lab you will use a special type of
motor called a servo. Servos use negative feedback to provide position control.

To operate, this servo expects a fixed pulse period of 20 ms and pulse widths between 0.750 and
2.2 ms. Not all analog servos have the same pulse width range, but widths outside the valid range
will overdrive this motor and possibly damage it. The microcontroller keeps time by counting the
cycles relative to an internal clock running at 2MHz.

How many cycles pass during 20 ms? How many during 0.750 ms? How many during 2.2 ms?

--- YOU MAY STOP HERE AND WE WILL DO THE REST IN CLASS ---
VANDERBILT UNIVERSITY
Department of Electrical Engineering and Computer Science

ES 140x EE Introduction to Engineering Fall 2021


Electrical Engineering Module
Lab 7: Servos

For this experiment each group will need a laptop, USB cable, Arduino Uno controller board,
ProtoShield board, jumper wires, a potentiometer, and a servo.

1. Build
Build the following circuit. Note: the servo connector wires are - (black), + (red), and pulse
(white). The pulse wire must be connected to D9, a digital output with controllable pulse width
modulation (PWM). The servo will buzz a little, but if you hear or see shaking, there may be
something wrong with your circuit and you should unplug the servo.

2.1 Program
Use the Examples / 01. Basics / AnalogReadSerial to print the input A0. While holding the base
of the potentiometer for support, turn the knob and observe the output in the Serial Monitor.
2.2 Program
Download and open the ClassServo.ino file from Brightspace. This code sets internal timers in
the microcontroller to generate a repeating pulse with a specified pulse width. Every 50 ms, the
microcontroller checks the input from the potentiometer and updates the pulse width accordingly.
At the top of the file, fill in the missing number of clock cycles.

3. Observe
Experiment with the circuit by changing the pulse width via the potentiometer. What does
changing the pulse width do to the servo?

4. Clean up
As you finish, make sure that everyone in your group understands and agrees upon the results
obtained in this lab. Place your hardware back in the case.

Finally, log on to Brightspace to enter your lab results and answer the post lab questions. This
can be done with your group, and even outside of class, but must be done before next class.

You might also like