Less motor power with USB conncted

Hi!

I have a simple setup with an Arduino UNO SMD R3, a Pololu VNH5019 Dual motor driver and a brushed DC motor. Everything is powered with a 12V power supply connected to the motor driver and send to the Arduino through VIN.

My problem is that I get different behavior with my motor depending on the presence of my USB cable used for programming and debugging.

As long as I am working on my project (USB cable connected) everything is fine. If I unplug the USB cable for testing, the motor has not enough power for moving the load. Everything works again when I plugin the cable again...

Whats the problem here? The 12V at the motor driver are always 12V, the USB connection does not affect this. Grounding? The PWM in this case is at 20%

12V is often too much for Vin, depending on what else is connected to the Arduino. The voltage regulator overheats.

Post the code, using code tags, and a complete wiring diagram (hand drawn, not Fritzing).

#include <DualVNH5019MotorShield.h>

// Define Motor Driver pins
#define INA1		5
#define INB1		4
#define EN1DIAG1	6
#define CS1			A0
#define INA2		7
#define INB2		8
#define EN2DIAG2	12
#define CS2			A1

#define BUTTON1		A4

DualVNH5019MotorShield motorDriver(INA1, INB1, EN1DIAG1, CS1, INA2, INB2, EN2DIAG2, CS2);

void setup() {
	Serial.begin(115200);

	Serial.println("Setup");
	
	motorDriver.init();
	
	pinMode(BUTTON1, INPUT); // Button 1
}

void loop() {
	static uint8_t button1 = 0;
	static uint8_t deb1 = 0;
	
	//Button debounce
	if (digitalRead(BUTTON1) == LOW) {
		delay(5);
		deb1++;
		if (deb1 >= 20) {
			button1 = 1;
			deb1 = 20;
			Serial.println("Button1");
		}
	}
	else {
		deb1 = 0;
	}
	
	
	if (button1) {

		button1 = 0;
		
		for (int i = 0; i >= -140; i -= 4) {
			motorDriver.setM2Speed(i);
			delay(10);
		}
		delay(1000);
		for (int i = -140; i <= 0; i += 4) {
			motorDriver.setM2Speed(i);
			delay(8);
		}
	}
}

The code ramps up the motor driver PWM from 0 to 35% after button 1 is pressed. The speed stays there for one second and goes back to 0. Without USB no problem. With USB connected no motor movement. The load seems to be too heavy.

Use your multimeter to check the Arduino supply voltage, when powered by the motor shield.

In particular verify that the 5V output remains at 5V at all times. If not, the regulator is overheating.