I have a bunch of servos which I'm all running with the same code. My problem is that some of the servos get to one of the stops and shake until they go back to the other stop. It only happens on a couple of the servos, but it happens everytime no matter where or what I plug it into.
#include <Servo.h>
Servo s1; // create servo object to control a servo
Servo s2;
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
void setup() {
s2.attach(9); // attaches the servo on pin 9 to the servo object
s1.attach(10);
}
void loop() {
s2.write(90);
s1.write(90);
delay(2000);
s2.write(180);
s1.write(180);
delay(2000);
}
Are you sure that all the servos can go all the way to 180 and all the way to 0 without jamming? Try them at 20 and 160. I hope you are not trying to power servos from the Arduino 5V pin, it can't supply enough current for more than 1 teeny servo, certainly not 2 or more, you need a separate 5 or 6V supply with 1 Amp per servo minimum.
Use this sketch to test them:
/*
Try this test sketch with the Servo library to see how your
servo responds to different settings, type a position
(0 to 180) or if you type a number greater than 200 it will be
interpreted as microseconds(544 to 2400), in the top of serial
monitor and hit [ENTER], start at 90 (or 1472) and work your
way toward zero (544) 5 degrees (or 50 micros) at a time, then
toward 180 (2400).
*/
#include <Servo.h>
Servo servo;
void setup() {
// initialize serial:
Serial.begin(9600); //set serial monitor baud rate to match
servo.write(90);
servo.attach(9);
prntIt();
}
void loop() {
// if there's any serial available, read it:
while (Serial.available() > 0) {
// look for the next valid integer in the incoming serial stream:
int pos = Serial.parseInt();
pos = constrain(pos, 0, 2400);
servo.write(pos);
prntIt();
}
}
void prntIt()
{
Serial.print(" degrees = ");
Serial.print(servo.read());
Serial.print("\t");
Serial.print("microseconds = ");
Serial.println(servo.readMicroseconds());
}
756E6C:
I hope you are not trying to power servos from the Arduino 5V pin, it can't supply enough current for more than 1 teeny servo, certainly not 2 or more
I am and I noticed that using two causes the problem on both servos and using one servo it has the issue for a few seconds then goes away. I'll get an external power source and try again. Thanks!