Monday, October 10, 2011

A Single Servo (CIRC-04)

Purpose
     To control a servo, which rotates by changing angles.

Equipment
  • 1 x 3 Pin Header
  • 1 x Mini Servo
  • 5 x Wire
  • 1 x Breadboard Sheet
  • 1 x Breadboard
  • 1 x Arduino Uno
Program Details
     
     Assembling the following circuit is not the most intimidating task. The wires are simply plugged as instructed. The 3 pin header helps to hold the servo connection in place. Complete assembly of the circuit takes about 4-8 minutes. See the assembled circuit below.




The images of above show the assembled and functional circuit.


The vocabulary used to program the servo is to some degree new, but easy. The key is to understand what controls the servo, that is position, ranging from 0 to 180 degrees. Accordingly, the program leads the servo to rotate a degree every 15 ms until it reaches 180 degrees, then rotate back to 0 degrees in the same manner. The variable 'pos' is assigned to do this. It is astonishing that a function as simple as this can be applied in something as big as an airport. 


Results


     First the connector between the servo and the 3 pin header was lose, so the servo did not pin. However after securing this connection, the servo rotated as programmed. 


Tips


     Simply make sure the connection between the pin header and servo is secure before uploading the program. Also make sure the values assigned to the variable 'pos' is within the limit (0-180).


Next Steps & Associated Program


     A slightly more complicated approach to controlling the servo would be changing the pulse directly, versus making the servo an object controlled by position. While the servo is on, it turns, for the allotted time, then it turns off, and repeats this function. See the code below.



 int servoPin = 7; //the servo is connected to pin 7, note the assembly should match this too

 void setup()
 {
   pinMode(servoPin,OUTPUT); //initialize the pin, set up purposes
 }

 void loop()//the following segment is repeated
 {
   int pulseTime=2100; //amount of time the servo will be on
   digitalWrite (servoPin, HIGH);//turn the servo on, it turns
   delayMicroseconds(pulseTime);//leave it turned on for this long
   digitalWrite (servoPin, LOW);//turn the servo off
   delay (25);//wait 25ms before repeating the segment
 }

Simply referred to the Sparkfun Inventor's Guide.

No comments:

Post a Comment