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:
- Is the H bridge IC chip internally protected from back EMF?
- 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);
}
}


