Tuesday, 1 November 2011

CIRC-04: Servos

Purpose: 
Change LED on and off  the mini servo knob.

Equipment:
•1 x Arduino Uno
•1 x Breadboard
5 x Wire
•1 x Mini Servo
·    •1 x 3 Pin Header
·  
Reference:
http://www.oomlout.com/a/products/ardx/circ-04

Program Details: 
Servos are initialized the same way LEDs are. Objects and imports were used in the code.

Time to Complete: 
10 minutes

Results:
Done without a problem. The LED turned on when the servo was > 180 degrees and off when < 180 degrees.


Photos of Project: 


Tips:
Just like the LEDs, motors, and wires, the servos has a right way and a wrong way. If your LED isn't lighting up, try rotating the servos 180 degrees.

Further Work:
Create many different cases that will turn the LED on and off and different angles of rotation.


Program Modifications:
The program is exactly the one from http://www.oomlout.com/a/products/ardx/circ-04

Program:
#include <Servo.h> //imports directory Servo.h
Servo myservo;
                
int pos = 0; //Variable of the angle of rotation on the servo.

void setup()
{
  myservo.attach(9); //Attach to Pin 9
}

void loop()
{
  for(pos = 0; pos < 180; pos +=1)
  {                                  
    myservo.write(pos);
    delay(15);
  }

  for(pos = 180; pos>=1; pos-=1)
  {                               
    myservo.write(pos);
    delay(15);
  }
}

No comments:

Post a Comment