Sunday, June 20, 2010

Arduino Simple Servo code

int servoPin = 7; // R/C Servo connected to digital pin
int myAngle; // angle of the servo (roughly in degrees) 0-180
int pulseWidth; // function variable

void servoPulse(int servoPin, int myAngle) {
pulseWidth = (myAngle * 11) + 500; // converts angle to microseconds
digitalWrite(servoPin, HIGH); // set servo high
delayMicroseconds(pulseWidth); // wait a very small amount
digitalWrite(servoPin, LOW); // set servo low
delay(20); // refresh cycle of typical servos (20 ms)
}

void setup() {
pinMode(servoPin, OUTPUT); // set servoPin pin as output
}

void loop() {
// cycle through every angle (rotate the servo 180 slowly)
for (myAngle=0; myAngle<=180; myAngle++) {
servoPulse(servoPin, myAngle);
}
delay(1000);
}
Related Posts Plugin for WordPress, Blogger...
Disclaimer: All the information in this blog is just gathered from different sites in the web and placed here and I am not the owner for these content

Popular Projects

Followers

My Blog List

Give Support

Give Support
Encourage me Through Comments & by Following