Starter Project 10 - H Bridge

Hey all,

I’m trying to learn arduino for a school project, and I’m running into an issue with the H bridge. I’m using the starter project book as a guide, but my circuit is quite different. Essentially, I have a button that should run the motor forward when pressed, and another button that runs the motor backward when pressed.

Now you ready for the twist? It works. Perfectly. At least when only LEDs are installed as the outputs.

As soon as I plug the motor into the output, things go awry. The motor runs very slowly when I press the backward button, and doesn’t run at all when I press the forward (although I can hear it trying). And as you can see from the picture, both LEDs light up, indicating that both outputs are live.

I’m worried that back EMF from the motor is adversely affecting the performance, however project 10 makes no use of diodes to prevent this.

So I have two questions:

  1. Is the H bridge IC chip internally protected from back EMF?
  2. How do I get full motor functionality out of this circuit?

Thanks in advance for the help!

const int controlPin1 = 2;
const int controlPin2 = 3;
const int enablePin = 6;
const int forwardPin = 4;
const int backPin = 5;

int forwardState = 0;
int backState = 0;

void setup() {
  // put your setup code here, to run once:
  pinMode(controlPin1,OUTPUT);
  pinMode(controlPin2,OUTPUT);
  pinMode(enablePin,OUTPUT);
  pinMode(forwardPin,INPUT);
  pinMode(backPin,INPUT);
  digitalWrite(enablePin,LOW);
}

void loop() {
  // put your main code here, to run repeatedly:
  forwardState = digitalRead(forwardPin);
  backState = digitalRead(backPin);

  if (forwardState == HIGH) {
    analogWrite(enablePin,255);
    digitalWrite(controlPin1,HIGH);
    digitalWrite(controlPin2,LOW);
    digitalWrite(13,HIGH);
  }
  else {
    analogWrite(enablePin, 0);
    digitalWrite(controlPin1,LOW);
    digitalWrite(13,LOW);
  }

  
  if (backState == HIGH) {
    analogWrite(enablePin,255);
    digitalWrite(controlPin2,HIGH);
    digitalWrite(controlPin1,LOW);
    digitalWrite(13,HIGH);
  }
  else {
    analogWrite(enablePin, 0);
    digitalWrite(controlPin2,LOW);
    digitalWrite(13,LOW);
  }
}

  1. Is the H bridge IC chip internally protected from back EMF?

Some are some aren't. Don't assume everyone knows what starter project 10 is.

What you are suffering is interference from the motor affecting the Arduino. We must get about 5 of these problems every week, for the last 10 years. The solution is to add some decoupling capacitors to the h-bridge's supply and also a capacitor actually on the motor's terminals.

Read what that does here:- De-coupling

Welcome to the real world of electronics, not just tutorials.

Astovio:
So I have two questions:

  1. Is the H bridge IC chip internally protected from back EMF?
  2. How do I get full motor functionality out of this circuit?
  1. Depends on which motor chip you're using. The L293D has inbuild back EMF diodes, the L293 not.
  2. Use a separate motor supply.

A Nano has a schottky backflow diode in it's USB supply, so the Nano"s 5volt pin is about ~4.6volt.
A motor chip, like the L293D, "looses" about 2.5volt in H-bridge mode.
So your motor will only see about 4.6-2.5= 2.1volt.

LEDs without current limiting resistors act like zener diodes.
That could eventually blow the LEDs or the motor chip.
Leo..

We can't see the bottom of your breadboard on your photos, so are the left-hand power and ground rails actually connected to power and ground?

Thank you for the replies.

The decoupling capacitor seems to be working. I put a capacitor in parallel with the motor leads and I've got life now. I've gotta do more research to figure out exactly what I'm doing though...

Thanks for pointing me in the right direction!

P.S.
The bottom rail of the breadboard is hooked up to positive and negative terminals of a 9V battery which isn't shown in the photographs. The H bridge is running off of 5V logic power from the arduino, and 9V driver power from this battery. Sorry for not making that clear.

Do you have a connected ground between the Arduino and 9V?

Do you have/need resistors on the LEDs?

I do have a ground between the arduino and the 9V

I did not have resistors on the LEDs, which I know is bad for the LEDs, but they worked enough to tell me what the H bridge was doing.