Arduino Servo freeze

I'm having an occasional issue with my project which uses several high power servos. I have the servos on a separate power supply with more than enough amps to power them. The arduino is powered via USB and has a common ground with the power supply.

Initially things worked correctly but when I added some extra servos and had a few of them drawing more current together, they occasionally freeze once the power draw goes to around 5 amps. Frustratingly, it's not every time. If they don't freeze in the first minute, they seems to be fine but occasionally the first initial surge of current freezes them until I unplug and reconnect the arduino USB. The power supply should be good for at least 20 amps so I don't think that is my issue.

I'm guessing it could be noise affecting the signal lines? I tried putting a ferrite choke on the cable but this doesn't seem to do much. Are diodes my answer? I'm a total electronics beginner. Can anyone help? :frowning:

Since you have not supplied a schematic or any code, people can only guess.

If it were a power issue, your arduino would reset. Does it? Do you have debug statements coming out to the Serial Monitor?

If you are drawing lots of current, your driver board and/or servo could be shutting down due to over temperature. Are they getting hot?

Hi,
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

How have you got your gnds connected, are you using heavy enough wire to power the servos?

Thanks.. Tom..... :slight_smile:

As Tom says it can easily still be a power problem but with the wiring rather than the power supply itself. I have seen people trying to connect high power servos via breadboards and using crocodile clips or even twisted wire connections. They have power problems!

A picture of your setup showing all components and wiring might give us some ideas.

Steve

I don’t think it is an overheating problem as if I don’t get an initial freeze, it powers away for a good hour without any issues. It could be a power problem from the connections being too thin, but would this cause a freeze? Initially I definitely didn’t have thick enough wires as when several servos were stalling at once, they would lose power/torque. The freezing started after adding in thicker wires and I don’t get any drop in power (or eratic servo movement when the voltage drops) but instead the servo stops at its current position and doesn’t move until I unplug and replug the arduino. I seem to get full power otherwise as long as it keeps going.

Here’s my schematic:

The image doesn’t seem to be showing, so I’ve attached it instead.

Here’s my code:

#include <Servo.h>

const int kActuatorCount = 3;                       


const char kActuatorName[kActuatorCount] = { 'A', 'B', 'C' };
const int kPins[kActuatorCount] = {11, 12, 13};             
const int kActuatorScale[kActuatorCount][2] = { { 15, 179 } ,    
                                                { 179, 0 } ,    
                                                { 15, 165 } ,    
                                                                                               };     
const char kEOL = ']';                              
const int kMaxCharCount = 3;                        
Servo actuatorSet[kActuatorCount];                  
int actuatorPosition[kActuatorCount] = {15, 179, 15};    
int currentActuator;                                
int valueCharCount = 0;                             

enum TPortState { psReadActuator, psReadValue };   
TPortState currentState = psReadActuator;

