Working with Arduino: Lesson #4: Servos EGN1007 Learning Goals Learning Goals: The student will be able to: 1. Build a complete circuit using the Arduino microprocessor 2. Identify important electrical components in a circuit and explain their use 3. Identify and apply specific elements in “C” code used to run a program in conjunction with how a circuit is built Servos A servo takes a timed pulse and converts it to an angular position. How do you communicate the angle at which the servo should turn? The control wire is used to communicate the angle. The angle is determined by the duration of a pulse that is applied to the control wire. This is called Pulse Coded Modulation. The servo expects to see a pulse every 20 milliseconds (.02 seconds). The length of the pulse will determine how far the motor turns. A 1.5 millisecond pulse, for example, will make the motor turn to the 90 degree position (often called the neutral position). If the pulse is shorter than 1.5 ms, then the motor will turn the shaft to closer to 0 degrees. If the pulse is longer than 1.5ms, the shaft turns closer to 180 degrees. Schematic Symbol? There is no symbol for a servo because it is part of an EXTERNAL circuit. The servo itself will be plugged into 3 ports somewhere on the circuit board, often represented by a 3-pin header. Let’s Begin 1. Place the 3 pin header into E5,6, & 7. 2. Plug the servo into the header 3. Run a wire from Analog 9 to A7. 4. Run a wire from the 5V to A6 5. Run a black wire from A5 to the ground(GND). Programming our sketch Let’s define 1 variable as an integer. Programming our sketch Just like before we need to set our SERVO as an output. Programming our sketch We begin by creating a variable called “pulsetime” which will record the time of the pulse that corresponds to than angular position you want. Compile and download Your turn! Using what you have learned in this lesson AND the past lessons, write a short program that controls servo using a potentiometer. Write your code on the lesson worksheet, draw the schematic, and explain your code. Hint: The POT reads values from 0 to 1024 and the servo only understands values from 0 to 180