Let's Make Robots!

Arduino servo twitching

Servo twitching. I know, simple stuff, but it's interesting to play with on new hardware. Another Arduino example "sketch" (they got a number of these) called Sweep simply moves a servo through a set range, back and forth. Just looking at the sketch (listed at bottom) this timeshows a servo controlsignla connected to pin 9. They recommend using the boards 5 volts to power the servo, which is coming from the USB connection. If I'd had a bigger servo, or was under load, it might be appraoching the 500 mA USB limit (or is it more now?). ANyway, here's the servo, and the seperation of the yellow signal wire from the power wires.

cap_008.jpg  cap_011.jpg

All that is required is to pry the little bit of plastic up that is holding the metal pin in the housing, letting it slip out.

The +5 and ground pins are by each other on the bottom of the board, and pin9 is up top, and is a PWM pin, I wonder why? : )  So it's just plug everything in, load up the sketch and off we go.  Intersting thing, the flashing LED code was still in, running, and apparently something was going on with pin 9 since the servo was twitching ever now and then. Little glitch, just something to keep in mind. Below is the connections, and even further below, a little video of it moving. Aww, ain't that cute. Fun stuff!

 cap_013.jpg

 

 

// Sweep
// by BARRAGAN <http://barraganstudio.com>

#include <Servo.h>

Servo myservo; // create servo object to control a servo

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
}
}
 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

It`s still 500mA as far as I know so I wouldn`t try testing the servos torque, hehe :D

BTW you have the same keyboard I used to have. So much easier to use, I wish I still had it. When I moved and left my keyboard behind it took about 3 months of typing like a 5 year old before I got used to the normal layout again.