L293 motor control half-working

Hello,

I am using an L293b to drive a couple 24VDC motors (left and right side both control a single motor), I believe I have wired the circuit correctly as indicated in the diagram from the datasheet (it showed a different wiring on the right side, I used the wiring shown on the left side for both motors). I am using an Arduino Uno to control the signals, with the following code (just ignore the stuff about valves - those go with the transistors on the breadboard):

const int onPin = 13;
const int motor1cwPin = 3;
const int motor1ccwPin = 5;
const int motor2cwPin = 6;
const int motor2ccwPin = 9;
const int valve1Pin = 10;
const int valve2Pin = 11;

int cycle = 0;
int cycle10count = 0;

int switchState = 0;

void setup() 
{
  pinMode(onPin, INPUT_PULLUP);
  pinMode(motor1cwPin, OUTPUT);
  pinMode(motor1ccwPin, OUTPUT);
  pinMode(motor2cwPin, OUTPUT);
  pinMode(motor2ccwPin, OUTPUT);
  pinMode(valve1Pin, OUTPUT);
  pinMode(valve2Pin, OUTPUT);
  
  digitalWrite(motor1cwPin, LOW); //I think all this part may be superfluous, but I put it in anyway 
  digitalWrite(motor1ccwPin, LOW);
  digitalWrite(motor2cwPin, LOW);
  digitalWrite(motor2ccwPin, LOW);
  digitalWrite(valve1Pin, LOW);
  digitalWrite(valve2Pin, LOW);
  
  Serial.begin(9600);
}

void loop() 
{
  switchState = digitalRead(onPin);
  if (switchState == LOW)
  {
    testRun();
  }
}

void testRun()
{
  cycle = ++cycle;
  //Serial.println("clockwise1");
  digitalWrite(valve2Pin, HIGH);
  digitalWrite(motor1ccwPin, LOW);
  analogWrite(motor1cwPin, 255);
  delay(5000);
  digitalWrite(motor1cwPin, LOW);
  digitalWrite(valve2Pin, LOW);
  //Serial.println("clockwise2");
  digitalWrite(valve1Pin, HIGH);
  digitalWrite(motor2ccwPin, LOW);
  analogWrite(motor2cwPin, 255);
  delay(5000);
  digitalWrite(motor2cwPin, LOW);
  digitalWrite(valve1Pin, LOW);
  
  //Serial.println("counter clockwise1");
  cycle = ++cycle;
  digitalWrite(valve2Pin, HIGH);
  digitalWrite(motor1cwPin, LOW);
  analogWrite(motor1ccwPin, 255);
  delay(5000);
  digitalWrite(motor1ccwPin, LOW);
  digitalWrite(valve2Pin, LOW);
  //Serial.println("counter clockwise2");
  digitalWrite(valve1Pin, HIGH);
  digitalWrite(motor2cwPin, LOW);
  analogWrite(motor2ccwPin, 255);
  delay(5000);
  digitalWrite(motor2ccwPin, LOW);
  digitalWrite(valve1Pin, LOW);

//if (cycle10count == cycle % 10)
  {
  Serial.print("cycle = ");
  Serial.print(cycle);
  Serial.println();
  }
}

I am powering the logic for the chip from the Arduino, and powering the motors with a 24DCV supply.

The problem is... the right side works fine, but the left side motor will turn on before I activate the program or even hook up the 24v (looks like it is pulling the 5v from the Arduino/logic supply - it turns very slowly). It will also still turn if I unhook the enable pin on that side of the IC.

