The purpose of this assignment is to learn to control the outputs Servos and LEDs using the primary input, potentiometer.
Equipment
- 1 x Servo & Servo Arm
- 1 x 3 Pin Header
- 1 x Potentiometer
- 3 x LEDs
- 3 x 330 Ohm Resistors
- 11 x Wires
- 1 x Arduino Uno
- 1 x Breadboard & Reference Sheet
Assembly
This circuit is simply a modification of CIRC4. The servo is attached in the same way, using a pin header and the three wires (power, grounding, data). The potentiometer follows the same principle, using 3 wires. Besides the servo and the potentiometer, there are 3 additional loads, LEDs, that are attached as usual. Assembling this circuit takes from 5-7 minutes. See the images below.
Program Details
This assignment utilized the concept of a 'library' to control the servo and make the code easier. A library typically has a specific set of functions which can be called within the program. Simply introduce the library at the top of your program before using it. In the following code, the LED codes are straightforward, used in previous blogs, the only different functions are those associated with the servo library. For instance, the function 'Servo ____' introduces the servo, with a name. In void setup(), the function '_____.attach(pin#)' forms the connection between the servo and digital pin. Note that the servo doesn't need to be declared input/output. The function 'map( , , ,)' is used to scale the values to be utilized by the servo. Finally, the function '_______.write(position variable)', turns the servo to the appropriate position. See the code below, which works to turn the servo as instructed by the potentiometer. The 3 LEDs are used to indicate the direction of the servo when it is at it's initial position, 90 degrees, and at it's max position (180).
Results
The program worked well after a few modifications. As always, strict timing has to be considered. Another consideration is the initial position, which should be carefully and manually set before the program is uploaded. Otherwise, it was another excellent exercise as it was a slight challenge integrating two outputs under the influence of one form of input.
Tips include:
- connect the servo to the circuit last because it can be easily detached and lost
- avoid clutter and section off the circuit (LEDs, potentiometer, servo), there are a lot of wires
- follow the current path to make sure the appropriate wires and resistors are present and connected accordingly
- secure the servo connection with fingers if necessary
- remember the scale starts at 0 degrees
- also remember to call the library at the very start of the program
Resources
Spark Fun Inventor's Starter Guide
http://schools.tdsb.on.ca/danforthcti/arduino/ArduinoGuide.html
http://schools.tdsb.on.ca/danforthcti/arduino/ArduinoGuide.html
No comments:
Post a Comment