Pages: [1]   Go Down
Author Topic: Arduino Uno with H-bridge  (Read 2257 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey everyone,

This is my first ever project but I am having problems getting my motor to run.

This is the sketch I uploaded to the board
Code:
// Project 1 - LED Flasher
int input1 = 5;
int input2 = 7;
int enableA = 6;


void setup() {
  pinMode(input1, OUTPUT);
  pinMode(input2, OUTPUT);
  pinMode(enableA, OUTPUT);
}
void loop() {
  digitalWrite(enableA, HIGH);
  digitalWrite(input1, HIGH);
  digitalWrite(input2, HIGH);
 
  delay(1000);
  digitalWrite(input1, LOW);
  digitalWrite(input2, LOW);
  digitalWrite(enableA, LOW);
  delay(1000);
}

I have used this diagram for reference http://bp0.blogger.com/_DLeG8x1l9dw/R__OZ0Pg0RI/AAAAAAAAAEA/jHWmi9gPqm0/s1600-h/L298.jpg

And this is how I have wired it up

http://imageshack.us/f/5/20110901001.jpg/

http://imageshack.us/f/15/20110901002.jpg/

I am trying to get my DC motor to run. Can anyone help me out?

As for a side question, can anyone confirm that we do not need to use any resistors for the l298n inputs? The board gives off 40ma for each input/output, is it okay to wire it like this without any resistors?

Thanks in advance
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25761
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can you confirm that that battery pack is just 3V?
That may not be enough when you take into account the H-bridge drop.

Do you have a multimeter?
If not, get one.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Denmark
Offline Offline
Edison Member
*
Karma: 35
Posts: 1052
Happy Hobbyist
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


I am no expert in H-bridges, but should it not be

 digitalWrite(enableA, HIGH);
  digitalWrite(input1, HIGH);
  digitalWrite(input2, LOW);

I mean both inputs high or low could mean a short circuit

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can you confirm that that battery pack is just 3V?
That may not be enough when you take into account the H-bridge drop.

Do you have a multimeter?
If not, get one.

Initially this Tamiya Dozer I have runs by connecting to this wired remote control which uses 3 volts (the 2 D cell batteries). Everything runs smoothly but when I remove the remote control and replace it with this, it doesn't work.



I am no expert in H-bridges, but should it not be

 digitalWrite(enableA, HIGH);
  digitalWrite(input1, HIGH);
  digitalWrite(input2, LOW);

I mean both inputs high or low could mean a short circuit



I just tried that but still no luck.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25761
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So, what does the multimeter show as the voltage at the motor at 100% PWM?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So, what does the multimeter show as the voltage at the motor at 100% PWM?

Sorry for being such a newbie but how I am suppose to test that out? The only way I can get the motor to run is connecting it with the original wires that came with the kit.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25761
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just measure the voltage across the motor - unless the wires are over-long, it won't make any difference if you measure it at the IC or the motor.
I just noticed you're not using PWM, so just turn the device on.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I can't find the multimeter in the garage, I will have to wait until my dad comes back. But anyways, I don't know if this helps but I tried directly attaching the battery to the motor and it works. Also I have tried the same setup but instead used a 9v battery and the motor still doesn't run. Does this conclude that it is not a problem associated with a voltage drop? And BTW, don't DC motors use PWM?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25761
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
And BTW, don't DC motors use PWM?
They can, but your code doesn't.

Quote
lso I have tried the same setup but instead used a 9v battery and the motor still doesn't run
If your motor normally takes C or D cells to move it, I doubt a 9V battery would do very much.

Quote
Does this conclude that it is not a problem associated with a voltage drop?
No.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

When I connect ground (from arduino) to pin 8 row which is the ground for the l298n and connect the negative wire (from battery) to the same row, then connect that wire and output 1 to the motor, it runs. So something is wrong with the 0v from the battery not connecting to the l298n bridge? I have tried almost everything I can, this is the only way the motor runs with my arduino code but is isn't really in a circuit. I can't get output 2 to carry out that 0v from the battery? Is that the problem here?
Logged

Johannesburg South Africa
Offline Offline
Newbie
*
Karma: 0
Posts: 12
It can only be attributed to Human Error
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I use some L298N Ic to drive DC motors ( They are dual H bridge drivers ie, can control 2 DC motors each )

Here is a snippet of code that works for them :, note that I have defined onboard_led_pin as pin 13, and the in_1,in_2 and enable pins as whatever they were connected to ( in_1 and in_2 are digital outputs, and enable is a pin with PWM should I choose to do speed control.

If you want the motor to do something, you call " motor_drive(DIR1,255) "  or " motor_drive(1,255) "  which will drive tho motor at full power n direction 1

Do you have a schematic of your setup so its easier to debug?

Quote
#define DIR1  1                              // motor direction 1
#define DIR2  2                              // motor direction 2
#define OFF  3                              // motor off


Quote
void motor_drive (int dir, int power)  // Direct hardware interface
{
   switch(dir)                                                         // Determine motor driving according to passed values
  {
     case DIR1:                                                      // Direction 1
             digitalWrite(in_1,HIGH);                                // Motor turns in Direction 1 at a set power (PWM on enable line)
             digitalWrite(in_2,LOW);            
             analogWrite(enable,power);
             digitalWrite(onboard_LED_pin,HIGH);
             break;
            
     case DIR2:                                                     // Direction 2
             digitalWrite(in_1,LOW);                                // Motor turns in Direction 2 at a set power (PWM on enable line)
             digitalWrite(in_2,HIGH);
             analogWrite(enable,power);
             digitalWrite(onboard_LED_pin,HIGH);
             break;
     case OFF:
             digitalWrite(in_1,LOW);                                // Motor lines are pulled low, and enable set low
             digitalWrite(in_2,LOW);
             digitalWrite(enable,LOW);
             digitalWrite(onboard_LED_pin,HIGH);
             break;
     default:
             digitalWrite(in_1,LOW);                                //  Motor lines are pulled low, and enable set low
             digitalWrite(in_2,LOW);
             digitalWrite(enable,LOW);
             digitalWrite(onboard_LED_pin,HIGH);
             break;
  }
  digitalWrite(onboard_LED_pin,LOW);
}

« Last Edit: September 02, 2011, 04:32:36 am by LocalgHost » Logged

 .
  .
...

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the advice,

It was indeed the analogwrite(pin,speed) that was the fix. Well it worked for a few seconds only. I think it is because I am connecting the ground of the arduino to the ground of the battery incorrectly. It seems to be working only if it touches slightly or something. Anyone know a solution? When I push the wires in the breadboard completely, it doesn't work anymore.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nevermind guys, the problem is with the bent h-bridge. Everything works now, Thanks for all your help.
Logged

Pages: [1]   Go Up
Jump to: