Servo Motor Hangs Periodically (tried with 3 different motors, same board)

Hello and thank you for reading my post. This is about the reliability of servo motors when attached to an Arduino board. I have recently helped my kids with an Arduino project. The trouble is that the servo motor is not consistent in activating when the event that activates it occurs (IR signal). Sometimes the motor will get electricity triggered, make a funny clicking sound, and then not move. This occurs inconsistently. I was wondering if this is most likely due to things such as a bad connection in the board, a bad servo motor, or perhaps I just have too many items attached to the Arduino board. (I have attached to it 2 LEDs, the servo motor, and an IR sensor. Could this be confusing the circuit in some manner?) I am not that familiar with Arduino although I have gotten this configuration to work very well in terms of its basic functionality. Often, it all operate as planned, with the exception of reliability. Sometimes the servo motor just doesn’t work properly. I do have numerous other servo motors and and also Arduino boards. I can try mixing and matching. (Although I have tried 2 other servo motors and get similar results with each.) My next step would be to solder the wires together that connect the servo motor to the three ports on the Arduino board. But before I started soldering I wanted to run the situation by those on the board and see if this is typical or if I may have missed something in the diagnostic. Thank you in advance for any help.

How are the servos powered? Hopefully not from the Arduino!

Provide us the code using code tags (up to the left in this window) and attache a wiring diagram, pen and paper could do. The way You power the different parts is quite interesting.

Hi thank you for your responses.

Yes I have all the accessories connected to the board - the 3V for power; the GND for ground/return; and then 4 of the pins for signal (power for the 2 LED’s).

