Monday, October 10, 2011

Circuit-04 - A single Servo

Purpose: To make a Mini Servo turn

Equipment: 
  • Arduino x 1
  • Breadboard x 1
  • Arduino Holder x 1
  • CIRC-04 Breadboard Sheet x 1
  • 3 pin header x 1
  • Wire  x 5
  • Mini Servo x 1

Reference: 
Program Details:
A couple of new things are introduced in terms of hardware in this exercise. First, a 3 pin header, is used to connect the wires of a servo to the arduino board.  The other hardware introduced in this exercise is the mini servo. We learn that when connecting the servo to the 3 pin header we have to make sure that the black wire is connected to the ground source through the pin header, the red wire with the electricity/power and the white wire with the signal/pin. (pin9 if your following the schematic provided in the book)

A lot of new programming is introduced with this circuit. First we learn how to import a bunch of methods related to servo. To do this we type in #include <Servo.h>, this imports all the pre-made methods related to Servo's. Then we learn how to make a new object (servo myservo). When we do this , we make a servo object called myservo. Through myservo, we can access all the methods we imported through the first line of code. We also learn 2 new methods in the exercise. The first one, myservo.attach, uses the object (myservo) and attaches it to the servo on the pin indicated. The second method, myservo.write, tells the servo attached to the pin indicated to go to the position indicated.

To create circuit-04, we followed the schematic and the code step by step. The circuit is very easy to make but the programming is quite difficult to understand for beginners.  

Time to complete: 15 mins to assemble
                               15 mins to program

Results: Our servo ran perfectly the first time. It did exactly as it was supposed to.

Photo: 

Tips: 
  • Make sure your servo wires match up (black with ground, red with power and white with Pin/Signal)
  • Make sure the wires bring power from POWER and not DIGITAL (same with ground)

Further Work: I will try to make the motor spin in different patterns (1 degree, then 10 degrees etc...) and also see what happens when I remove the delay or increase the delay. 

Program Modifications: 
The program is the exact one from the link below, there were no modifications.

Program:
#include <Servo.h>        // imports servo class and methods
Servo myservo;             // creates a servo object called myservo 
int pos = 0;                   // integer pos stores the servo's postion (0 = 0 degrees, 180 = 180 degrees) 
void setup()                  // Runs once when program is intialized 
  myservo.attach(9);     // myservo (the servo object) is now attached to pin9 
}
void loop()                                        // everything inside the loop is repeated
  for(pos = 0; pos < 180; pos += 1)  // for loop causes servo to turn 180 degrees (in 1 degree intervals) 
  {                                  
    myservo.write(pos);                      // tells servo to go to position in variable 'pos' 
    delay(15);                                    // delays 15 milliseconds before looping 
  } 
  for(pos = 180; pos>=1; pos-=1)    // for loop causes servo to return to 0 degrees (in 1 degree intervals) 
  {                                
    myservo.write(pos);                     // tells servo to go to position in variable 'pos' 
    delay(15);                                   // delays 15 milliseconds before looping
  } 
}// ends the loop 



No comments:

Post a Comment