Arduino Nano + L293D + servos - Servos stop working after a while.

Hi, I am controlling 2 servos and 2 small toy motors using a L293D using a Nano.
When power up, everything seems ok but after a minute or so, the servos stop.
When I start without the DC motors or even just one of them, things seems to run ok.
I am using a 7.2, 2A wall adapter for the motors and the Nano input.
I also tried 2 slightly bigger DC motors at 12V and the same thing happened.
I have noticed the L293D becomes very hot, within seconds.

Any clue why this happens? Thanks in advance. George

I expect there is a problem with the components, your wiring or perhaps with your code. But I can't see any of them.

What servos do you have? What motors? How exactly are they connected and powered?

Steve

Thanks Steve,

My code is copied below.
Servos are MG996R rip-offs.
DC motors are standard toy motors, amazon claims 1.5 to 6V.

/* TTR_MK3A
Table tennis robot software based on 2 servos and 2 DC motors for a table tennis motor
Servo 1 - elevator (continuous rotation), servo 2 - pivot (non continuous rotation), DC 1 - topspin. DC 2 - backspin
Additional components:
microswitch for launch pivot servo synching
Switches, buttons, pots, ..., rest tbc
Links:
http://www.arduino.cc/en/Tutorial/Sweep
*/
#include <Servo.h>
Servo elevator;     // create servo object to control a servo
Servo pivot;  // create servo object to control a servo
int pos = 0;    // variable to store the servo position

int topmotorP = 6;      // LED connected to digital pin 9
int topmotorN = 9;      // LED connected to digital pin 9
int bottommotorP = 11;      // LED connected to digital pin 9
int bottommotorN = 10;      // LED connected to digital pin 9

void setup() {
  elevator.attach(3); // attaches the servo on pin 9 to the servo object
  pivot.attach(5); // attaches the servo on pin 9 to the servo object

  pinMode(topmotorP, OUTPUT);  // sets the pin as output
  pinMode(topmotorN, OUTPUT);  // sets the pin as output
  pinMode(bottommotorP, OUTPUT);  // sets the pin as output
  pinMode(bottommotorN, OUTPUT);  // sets the pin as output
  digitalWrite(topmotorN, 0);
  digitalWrite(bottommotorN, 0);

}

void loop() {
  elevator.write(100); // tell servo to go to position in variable 'pos'
  analogWrite(topmotorP, 200);
  analogWrite(bottommotorP, 200);

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

Follow slipstick's suggestion, post all of the code, a schematic, not a frizzy drawing, links to the parts and power requirements for the motors. Explain how you did the 12V.

Those servos need plenty of power particularly when used at high voltages. They are not specified for 7.2V and even at their normal 6V a 2A power supply is not sufficient.

The comments in your code are rubbish and just confuse things. They should either be accurate or be removed.

Steve

Ok thanks All,
I will generate a schematic, tidy up my code comments, see if I can provide any other info.
George

Hello,
Code comments amended.
Schematic generated and attached.
The servos are not plugged in the input voltage but on the Nano's 5V output. For input power I use a selectable wall adapter. I have set it to 7.2V. Current rating is 2A. At some point I used 12V when I temporarily used 2 larger DC motors to see if they will respond differently.

DC motors link
https://www.amazon.co.uk/gp/product/B075Q444K9/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1
Servo motor link

/* TTR_MK3A
Table tennis robot software based on 2 servos and 2 DC motors for a table tennis motor
Servo 1 - elevator (continuous rotation), servo 2 - pivot (non continuous rotation), DC 1 - topspin. DC 2 - backspin

Links:
http://www.arduino.cc/en/Tutorial/Sweep
*/
#include <Servo.h>
Servo elevator; // create servo object to control a servo
Servo pivot;    // create servo object to control a servo
int pos = 0;    // variable to store the servo position

int topmotorP = 6;      // top motor positive pin
int topmotorN = 9;      // top motor negative pin
int bottommotorP = 11;  // bottom motor positive pin
int bottommotorN = 10;  // bottom motor negative pin

void setup() {
  elevator.attach(3); // attaches the servo on pin 9 to the servo object
  pivot.attach(5); // attaches the servo on pin 9 to the servo object

  pinMode(topmotorP, OUTPUT);   // sets the pin as output
  pinMode(topmotorN, OUTPUT);   // sets the pin as output
  pinMode(bottommotorP, OUTPUT);// sets the pin as output
  pinMode(bottommotorN, OUTPUT);// sets the pin as output
  digitalWrite(topmotorN, 0);   // topmotor negative pin / no opposite direction required
  digitalWrite(bottommotorN, 0);// bottom negative pin / no opposite direction required

}

void loop() {
  elevator.write(100);            // set speed for continuous rotation servo
  analogWrite(topmotorP, 200);    // set PWM speed for top motor
  analogWrite(bottommotorP, 200); // set PWM speed for bottom motor

  for (pos = 60; pos <= 120; pos += 1) {  // goes from 60 degrees to 120 degrees in steps of 1 degree
  pivot.write(pos);                       // tell servo to go to position in variable 'pos'
  delay(15);                              // waits 15ms for the servo to reach the position
  }
  for (pos = 120; pos >= 60; pos -= 1) { // goes from 120 degrees to 60 degrees in steps of 1 degree
  pivot.write(pos);                      // tell servo to go to position in variable 'pos'
  delay(15);                             // waits 15ms for the servo to reach the position
  }
}

TTR_MK3A_schema_1.pdf (13.8 KB)

A pic of the breadboard attached this time, after reducing the size...

Georgios78:
The servos are not plugged in the input voltage but on the Nano's 5V output.

That's much worse. The regulator that feeds the Arduino 5V pin cannot provide nearly enough current for those powerful servos. You're in real danger of damaging it.

Oh and powering servos through a breadboard is also a bad idea.

Steve

Ok thanks Steve, My plans are:
Move the circuit to a stripboard.
Use a 5V DC to DC converter directly from the 7.2V input for the 2 servos.
Alternatively, set the input to 5V and use a converter to 9V for powering up the Nano.

I could power up everything by the 7.2V including the servos but the input range I believe is 4.8 to 7.2 so I am not sure if this will be ok of the servos.

Gorge

That would work but I'd use 5V either with a different wall adaptor or a 5V DC-DC converter, which should have at least 3A output, to drive both the servos and the Arduino via its 5V pin. Much better than using Vin or the barrel connector.

Steve

Hi Steve,
Would you be able to explain a bit more your suggestion?
Do you mean to use 5v for everything? I thought that the Arduino can take from 7 to 12?

George

The Arduino actually works internally on 5V. It has a little regulator in so it CAN be run from higher voltages but that's not very good and can overheat and break. So if you can provide 5V directly to the 5V pin everything works better. Note that when you have the USB cable plugged in that provides 5V too.

The L293D and the motors are the ONLY things that might need more than 5V.

Steve

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.