# Why can't I drive more than one H-Bridge unless all other output pins are in Hi-Z state?

I've looked at other questions, this one came the closest, but my problem is not in terms of power supply.

To drive multiple DC motors from an Arduino Mega 2560, I got a few HG7881-based dual H-bridge drivers. Looking at the datasheet of that chip, they seem to be sufficient. Testing the motors with my bench supply at 9V, they never reach 400mA when stalled, which is still far below the typical continuous output current of 600mA.

When I drive just a single motor through one of these H-bridges, it works 100% fine, even PWM mostly works, down to about 30% duty cycle. However, once I connect a second H-bridge to two more pins of the Arduino, and just set those to OUTPUT, the motor stops working:

int motor0_forward = 2;
int motor0_backward = 3;
int motor1_forward = 4;
int motor1_backward = 5;

int led_pin = 13;

void setup()
{
// Set up motor 0
pinMode(motor0_forward, OUTPUT);
pinMode(motor0_backward, OUTPUT);
digitalWrite(motor0_forward, LOW);
digitalWrite(motor0_backward, LOW);

// Set up control LED
pinMode(led_pin, OUTPUT);
digitalWrite(led_pin, LOW);

// Set up motor 1
// Everything works if these four lines are commented out!
pinMode(motor1_forward, OUTPUT);     // ???
pinMode(motor1_backward, OUTPUT);    // ???
digitalWrite(motor1_forward, LOW);   // ???
digitalWrite(motor1_backward, LOW);  // ?*/
}

void loop()
{
digitalWrite(led_pin, HIGH);
delay(50);
digitalWrite(led_pin, LOW);

// Test motor 0
digitalWrite(motor0_forward, HIGH);
delay(50);
digitalWrite(motor0_forward, LOW);
digitalWrite(motor0_backward, HIGH);
delay(50);
digitalWrite(motor0_backward, LOW);

delay(500);
}


Instead of commenting the lines out, I can also set the pinMode to INPUT to get the pins into Hi-Z, and that is the workaround I am using in my actual program.

However, I would like to understand what's going on here.

I have the on-board LED blinking to make sure there's no brown-out or reset happening, and it blinks steady in short pulses, so no issue here.

As the outputs for motor1 are set to low, the connected motor is not driven. The load should at maximum be 20mA, according to the datasheet, but none of that should be supplied by the Arduino. The lab supply shows ~43mA current draw, which seems a little higher than advertised but still ok for two H-bridges. So I'm fairly certain that there's no overcurrent situation on the Arduino itself.

I tried using two separate boards, no difference. I tried using other pins, even pins without PWM output, no luck. I tried putting in series resistors to limit the current somewhat, but the highest I got with a single motor still working was 330R, and that didn't solve the problem either.

What does work is disconnecting the motor1 H-Bridge from the Arduino physically. When I do that, motor0 immediately starts moving again. With an analog oscilloscope, I could confirm that the signal sent out on the motor0 pins by the Arduino does not change whatsoever between motor1 being connected or not.

So, what the hell is going on here? What else can I check?

As always, it's the last thing you look for. Just before posting the question, I thought to also have a look at the input pins of the unconnected motor.

Lo and behold, something strange:

At 10ms and 0.5V per division, this seems to be some signal with a period of ~20ms, at ~0.8V peak-to-peak. 20ms equals 50Hz. See where this is going yet?

This pattern emerged because I had connected the probe ground to the Arduino ground, which is powered by my PC's USB port, and the probe's micrograbber to the H-Bridge input, which was powered by the lab supply. And that's where the problem was; Lab supply and Arduino were not grounded to one another directly, so the signal levels between them picked up noise from the grid.

Once I connected the DC grounds of lab supply and Arduino together, everything worked perfectly fine and I can now even drive two motors at the same time.

Hope someone will find this helpful in the future!

• When I tried 3 motors my USB stopped working but ok on laptop without charger only... same issues even when charger is floating..grounding EMI Aug 19, 2020 at 23:08