I have a servo connected to my Arduino Uno. It functions perfectly with my modified Sweep function as well as the original example code if the circuit is powered via the Arduino's USB. However if I then power it externally from a battery, the behaviour is very different - it swings quickly from side to side past the desired point, and modifying the Sweep delays in the code does not affect this speed.
It is powered by a 9v battery, regulated down to 5v through an MD25. The ground connections between the Servo and the Arduino are connected, and I have tried installing a 470uF capacitor across the servo power leads.
Does anyone please know what the problem could possibly be??? D:
void sweepServo (Servo servo, int finalAngle, int slowness){
finalAngle = constrain(finalAngle, 0, 180);
int dir;
int pos = servo.read();
if (pos > finalAngle){
dir = -1;
} else {
dir = 1;
}
for (; pos != finalAngle; pos += dir){
servo.write(pos);
delay(slowness);
}
}
Does the MD25 documentation recommend a "9V battery"?
Those batteries, 9V batteries ("transistor batteries", etc.), are good for next to nothing - they don't have the juice.
You could do better to make up your own 9V battery pack with AA or C cells, one suggestion.
Running servos through regulators is chancey. Providing them 6V right from batteries is probably best (from my perspective.)
So I'm using this Servo in my project with an Arduino Uno.
For some unknown reason, when the servo is powered from the 3.3v pin, it behaves perfectly, going to the correct position, but when powered by 5v or more its behaviour becomes very erratic, often flicking randomly from side to side.
Does anyone know why this could be? I need it to run off 5v because I need the higher torque. I've got a 470uF capacitor across the servo power supply, and the ground pins are connected.
What is extremely peculiar here is the suggestion that you could ever power a servo from the 3.3V output. You may just get away with powering it from the 5 V pin if the UNO is powered from the USB though even that is not advisable.
I think we need a clear diagram or perfectly focused and lit (in daylight) photograph of just how you are actually connecting it in each case, before passing judgement.
Wiring is literally straight into the Arduino. A quick test across the servo shows the voltage from the 3.3v pin is more like 3.8v, which would explain how the servo is powering at this low voltage.
However the issue is still why is it behaving erratically when powered with 5V?!
This thread is about "Weird Servo Behaviour" and your other recent thread is about "Servo Misbehaving on Battery Power" (or vice-versa) so I think I'll merge them. Please don't cross-post. We were getting somewhere with your other thread, I think.
Wiring is literally straight into the Arduino. A quick test across the servo shows the voltage from the 3.3v pin is more like 3.8v, which would explain how the servo is powering at this low voltage.
This is a BAD IDEA. The Arduino was never designed to power motors from either the 5V or 3.3V pins.
I'm not buying that. The 3.3V regulator WILL NOT output 3.8 V , period. Your measurement is innaccurate. There has to be some other explanstion. 3.3 V LDOs that output 3.8 V are ad common as elephants that fly.
UPDATE: I checked the voltage across the servos, and it reads as 3.9v when plugged into the computer, but 4.9v when powered by the battery.
This would tell you that the servo is pulling down the USB 5V to 3.9V, but the battery is able to supply more current (than the USB). USB is typically 500mA so if you measure the servo current it is probably going above that.