one MOSFET IRF520 and two engines

Hi,

So i have a problem with my arduino car. I have two motors connected to a MOSFET IRF520 on every axle and the problem is that they are not getting the voltage they sholud (they are getting about half of it) (and I'm checking it on the module) and for some weird reason if i connect one motor in works perfectly fine. Do You have any solution to this?

#include "HCMotor.h"

#define MOTOR_PIN1 7
#define MOTOR_PIN2 8

HCMotor HCMotor1;
HCMotor HCMotor2;

int Speed=0;

void setup() 
{
  pinMode(LED_BUILTIN, OUTPUT);
  
  HCMotor1.Init();
  HCMotor1.attach(1, DCMOTOR, MOTOR_PIN1);
  HCMotor1.DutyCycle(1, 100);

  HCMotor2.Init();
  HCMotor2.attach(0, DCMOTOR, MOTOR_PIN2);
  HCMotor2.DutyCycle(0, 100);

}

void loop() 
{
     delay(5000);
     
     digitalWrite(LED_BUILTIN, HIGH);
     
     for(Speed;Speed<100;Speed+=10)
      {
       HCMotor1.OnTime(1, Speed);
       HCMotor2.OnTime(0, Speed);
       delay(10);
      }
     delay(5000);
     
     digitalWrite(LED_BUILTIN, LOW);
     
     for(Speed;Speed>0;Speed-=10)
      {
       HCMotor1.OnTime(1, Speed);
       HCMotor2.OnTime(0, Speed);
       delay(10);
      }
}

The IRF520 won't work with Arduino, as it is not a logic level MOSFET. It requires 10 V on the gate to be fully switched on. In your case it is only partially on.

Look for a logic level MOSFET, such as this one, or use a suitable motor driver, like those from Pololu.

The IRF520 is a truly ancient device with appaling low performance by modern standards. Its also
rated at 100V (higher voltage devices have higher on-resistances anyway).

What is the DC voltage involved?

What is the stall current of the motors?

Without those values we would be just guessing.