L298N Motor Driver and DC Motors Not Spinning

Hi everyone, have tried to solve this issue for hours but still have not had luck. Trying to run two DC motors with a L298N motor driver, one 9V battery connected to the L298N and another 9V battery powering the Arduino. Here is some pictures with the code listed below.

|375x500

|375x500

|375x500

|375x500

|375x500

|375x500

int enA = 5;
int in1 = 6;
int in2 = 7;
int in3 = 8;
int in4 = 9;
int enB = 10;

void setup() {
  pinMode(enA, OUTPUT);
  pinMode(enB, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(in3, OUTPUT);
  pinMode(in4, OUTPUT);
}

void loop() {
  analogWrite(enA, 200);
  digitalWrite(in1, HIGH);
  digitalWrite(in2, LOW);
  analogWrite(enB, 200);
  digitalWrite(in3, HIGH);
  digitalWrite(in4, LOW);
  delay(250);
}

9 V batteries are for smoke alarms and are totally unsuitable for motors. You should use a DC power brick capable of supplying 9-12V at 1 or more Amperes instead.

Note that the ancient L298 driver is extremely inefficient, very limited in current handling capability and wastes a large amount of power as heat. You are much better off with a modern motor driver like this one.

Note that the motor driver you choose must be able to handle the [u]stall current[/u] of the motor. Either find that on the manufacturer's web page or product data sheet for your motor, or measure the winding resistance with a multimeter. The stall current is the motor voltage divided by the winding resistance (I = V/R).

Finally, did you connect the motor driver ground and the Arduino ground?

Thanks for your help, didnt know that we could not use a 9V battery to power the motor driver. Is it necessary to connect the motor driver ground and the Arduino ground? Our Arduino has a seperate power source so I did not think it mattered.

Is it necessary to connect the motor driver ground and the Arduino ground?

Always necessary to connect the grounds.

The 9V battery might be able to spin [u]one[/u] motor for a couple of minutes before dying. But don't count on it!

Ok, but connected to the two Arduino grounds is a hc06 Bluetooth module and a servo motor, how would I go about connecting the l298n ground?

You will have to figure out a way to connect several ground wires to one ground pin. Y connections work fine.

I suggest to get rid of all the other stuff, and concentrate on getting the [u]motor[/u] working. One step at a time!

jremington:
Always necessary to connect the grounds.

The 9V battery might be able to spin one motor for a couple of minutes before dying. But don’t count on it!

Like jreminghton said, i guess is the lack of ground between the arduino and the l298, because on the images you posted i cant see any wire connecting the 2 grounds

dulk: Thanks for your help, didnt know that we could not use a 9V battery to power the motor driver. Is it necessary to connect the motor driver ground and the Arduino ground? Our Arduino has a seperate power source so I did not think it mattered.

If the arduino needs to apply a signal of say 5 volt DC to a particular input port of the motor driver, then that 5 volt DC will certainly be relative to the arduino's ground.

So if the local 'ground' of the motor driver is at some 'other' voltage that is not the same as the arduino's ground voltage ........ then you can think about whether that matters or not. Also, a circuital loop is required to complete a circuit. So if the local 'gnd' of the arduino is not connected to the local 'gnd' of the motor driver, then connecting arduino 5V output (relative to arduino gnd) to the motor driver isn't going to do much (or anything).