I don’t really know the Arduino very well. I just got this to work by reading the tutorial sections about LED lights, an IR reader, and a servo. I took those 3 different kinds of diagrams (each of which has the individual accessory with all its pins connected to the board, and then I just merged them all together into one solution.

The hand-written diagram is attached. (are you finding this readable?)

I will attached the code in another post.

Thank you again for the help!

2020-03-10_164906.jpg

Are Your servos powered by air? What power supplies are involved? Connected where?'

Here is the code. Just did this very simply, by using the templates from the tutorial for the sections on LED lights, a servo motor, and an IR reader. Made simple edits to make them work together.

//www.elegoo.com
//2016.12.08
#include <Servo.h>
#include <IRremote.h>
#include <IRremoteInt.h>

int receiver = 11; // Signal Pin of IR receiver to Arduino Digital Pin 11

/*-----( Declare objects )-----*/
IRrecv irrecv(receiver);     // create instance of 'irrecv'
decode_results results;      // create instance of 'decode_results'


Servo myservo;  // create servo object to control a servo

int pos = 0;    // variable to store the servo position
int red  = 5;
int green= 3;


/*-----( Function )-----*/
void translateIR() // takes action based on IR code received

// describing Remote IR codes 

{

  switch(results.value)

  {
  case 0xFFA25D: Serial.println("POWER"); break;
  case 0xFFE21D: Serial.println("FUNC/STOP"); break;
  case 0xFF629D: Serial.println("VOL+"); break;
  case 0xFF22DD: Serial.println("FAST BACK");    break;
  case 0xFF02FD: Serial.println("PAUSE");    break;
  case 0xFFC23D: Serial.println("FAST FORWARD");   break;
  case 0xFFE01F: Serial.println("DOWN");    break;
  case 0xFFA857: Serial.println("VOL-");    break;
  case 0xFF906F: Serial.println("UP");    break;
  case 0xFF9867: Serial.println("EQ");    break;
  case 0xFFB04F: Serial.println("ST/REPT");    break;
  case 0xFF6897: Serial.println("0");    break;
  case 0xFF30CF: 
  {
    Serial.println("1");    
    break;
  }
  case 0xFF18E7: Serial.println("2");    break;
  case 0xFF7A85: Serial.println("3");    break;
  case 0xFF10EF: Serial.println("4");    break;
  case 0xFF38C7:
  {
    Serial.println("5");    

    digitalWrite(red, LOW);
    digitalWrite(green, HIGH);

    
    for (pos = 0; pos <= 60; pos += 1) { // goes from 0 degrees to 180 degrees
      // in steps of 1 degree
      myservo.write(pos);              // tell servo to go to position in variable 'pos'
      delay(5);                       // waits 15ms for the servo to reach the position
    }
     myservo.write(0);
    delay(1000);

  digitalWrite(red, HIGH);
  digitalWrite(green, LOW);
   
   
   /* for (int thisNote = 0; thisNote < 8; thisNote++) {
      // pin8 output the voice, every scale is 0.5 sencond
      NewTone(8, melody[thisNote]);
     
      // Output the oice after several minutes
      delay(duration );
    }
*/
/*    
    for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
      // in steps of 1 degree
      myservo2.write(pos);              // tell servo to go to position in variable 'pos'
      delay(15);                       // waits 15ms for the servo to reach the position
    }
    /*
    for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
      myservo.write(pos);              // tell servo to go to position in variable 'pos'
      delay(15);                       // waits 15ms for the servo to reach the position
    }
    */

    
    break;
  }
  case 0xFF5AA5: 
  {
    Serial.println("6");
    /*
    for (pos = 0; pos <= 90; pos += 1) { // goes from 0 degrees to 180 degrees
      // in steps of 1 degree
      myservo3.write(pos);              // tell servo to go to position in variable 'pos'
      delay(15);                       // waits 15ms for the servo to reach the position
    }
    
    for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
      myservo.write(pos);              // tell servo to go to position in variable 'pos'
      delay(15);                       // waits 15ms for the servo to reach the position
    }
    */
    break;
  }
  case 0xFF42BD: 
  {
    Serial.println("Debug print");
    Serial.println("7");    
    break;}
  case 0xFF4AB5: Serial.println("8");    break;
  case 0xFF52AD: 
  {
    Serial.println("9");
   /* 
   for (pos = 0; pos <= 60; pos += 1) { // goes from 0 degrees to 180 degrees
      // in steps of 1 degree
      myservo1.write(pos);              // tell servo to go to position in variable 'pos'
      delay(15);                       // waits 15ms for the servo to reach the position
    }
    /*
    for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
      myservo.write(pos);              // tell servo to go to position in variable 'pos'
      delay(15);                       // waits 15ms for the servo to reach the position
    }
    */
    break;
  }
  case 0xFFFFFFFF: Serial.println(" REPEAT");break;  

  default: 
    Serial.println(" other button   ");

  }// End Case

  delay(500); // Do not get immediate repeat


} //END translateIR



void setup() {
Serial.begin(9600);
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  irrecv.enableIRIn(); // Start the receiver

  pinMode(red, OUTPUT);
  pinMode(green, OUTPUT);
  digitalWrite(red, HIGH);
  digitalWrite(green, LOW);
/*
 * doenst work in setup???
    myservo.write(0);
  delay(10);
  myservo.write(45);
  delay(10);
  myservo.write(90);
  delay(10);
  myservo.write(0);
 */


}

void loop() {
  myservo.write(0);
  delay(10);
 
 if (irrecv.decode(&results)) // have we received an IR signal?

  {
    translateIR(); 
    irrecv.resume(); // receive the next value
  }
}

The way the power goes to this configuration is a USB connection onto the Arduino board. It's and A-to-B USB connector. I then plug the USB cable into an Anker brand, wall-outlet powered USB charger.

(someone else posted that they said they were hoping I didn't have this powered through the Arudino board … I just am not sure which connections to what type of power source need to be made in order to avoid that since all the examples I created have each accessory fully connecting to the Ardino for power, signal and ground...)

Thanks again for your help!

USB might not provide current enough for Arduino and servos. Check up that supply.

Thank you I will have a look. How would I get more current to this configuration? Is there a way to power a servo separately than from the board? There is also a barrel connector that I can use to power the board with a 9V batter but this didn't work at all. I have a bit of a background in electricity but very little practical experience (and my intuitive grasp of it doesn't got much beyond reciting V=IR). If you tell me just approximately what to do to send power in a different manner and about what sort of parts / batteries/wires/power supply, I can search it up and wire it.

Thank you!

Check the specs for the servos. What current do they use? What is the stall current? Most likely You need a separate and better pwr supply for the servos.
The servo driver board certainly has a connection point for motor pwr.

jk_boston:
Thank you I will have a look. How would I get more current to this configuration? Is there a way to power a servo separately than from the board? There is also a barrel connector that I can use to power the board with a 9V batter but this didn't work at all. I have a bit of a background in electricity but very little practical experience (and my intuitive grasp of it doesn't got much beyond reciting V=IR). If you tell me just approximately what to do to send power in a different manner and about what sort of parts / batteries/wires/power supply, I can search it up and wire it.

