Issue with DIY H Bridge

Hello Everyone,

I have made an H Bridge using BD139, BD140 transistors and Arduino Nano. The PWM signal from receiver is being fed to D5 pin on Nano and D3, D4 pins control forward and reverse motion of the motor.

However, It works only when connected to PC. If I disconnect it, It doesnt work. I am providing 7.4v supply using 2s battery to power the circuit.

Here's the code

#define forwardpin 3
#define reversepin 4

int pwm;
float x;


void setup() {
  Serial.begin(9600);
  pinMode (forwardpin, OUTPUT);
  pinMode (reversepin, OUTPUT);
  

}

void loop() {
  x = pulseIn(5, HIGH);
  //Serial.print(x);
 // Serial.print("    ");

  if (x>1550)
  {   
    pwm = map(x, 1550, 2000, 0, 255);
    if(pwm<0)pwm = 0;
    if(pwm>255) pwm=255;
    analogWrite (forwardpin, pwm);
   // Serial.println(pwm);
  }
  else if(x<1450)
  {
    
    pwm = map (x, 1450, 1000, 0, 255);
    if(pwm<0)pwm = 0;
    if(pwm>255) pwm=255;
    analogWrite (reversepin, pwm);
    //Serial.println(pwm);
  }
  else
  {
    analogWrite (reversepin, 0);
    analogWrite (forwardpin, 0 );
    }
  
}

And the circuit?

If you are trying to power a motor from a Nano forget it. The Nano isn't a power supply, the motor needs its own power supply. The regulator on a Nano is not capable of powering anything much beyond the Nano. The same is true for any other Arduino board.

The BD139/140 devices aren't designed as switching transistors and have poor switching performance
even at only 0.5A output (0.5V Vsat - ie about 1 ohm on-resistance equivalent).

Also for switching duty BJTs only have about ten-fold gain, so given an Arduino pin is limited
to an absolute maximum of 40mA I don't see you being able to handle more than about 0.3A
output with them...

What max load current do you want to be able to drive? Most motors have an amp or more
stall current so you'll almost certainly need reasonable heatsinking for these transistors to
protect them from heat dissipation.

And please post the circuit - there are ways to make an H-bridge that are reasonable and many
more ways to make one that's deeply flawed(!)