Friday, October 21, 2011

A Single Servo (CIRC-04)

PURPOSE:
To rotate a hobby servo from 0 to 180 degrees and from 180 to 0 degrees.
EQUIPMENT:

·         1 x Arduino Holder
·         1 x Breadboard
·         1 x Arduino Uno
·         1 x 3 Pin Header
·         1 x Mini Servo
·         5 x Wire (any color)
·         1 x CIRC-04 Breadboard Sheet
PROGRAM DETAILS:
Circ-04-servo-extra.png
Schematic Diagram, showing current flows in  the circuit
In CIRC-04, the main component introduced is the Hobby Servo which takes a timed pulse and converts it into an angular position of the output shaft. Servos make the movement inside a small gearbox more powerful and easier to control. They are widely available and cost about couple of dollars to hundreds. Power, ground, and signal are the three wires servos have. The red wire is the power wire which needs to be connected to the 5V pin on the Arduino board. The black/brown wire is the ground wire which needs to be connected to a ground pin on the Arduino board. The yellow, orange or white pin is the signal pin which needs to be connected to a digital pin on the Arduino board. A standard servo can rotate back and forth from 0-180 degrees. The rotating is controlled and timed; between 1.25 milliseconds (0 degrees) and 1.75milliseconds (180degrees). *Note* the servo runs smoothly if the pulse is sent every 25-50 milliseconds.
In terms of software, a new library called Servo.h is introduced and is brought in the code in this way: #include <Servo.h>. In the code, the very next line is: Servo myServo which creates a servo object to control a servo (the concept of creating objects was first introduced in this circuit lab as well). Moreover, a term from the Servo Library is introduced here and that is, Sweep: sweeps the shaft of a servo motor back and forth. In this circuit lab, we also got to learn about the two new methods attach()and write(). The method attach() can only attach the Servo variable to pin 9 or 10 (for our lab, it is pin 9). The method write() writes a value(angle) to the servo, controlling the shaft accordingly.
Putting circuits together is the most fun and easiest task. The 5 wires were attached to the breadboard as instructed. The 3 pin header helped to hold the 3 servo leads in place.
TIME TO COMPLETE:
10 minutes to build the circuit and 8 minutes to program it.
RESULTS:
At first, the connection between the 3 pin header and the hobby servo was lose but after I connected it again and made it tighter, the servo rotated and the program ran successfully.
PHOTOS OF PROJECT:
 
Final and Functional Circuit

TIPS:
The plug of the servo is not polarized so ensure that it is plugged in the right way.
FURTHER WORK:
To improve this circuit lab, I could adjust the rotating angle and speed of the servo motor. I can adjust the angle of degree by adjusting the for loop. For example, making pos < 90 will make the 90 degrees of rotation. I can also adjust the speed by modifying the delay time and making it a smaller number for a faster rotation, or a bigger number for a slower rotation.

PROGRAM MODIFICATIONS:
My program is the exact same program as the one from the following link:

PROGRAM (with comments):
// Sweep
// by BARRAGAN
 

#include <Servo.h>
Servo myservo;  // create servo object to control a servo
                // a maximum of eight servo objects can be created

int pos = 0;    // variable to store the servo position
void setup()
{
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}

void loop()
{
  for(pos = 0; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees
  {                                  // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for(pos = 180; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees
  {                             
    myservo.write(pos);              // tell servo to go to position in variable ‘pos’
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}


REFERENCE:

No comments:

Post a Comment