Thank you!

Don't use those 9v smoke alarm batteries as they'll get you into more trouble than Flash Gordon.

Servos can pull a lot of current and can be electrically noisy to the Arduino.

Drive the servo's Positive line from 4 AA batteries.

Connect the ground of the above with the ground of a second supply of around 7.4v like a 2 cell lipo battery.

The positive of the Lipo should feed into the Arduino Raw terminal.

The Raw terminal is internally connected to a regulator in the Arduino board which gives the 5V for the board.
The servo signal wire still goes to whatever Arduino terminal.

There are also other configurations.

Great, thank you, I will have a look.

The idea of a servo driver board is new to me but I will go ahead and order one if that will fix it.

FY I have just the simple servo motors that came with the introductory Arduino kit. They are pretty small.

Just a couple questions:

  • Are there a lot of different options on these driver boards? I did a quick search and it looks like there may be. I was just looking for the very most simple that will decisively fix the problem

  • Roughly how does the wiring work ? The servo as I understand it has a wire for pulse/signal, power and ground. Do I leave the pulse wire connected directly to the Arduino and then hook the power and ground wires to the servo driver board? or, just approximately, which wires go where ? And then I can fiddle with it.

  • Should I just hook a 9V battery to the driver board and do they usually come with a barrel connector for a 9V batter connection? Or how else is power set up for these ? 2 9V batteries wired in series? Is there a better way? I’ll get any other practical set of pieces to make it work. And do some wiring. I just don’t have the electrical experience to know what specifically to do.

Thank you again for the help !

(basically any simple tutorial on how to tie in a servo driver board to an Arduino and I could probably get it sorted. But any very specific guidance in the interim and I will certainly go through it)

Thanks!

I have no idea what servos You've got. The servo pulse pin is made to connect to the Arduino. Servo driver, Arduino and all pwr supplies must have GND connected to each other.
A 9 volt battory is a poor choice. Maybe it can run an Arduino, being fed to the barrel jack but then almost nothing can be connected to the 5 volt Arduino pin.
You tell You got the servos toghether with the Arduino. Was it such a developemnt kit? In that case, have You tried the exercises in the kit?
There are servos that can be powered directly, without driver boards, but I still urge You to give the servos proper supply of current.
Is there any designation, brand and type name of the servos? Just saying "servo" is not enough.

Have no idea what

jk_boston:
Great, thank you, I will have a look.

The idea of a servo driver board is new to me but I will go ahead and order one if that will fix it.

Have no idea what you are referring to with "servo driver board".

All I said was you need another battery to drive your servo, preferably 4 AA cells.

For future reference, servo current draw( nominally expected to be close to 1 Amp) is not determined by the size of the servo.
Many electronic devices follow the same routine, i.e. size is not necessarily any form of indicator of current requirement.

@bluejets
Servo driver board migh come from my postings...

Typical servo wiring setup using an external power supply. Servos usually work best at the high end of their operating voltage band.

servo power.jpg

Thanks all for the input. I think I have a plan now, I've ordered some battery packs.

@zoomkat - in the diagram above, can the remainder of the Arduino board still be hooked up to power via the power connectors on the board itself (ie, the barrel connector or the usb port)? In other words, will that circuit diagram work ok if the servo external power is from a distinct and separate battery is used to power the main Arduino board itself?

Also to all who asked about the spec of the servo - it is an SG90 micro servo motor, it looks like it operates between 4.8 and 6 volts. Does this add the needed clarification ?

Thank you again for your help and any other suggestions !

Yes, You can preferably supply pwr separately to servos and Arduino. Personally I use 5 volt powerpacks, used for charging smartphones, to feed the Arduino itself. Motors etc. I feed by separate and "big" powersupplies.

"@zoomkat - in the diagram above, can the remainder of the Arduino board still be hooked up to power via the power connectors on the board itself (ie, the barrel connector or the usb port)? In other words, will that circuit diagram work ok if the servo external power is from a distinct and separate battery is used to power the main Arduino board itself?"

Yes, just make sure the grounds between the servo power supply and the arduino ground are connected together like in the diagram.

awesome, thanks all, just ordered a bunch of stuff and will give it a go.

thank you on behalf of my kids!