I'm attempting to use servos with an arduino for the first time and I'm somewhat stumped at the moment. I don't think the problem is with the arduino code, but I would appreciate any insights at all. To simplify my tests, I'm currently using the Servo library Knob demo (adjusts servo position based on voltage input from a pot).
I needed a high torque servo for my project and ordered several TowerPro MG958 servos. When I hooked one up, the servo just clicked (at about 3 Hz) and didn't move. I tried using a lower torque Futaba servo that I had and it seemed to work fine. I thought that perhaps the TowerPro was broken, so I tried another TowerPro with the same results. I took the TowerPro servos to a local hobby store and they were nice enough to try them out in an RC Car receiver and they worked fine. So something is apparently wrong with my setup at home.
I am powering the servo separately from the arduino using an adjustable voltage bench top supply capable of supplying 3 A. I have tried running this from 4.8-6.6V. The grounds are in common for both the arduino and the servo. I had a 220 ohm current limiting resistor in line with the signal to the servo, but have also tried without this.
When looking at the signal on a scope, it looks great. I see a .8-2.5 mSec pulse (based on the pot position) every 20 mSec.
I can't figure out why the TowerPro servos won't work with this arduino setup, but work fine in an RC receiver. Something's obviously different, but I can't figure it out. Unfortunately, I don't have an RC receiver at home where the scope is. Anyone have any ideas?
What is the voltage across the servos power leads while it is clicking? Make sure the servo negative power lead is connected to Arduino GND. Try your servo with this test program: Connect servo signal wire to pin 9.
/*
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());
}
Thanks for the suggestions. This led me to the solution.
I measured the supply voltage with a voltmeter and was getting a steady 5V, but when I looked at it with a scope, I saw regular short spikes where it dropped down below 4V. My fancy regulated bench top power supply couldn't actually supply the needed current for these spikes. It looks like the servo even at rest with no load was pulling very short spikes of over 1A. With my bench supply, this was causing the voltage to drop enough that the servo was not functioning. After I switched to using an RC lipoly battery, it seems to work fine.