Help using an H-Bridge

I’ve got an H-Bridge that I’m controlling two motors with. Everything’s working fine as far as I can tell, except for this - when I power the motors with the 5 V from the Arduino (a Diecimila), only one of the motors work. When I power it from a 9 V battery, both motors work but they go too fast and it smells like they’re burning. What should I do to power the motors equally?

Thanks!

Here’s my code btw, I don’t know if it matters. Another problem I’m having is the motors don’t turn off after the 300 milisecond delay. Why would that be?

 //10 HIGH - back left
 //11 HIGH - forward left
 //6 HIGH - forward right
 //9 HIGH - back right
 
 
 void setup()   {         
   pinMode(6, OUTPUT);     
   pinMode(9, OUTPUT);
   pinMode(10, OUTPUT);     
   pinMode(11, OUTPUT);
   pinMode(13, OUTPUT);
   
   blink ();
 }

 void loop()                     
 {
       straight (300, 200);
       delay (7000);
 }

 void straight (int milisecs, int velocity) {
   analogWrite(3, velocity);
   analogWrite(5, velocity);
   
   digitalWrite(6, HIGH);
   digitalWrite(9, LOW);
   digitalWrite(10, LOW);
   digitalWrite(11, HIGH);
   
   delay (milisecs);
   
   digitalWrite(6, LOW);
   digitalWrite(11, LOW);
   analogWrite(3, 0);
   analogWrite(5, 0);
 }

void blink ()
  {
    int i = 0;
    for (i; i<3; i++) {
       digitalWrite(13, HIGH);
       delay(400);
       digitalWrite(13, LOW);
       delay(400);
    }
  }

Your H-bridge chip apparently has a separate "motor power" input that you used for testing with the 9V battery. Just connect another regulated power supply (probably 5V, since it was partly working when stealing power from the Arduino. But you might need a higher voltage, because you lose a couple of Volts in the H-bridge chip's output transistors) to that same input.

Ran

What do you mean regulated, and how would I do that with batteries? Does the Arduino's 5 V not actually put out 5 V?

What do you mean regulated, and how would I do that with batteries? Does the Arduino's 5 V not actually put out 5 V?

You need some form of voltage regulator. The Arduino 5V does put out (approximately) 5V, but that doesn't seem to be enough to power both motors along with the Arduino.

I’ve got a 5 V voltage regulator, but if 5 V won’t be enough then that won’t work. 9 V is too much, how could I supply something in between?

e: I can get 6 V with four AA batteries, if I just made it go through a capacitor before the H bridge would that be enough regulation?

I advised a regulated supply because the unregulated supplies you can buy cheaply often put out far more than their nominal voltage. The motors almost certainly won't be upset by a little more than 5V, so the 6V battery pack will be fine for testing. Just check them after running them for a few minutes, to make sure they're not getting hot.

And, if you use NiMH batteries (as all eco-conscious geeks should ;)), it'll be about 5V, anyway.

Ran

But isn't that it's 5 V my problem? If I'm just going to use a 5 V power supply why wouldn't I just use the one from the Arduino? Or is that one not regulated?

But isn't that it's 5 V my problem?

It is if it can't supply enough current for your motors. In that case the voltage will drop.

If I'm just going to use a 5 V power supply why wouldn't I just use the one from the Arduino?

Because you have limited amount of current through that one. It's about 500mA if from the USB and about 300mA if from the on board regulator.

you could use an external transformer, there are some cheap ones with selectable voltages, or if your application needs to be wireless, use a battery pack as Ran suggested. There are plenty of them in model building shops, with various capacities and technology (NiMH or LiPo)

Ok I got a 5 V regulator that should supply 1 amp, I'll power it with a 9 V for now.

I plugged in the 5 V regulator and took out the ground from the Arduino, since I have ground from the regulator. It stopped working, and wouldn't work until I had plugged the ground back in from the Arduino. Can anyone explain why this happens?

Thanks!

e: Actually, I don't think this is how I should be doing this. The 9 V I power the motor with is very hot. Dang.

Whenever you're using two power supplies, you must share the grounds. No idea why, I just know you have to. Maybe it's one of those things people just don't get, like parallel resistors? :P

What do you mean share the grounds? If you mean hook everything up to the grounds from both power supplies, why is it that when I did that one of the 9 V batteries got very hot?

I mean that all grounds (negative) of all power sources (Arduino, batteries, etc.) used in a project must be connected.

you must share the grounds. No idea why, I just know you have to.

Look here for the answer:- http://www.thebox.myzen.co.uk/Tutorial/Power_Supplies.html