My project has a couple of servos connected to it, they are powered from an external battery source but that source also powers the Arduino via the Vin pin.
If the servos move quickly and erratically enough the Arduino will freeze for a second which is very bad for what I want to do
After a lot of narrowing down I'm pretty confident it is the servos hogging power but I can't think how to solve this issue; would a large decoupling capacitor on the Vin pin help or are there other ways around this?
Maybe tell us what kind of batteries you are using right now.
9V-batteries are really not good for driving either the Arduino or your servos!
Get some battery holders like these:
One with 6 cells for the Arduino, and one with 4 cells for powering the Servos
You will get most out of your batteries, if you take the holder with 6 cells, and remove one cell, and solder a link, so it's effectively a 5-cell battery holder - this way the least amount of precious energy is lost in the voltage regulator in your Arduino.
It's a little complicated, power comes from a Futaba model aircraft receiver that is being powered by a speed controller connected to a lithium battery; the idea was to fit my project to a model aircraft and have it run off the planes on board battery, the receiver can already drive multiple servos so I had hoped it would be able to do the same for the Arduino.
Powering sensitive digital electronics from the same supply rail as noisy high-current
servos and motors is best avoided, 90% of all servo issues on this forum result from
hoping you can get away with it.
You can get away with if you know what you are doing and implement good
noise filtering and provide a high enough current supply for all load-combinations,
but honestly its much easier to power servos/motors from a separate supply to the
Arduino.
Oddwired:
It's a little complicated, power comes from a Futaba model aircraft receiver that is being powered by a speed controller connected to a lithium battery; the idea was to fit my project to a model aircraft and have it run off the planes on board battery, the receiver can already drive multiple servos so I had hoped it would be able to do the same for the Arduino.
If this is your setup, you get 6V from your BEC in your ESC.
Powering the Arduino from 6V is not trivial, so my best guess is that you did something wrong already.
I have powered Arduino's from ESC's by the means of a standard silicon diode in series with the 6V-supply. The voltage drop over a standard diode is about 0.6-0.7V - which brings you into the "safe" voltage range for the 5V-pin.
Connect the 6V supply from your ESC/Receiver to the Arduino thru a diode, to the 5V-pin. Do not use the VIN-pin for anything.
Oddwired:
Thanks I'll give the separate supply solution a go first.
Zap, Power the Arduino by putting power into the 5v output pin?
Yes. Just make sure that you do not plug anything into the DC-jack or the VIN-connector, as this could destroy the voltage regulator on board (in this case, the voltage regulator "sees" voltage the wrong way round, which it cannot tolerate)
Below is a setup I've used for a long time to protect a servo control chip from a brownout due to high starting power requirements of servos. A large capacitor is used to help maintain chip voltage during the low voltage transient, and a diode is used to prevent the capacitor from trying to back feed the power header when the power header goes low (like a check valve in a mechanical system).