L293d strange behavior



hi

i am making a bluetooh controlled car using arduino. since i am not using the original arduino uno but my own custom board so i made a motor driver shield using l293d but it is behaving strangely! when i turn on the board, it works ok for the first few commands sent over bluetooth (forward etc..) but then the car starts rotating as if i have sent the turn command. to make sure this problem is not due to some code problem, i took the same l293d and tried it on my 433MHz rf controll board ( which uses a ht12d ie i had same four outputs like in the case of a microcontroller and used the rf remote based on ht12e to controll these four outputs with four inputs on ht12e) but still it worked for some time when i started it and again one motor started rotating in wierd manner. i am using two nokia 3.7 volt 1000mAh in series as the power source and the motors are cheap toy motors like this - http://thinkoutofthenet.com/wp-content/uploads/2010/03/dc-toy-motor1.jpg i even connected .1uf caps at the motor terminals to check if it is a noise problem due to those motors but the same result was obtained i read somewhere that the l293d can habdle only 600mA  but the ic is not getting hot

UPDATE- i did what nhbill and sheldon said and tested each piece separately, i took out the l293d from the board, tested it on breadboard and found that it is working fine so there is not any problem in motor driver. After this i tested the bluetooth connection and my code and as Birdmun advised, i modified my code so that it sends back what it is receiving over the bluetooth to the serial terminal. here is the code-- (f- move forward, s-stop, b-move backwards, r-right turn, l-left turn)


 const int ma1 = 5;
 const int ma2 = 7;
 const int mb1 = 6;
 const int mb2 = 8;
 char a;

 void setup()
 {
   Serial.begin(9600);
   pinMode(ma1,OUTPUT);
   pinMode(ma2,OUTPUT);
   pinMode(mb1,OUTPUT);
   pinMode(mb2,OUTPUT);
 }

 void loop()
 {
   while(Serial.available()>0)
   {
    a = Serial.read();
    Serial.print("\n");
    Serial.print(a);
   }
 
   switch (a) {
    case 'f':
    drive(255, 0, 255, 0); //forward
    break;
    case 's':
    drive(0, 0, 0, 0); //stop
    break;
    case 'l':
    drive(128, 1, 128, 0); //left
    break;
    case 'r':
    drive(128, 0, 128, 1); //right
    break;
    case 'b':
    drive(0, 1, 0, 1); //backup
    break; 
    }
 }
 
 void drive(int m1spd, boolean m1dir, int m2spd,  boolean m2dir) 
 {
   analogWrite(ma1, m1spd);
   digitalWrite(ma2, m1dir);
   analogWrite(mb1, m2spd);
   digitalWrite(mb2, m2dir);
 }
 
 now if i send f to move it forwards or b for moving it backwards it works for 5-6 times then the microcontroller sort of "hangs" and the wheels keeps on rotating to move it forward or backward depending on the last character i send and after this either the microcontroller doesn't send anything back to serial or starts sending back random characters and symbols. this problem occurs more often (only works properly once or twice) if i try to turn it (NOTE- i am using PWM while turning to slow down its turning speed)

UPDATE- i added a 100uF cap between the 5 volt and the ground terminals on the l293d, it works properly for more time now ( :D ) but still it is not fully reliable and hangs after about 20 or 30 commands

 so is it the noise problem? if it is then what more can i do to dampen this noise?

thanks

sanc04

mA != mAh

mA is a measure of current required or in the case of your driver the amount of current it can supply at any given time. mAh is a measure of how much current over time can be supplied. 900mAh means, roughly, that the batteries can supply 900mA for an hour.

oops…:stuck_out_tongue:

thanks for pointing it out Birdmun, i always confuse the two things :stuck_out_tongue:

What I would do is break it

What I would do is break it down to testable pieces.  Go from the large, gee I have a problem to piece by piece testing.  Take the blue tooth piece out (comment out the code) and go directly from the L293 chip to your car (or use a different motor with similar characteristics to test with) and see if you can repeat it.  Run through ALL actions you would do with your car to test that you are interacting correctly with the L293 chip.  Run through the actions you did with the blue tooth code in place to see if you can repeat it.  If you can repeat it, it is a software issue.  If not, hardware somewhere is causing the issue.  Separate and test piece by piece, then slowly integrate each piece back in, test and confirm it works until you find what the issue is.

Good luck!

Bill

 

l293d

You have probably one of this 3 problems. First check your input and output connections and test which of the inputs or outputs should be logic 1 or logic 0 for forward and backward if any of this are wrong or does not work the motor will rotate. Second check for your code. And third is to check your bluetoot communication if you use terminal does that is sending right characters.I would do the  same like Bill separate each device and test it. I have same problem just litle different with one command for backward only one of the motors was working and i find out that in code i reset enable bit and never set for backward command, so check twice everything and buy one more l293d they are cheap and always should have more than one for testing.

Hope you will find the issue :slight_smile:

updated my post

updated my post

Voltage dip

If you change direction from full forward to backwards abruptly, it will give a voltage dip onto the battery causing your microcontroller to reset. what you can try is:

  1. In your code: let the motor first stop, then a little pause, and then change direction.
  2. Look again how you did your wiring… are the wires too thin? and is is smart not to have (for example) the wire going from battery to microcontroller, and from there continue to the l293. better use an 2nd wire from battery to l293 then.
  3. Eventually use separate accus for motors and microcontroller.

RX

Did you clear the RX buffer at the end of your commands ? If Rx is full with characters might this cause your code to follow just the last character after a while. And for your battery source maybe you have problem with dc - motors if you generate too much current that the dc - motors cant handle and cant stop cause recharging is too fast.