When I hook up the 24v and turn on the program it will only turn in one direction (even when both pins are low) going full speed and when it is supposed to turn the other way it just slows down (so the 24v is disabled and it's just pulling 5v from the board again.)

I have used this same circuit and program before (the stuff about the valves is new), and it didn't act like this then, although it's not the "same" circuit since I disassembled the first one and reassembled this one fresh.

I have stared at this circuit for hours and I'm fairly certain it is wired exactly the same on both sides, and the electronics expert at my office is perplexed as well.

I'm embarrassed to admit I blew out my Atmega when I tried to ground the motor outputs (with the 24v hooked up) in a desperate last ditch, so I'm waiting on a new one I ordered before I can try anything again, although I can still fiddle with the IC by itself. I have a few of those still, I've only blown out about half of the ones I had on hand.

I would be most grateful for any thoughts on this.

L293 circuit.jpg

Should be no need to blow out parts.

I suggest:

  1. replace the motors with 1k or 2k resistor (might need a few to get the power capability) , and perhaps parallel that with back to back LED's as well (to see the output state).

  2. get your voltmeter out. If you don't have on you should purchase one. It can be a cheap $10 or so meter as you measurements don't have to be too precise.

  3. Verify the L293 logic supply is not dragging down the 5V output of the Arduino. It can be as high as 40 ma (I doubt it will draw the 60 ma cited on the spec sheet)

  4. Measure each pin (at the pin) of the L293 when it is the working direction and when it is not working. You could see when things are not what they should be.

When I read your post the first thing that popped into my mind is a bad connection on the plug-in (prototype) board. They are not terribly reliable especially when using thicker leads (diodes) and wires.

A quick look at the wiring..... it looks like pin 6 goes to a diode not an Arduino input? You should mark where the motors are connected as well.

Certainly NOT trying to be a smartazz, but here's my solution :slight_smile:

Hello,

Well, you do not need the Arduino to test the L293, the idea of using LED is cool,but I think you can still test only with the motor.

The L293 has two models, with internal diodes and no diodes, be sure that it has diodes, if it is the L293 model without internal diodes, you need to add external diodes!

Note that when using internal diodes, the chip will heat up more. I prefer to use external diodes.

I am using the L293B, so the external diodes are recommended.

Pin 6 is the output for one side of the motor, and per the circuit diagram also has diodes going from Gnd and to v2. The other motor output is pin 3, which also has diodes going from Gnd and to v2.

I added all the extra (LOW) commands to make sure there weren't any floating pins. I don't know that those are necessary, and I don't think the problem was with the code anyway. Let me know if you think those could be taken out to clean up the code some.

I am inclined to agree with the breadboard being the problem. What do you suggest for prototyping, especially if I want to reuse components for other projects?

Thanks.

I would put the components on a solder type board. Something like this:

ebay printed strip board

I would get a socket for the L293 and purchase more diodes.

The small transistors can stay on the plugin board, that is if the plug in board sockets have not been stretched out by the thicker leads at some point.

I missed the function of pin 6, might have been looking a the wrong datasheet.

Hello,

Datasheet:

On page 8, we have the truth table, as you can see, it's very simple, it has a control pin (EN), and the inputs (A), which are not inverters.

The use of diodes is mandatory for inductive loads, such as solenoid, motors etc., since when deenergizing, a reverse voltage will arise with the degaussing of the coil, then the diode will reverse this voltage peak and prevent it from flowing through the other components of the circuit.

Please, see if this code helps the L293(D) test, remember to enter the correct port number that drives each L293 pin:

#define L293_1A 3
#define L293_2A 4
#define L293_3A 5
#define L293_4A 6
#define L293_12EN 7
#define L293_34EN 8

void setup() {
  // put your setup code here, to run once:
  pinMode(L293_1A, OUTPUT);
  pinMode(L293_2A, OUTPUT);
  pinMode(L293_3A, OUTPUT);
  pinMode(L293_4A, OUTPUT);
  pinMode(L293_12EN, OUTPUT);
  pinMode(L293_34EN, OUTPUT);

  digitalWrite(L293_1A, LOW);
  digitalWrite(L293_2A, LOW);
  digitalWrite(L293_12EN, LOW);

  digitalWrite(L293_3A, LOW);
  digitalWrite(L293_4A, LOW);
  digitalWrite(L293_34EN, LOW);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(L293_1A, HIGH);
  digitalWrite(L293_12EN, HIGH);
  delay(2000);
  digitalWrite(L293_1A, LOW);
  digitalWrite(L293_12EN, LOW);
  
  delay(2000);

  digitalWrite(L293_2A, HIGH);
  digitalWrite(L293_12EN, HIGH);
  delay(2000);
  digitalWrite(L293_2A, LOW);
  digitalWrite(L293_12EN, LOW);

  delay(2000);

  digitalWrite(L293_3A, HIGH);
  digitalWrite(L293_34EN, HIGH);
  delay(2000);
  digitalWrite(L293_3A, LOW);
  digitalWrite(L293_34EN, LOW);

  delay(2000);

  digitalWrite(L293_4A, HIGH);
  digitalWrite(L293_34EN, HIGH);
  delay(2000);
  digitalWrite(L293_4A, LOW);
  digitalWrite(L293_34EN, LOW);

  delay(2000);
}

I ended up using an L293D (well, 2 stacked on top of each other) and it's working fine, but I'm still bothered by not being able to figure out what was wrong with the L293B arrangement. Oh well. Maybe I'll try again later.

Thanks for your replies.