void setup()
{
    
    for (int i = 0; i < kActuatorCount; i++)
        actuatorSet[i].attach(kPins[i]);
    
   
    for (int i = 0; i < kActuatorCount; i++)
        updateActuator(i);
    
    Serial.begin(9600); 
 
void loop()
{

}


void serialEvent() {
    char tmpChar;
    int tmpValue;

    while (Serial.available()) {
        
        if (currentState == psReadActuator) {
            tmpChar = Serial.read();
            
#ifdef DEBUG           
Serial.print("read in ");           
Serial.println(tmpChar);           
#endif
            for (int i = 0; i < kActuatorCount; i++) {
                if (tmpChar == kActuatorName[i]) {
#ifdef DEBUG           
Serial.print("which is actuator ");           
Serial.println(i);           
#endif
                    currentActuator = i;                        
                    currentState = psReadValue;                 
                    actuatorPosition[currentActuator] = 0;      
                    valueCharCount = 0;                         
                    break;
                }
            }
        }
        
        
        if (currentState == psReadValue) {
            while ((valueCharCount < kMaxCharCount) && Serial.available()) {
                tmpValue = Serial.read();
                if (tmpValue != kEOL) {
                    tmpValue = tmpValue - 48;
                    if ((tmpValue < 0) || (tmpValue > 9)) tmpValue = 0;
                    actuatorPosition[currentActuator] = actuatorPosition[currentActuator] * 10 + tmpValue;
                    valueCharCount++;
                }
                else break;
            }
            
            
            if (tmpValue == kEOL || valueCharCount == kMaxCharCount) {
#ifdef DEBUG           
Serial.print("read in ");           
Serial.println(actuatorPosition[currentActuator]);           
#endif
                
                if (actuatorPosition[currentActuator]<128) actuatorPosition[currentActuator]=0;

                
                actuatorPosition[currentActuator] = map(actuatorPosition[currentActuator], 128, 255, kActuatorScale[currentActuator][0], kActuatorScale[currentActuator][1]);
               
#ifdef DEBUG           
Serial.print("scaled to ");           
Serial.println(actuatorPosition[currentActuator]);           
#endif
                updateActuator(currentActuator);
                currentState = psReadActuator;
            }
        }
    }
}



void updateActuator(int thisActuator) {
    int safePos;
    safePos=actuatorPosition[thisActuator];
  
    actuatorSet[thisActuator].write(safePos);
}

Hi,
Ops circuit;


Can you post a picture of your project please, so we can see your component layout?

Thanks... Tom... :slight_smile:

"I'm guessing it could be noise affecting the signal lines? I tried putting a ferrite choke on the cable but this doesn't seem to do much. Are diodes my answer? I'm a total electronics beginner. Can anyone help?"

Are your wires large and soldered or are you using bread board jumpers on a bread board? Do you have the servos grounds properly connected to the arduino ground? Have you tried using the serial monitor to see what is happening with the arduino? A simple test would be to disconnect the servos from the arduino and see if the arduino still crashes.

As has been asked several times, post a pic of your project so that we can see more details of how you actually have the components arranges and wired.

zoomkat:
Are your wires large and soldered or are you using bread board jumpers on a bread board? Do you have the servos grounds properly connected to the arduino ground? Have you tried using the serial monitor to see what is happening with the arduino? A simple test would be to disconnect the servos from the arduino and see if the arduino still crashes.

The servos are remote from the arduino and are connected via a 3m 8pin Din cable. 4 of the pins are used to supply the Gnd and Voltage.

The servos are definitely connected to the arduino Gnd. There’s no crash if I don’t use any servos, use all the servos with little load or when I had a single connection from the Gnd (Though this was limiting the max current and preventing more than one servo reaching stall current). When I had a weedier connection, I wasn’t getting any freezes and instead when one servo stalled and pulled more current, the others would lose torque and occasionally would be erratic until the current dropped back down as my voltage was dropping when the amps rose. It has only been since adding a thicker Gnd wire that my voltages and amps have been able to go higher but I now suffer the occasional freeze on all servos once the amps rise.

I haven’t tried using the serial monitor so I’ll try that - thanks for the tip.

vinceherman:
As has been asked several times, post a pic of your project so that we can see more details of how you actually have the components arranges and wired.

I’ll try to post a photo to help though I’ll need to do some dismantling first!

Thanks for all your replies. I’ll try some more/thicker/shorter wires and check if anything is reported in the serial monitor. Cheers! :slight_smile:

A simple thing to do is connect a multimeter to your arduino board to monitor the board voltage, and watch the board voltage as the servos move. If your arduino has an on board LED, turn it on in the setup part of your code, then watch it for dimming or flickering during servo operation. I think most likely you have a power issue.

GWiz79:
The servos are remote from the arduino and are connected via a 3m 8pin Din cable. 4 of the pins are used to supply the Gnd and Voltage.

The servos are definitely connected to the arduino Gnd. There's no crash if I don't use any servos, use all the servos with little load or when I had a single connection from the Gnd (Though this was limiting the max current and preventing more than one servo reaching stall current). When I had a weedier connection, I wasn't getting any freezes and instead when one servo stalled and pulled more current, the others would lose torque and occasionally would be erratic until the current dropped back down as my voltage was dropping when the amps rose. It has only been since adding a thicker Gnd wire that my voltages and amps have been able to go higher but I now suffer the occasional freeze on all servos once the amps rise.

Have you got any bypass capacitors on the power wires from the control area to the servos.
Are any of the wires shielded, you could be getting servo power supply current spikes inducing a spike in the servo signal wire.
When you get a "freeze" does the servo and or the controller "freeze".
Can you use "Blink without delay" example in your code so you have a blinking "heatbeat" LED showing if the controller is still processing code.

Tom... :slight_smile:

I don't have any bypass capacitors on the power wires though I run it from a 24v supply with a buck convertor (not sure if this has some inbuilt capacitance?). I also don't have any shielding on the wires.

However, I think my problem is solved and that it was mechanical rather than electrical. I mentioned that the freezing was occasional and what was frustrating was that when I opened up my control unit, it never seemed to freeze but only when the control unit was in situ. I suspect the problem all along has been the movement of the servo was jiggling out the usb connection to the arduino causing it to freeze. At any rate, I've not had any freezes since without changing anything electrical.

So, sorry for the waste of time, but thank you for all your responses. I'll bear in mind all the useful advice in case I have any issues in the future or with additional projects. Thanks! :slight_smile: