I’m using an L293 h-bridge with two Mabuchi toy motors. When I send both motors the forward command it works but when In try and reverse, one reverses the other stops!
I have checked, double, triple, checked my wiring, and code. I have two L293’s both behave the same. I just got two L298’s I’m gonna try as soon as I figure out how to plug them in the breadboard!
I also just ordered a Baby Orangutan to try since it has built in h-bridge.
The motors are the ones that come with Tamiya’s twin motor gear box kit.
The controller is an Arduino.
Here is the code used to test the H-Bridge
///////////////////
// h bridge test //
///////////////////
const int switchPin = 7; // switch input
const int enablePin1 = 10; // Enable for Motor 1
const int enablePin2 = 11; // Enable for Motor 2
const int motor1Pin = 2; // H-bridge leg 1 (pin 2, 1A)
const int motor2Pin = 3; // H-bridge leg 2 (pin 7, 2A)
const int motor3Pin = 4; // H-bridge leg 3 (pin 10, 3A)
const int motor4Pin = 5; // H-bridge leg 4 (pin 15, 4A)
const int ledPin = 13; // LED
void setup() {
// set the switch as an input:
pinMode(switchPin, INPUT);
// set all the other pins you're using as outputs:
pinMode(enablePin1, OUTPUT);
pinMode(enablePin2, OUTPUT);
pinMode(motor1Pin, OUTPUT);
pinMode(motor2Pin, OUTPUT);
pinMode(motor3Pin, OUTPUT);
pinMode(motor4Pin, OUTPUT);
pinMode(ledPin, OUTPUT);
// set enablePin high so that motor can turn on:
// digitalWrite(enablePin1, HIGH); //Uncomment if enable pins are not tied to Vcc
// digitalWrite(enablePin2, HIGH); //Uncomment if enable pins are not tied to Vcc
digitalWrite(switchPin, HIGH); // Enable internal pull up restor
// blink the LED 3 times. This should happen only once.
// if you see the LED blink three times, it means that the module
// reset itself,. probably because the motor caused a brownout
// or a short.
blink(ledPin, 3, 100);
}
void loop() {
// if the switch is high, motor will turn on one direction:
if (digitalRead(switchPin) == HIGH) {
digitalWrite(motor1Pin, LOW); // set leg 1A of the H-bridge low
digitalWrite(motor2Pin, HIGH); // set leg 2A of the H-bridge high
digitalWrite(motor3Pin, LOW); // set leg 1B of the H-bridge low
digitalWrite(motor4Pin, HIGH); // set leg 2B of the H-bridge high
}
// if the switch is low, motor will turn in the other direction:
else {
digitalWrite(motor1Pin, HIGH); // set leg 1A of the H-bridge high
digitalWrite(motor2Pin, LOW); // set leg 2A of the H-bridge low
digitalWrite(motor3Pin, HIGH); // set leg 1B of the H-bridge low
digitalWrite(motor4Pin, LOW); // set leg 2B of the H-bridge high
}
}
/*
blinks an LED
*/
void blink(int whatPin, int howManyTimes, int milliSecs) {
int i = 0;
for ( i = 0; i < howManyTimes; i++) {
digitalWrite(whatPin, HIGH);
delay(milliSecs/2);
digitalWrite(whatPin, LOW);
delay(milliSecs/2);
}
}
Ok as soon as I figure out how to post pics I’ll post a pic of how it’s wired
TIA
Robert