Dual h-bridge DC Motor Controller

Hi! I am trying to figure out a problem about Dual h-bridge (like the one I’ve attached) which controls two TT motors.

I connected the dual h-bridge to Arduino UNO.

Initially I powered just the Arduino by a 9V battery and I connected the dual h-bridge to the 5v port, but then I changed my mind because the motors received little energy, therefore they moved slowly.
(PS The motors worked perfectly)

Consequently, I decided to power the dual h-bridge separately by an other 9V battery. (I connected the dual h-bridge directly to the battery, without any resistor).

I uploaded the same code as before on Arduino, but I realized I can just move the motors simultaneously: when i try to move one motor at a time, both of the motors don’t move.

How can I solve this problem? I need your help.

PS I’ve attached the code I am using.

code.ino (1.81 KB)

Are all your grounds tied together? If you have one 9V battery powering your arduino and another one powering your H bridge, they need to share a common ground