working with arduino: lesson #4: servos egn1007. learning goals learning goals: the student will be...

9
Working with Arduino: Lesson #4: Servos EGN1007

Upload: moses-davidson

Post on 12-Jan-2016

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 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

Working with Arduino:Lesson #4: Servos

EGN1007

Page 2: 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

Learning Goals

Learning Goals: The student will be able to:1.Build a complete circuit using the Arduino microprocessor2.Identify important electrical components in a circuit and explain their use3.Identify and apply specific elements in “C” code used to run a program in conjunction with how a circuit is built

Page 3: 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

ServosA 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.

Page 4: 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

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.

Page 5: 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

Let’s Begin

1.Place the 3 pin header into E5,6, & 7.2.Plug the servo into the header3.Run a wire from Analog 9 to A7.4.Run a wire from the 5V to A65.Run a black wire from A5 to the ground(GND).

Page 6: 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

Programming our sketch

Let’s define 1 variable as an integer.

Page 7: 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

Programming our sketchJust like before we need to set our SERVO as an output.

Page 8: 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

Programming our sketchWe 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

Page 9: 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

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