Spinning Motor with L298N

I just recently started working with electronics and Arduino. I was able to connect the Arduino to an L298N.

I was just trying to run a 5V DC motor (which spins if I connect its pin to 5V and GND on Arduino) with the L298N.

I am using the following code and I connected the pins 9,8,7 to ENA, IN1, and IN2. When I power the L298N with 5V, and check the voltage across OUT1 and OUT2, I notice it moving between 0 and 5V as desired. But the moment I connect it to the DC motor, the voltage reading goes to 0 and the motor does not spin. It still spins if I connect it to the Arduino 5V and Gnd, but not the L298N.

I also tried to connect a 12V electromagnet instead of the motor and applied 12 V power to the L298N. But same results.

// Motor A connections
int enA = 9;
int in1 = 8;
int in2 = 7;

void setup() {
// Set all the motor control pins to outputs
pinMode(enA, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);

// Turn off motors - Initial state
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
}

void loop() {
directionControl();
delay(1000);
}

// This function lets you control spinning direction of motors
void directionControl() {
// Set motors to maximum speed
// For PWM maximum possible values are 0 to 255
analogWrite(enA, 255);

// Turn on motor A & B
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
delay(2000);

// Turn off motors
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
}

Did you connect the motor to OUT1 and OUT2?
The L298 is going to drop at least 1.6 volts or more depending on motor current (which you didn't say), you probably need at least 7 to 8 volts for a 5V motor.

(deleted)

I connected the OUT1 and OUT2 to the motor. I tried increasing the voltage to 7-8 V and still see no spinning. I just find it strange that with the motor disconnected, the OUT1 and OUT2 measure the voltage I expect, but when I connect the motor to the output pins, the voltage reading is 0 and there is no motion.

Just as a recap:
In the case of most modules (L298) the circuit can be supplied in two different ways.Since the module incorporates a on-board 5.0 VDC regulator, the required supply voltage for the operation of the actual L298 IC can be taken from the motor supply voltage and is the preferred way of going about this. Next, if you want to keep the motor supply voltage completely separate and independent there should be a jumper on the module. The jumper is normally labeled J1 and has an A & B position. The A position being the preferred position but if you go this route using the onboard 5 volt regulator the supply voltage should be at least 7 volts to make up for regulator dropout voltage. So if powering the L298 board from the 5 volts of an Arduino board it likely won't work.

The Enable A or B are set High for the corresponding motor for operation and then IN1 or IN2 control motor 1 direction and IN3 and IN4 control motor 2 direction.

Ron

1 Like

tackymime:
I connected the OUT1 and OUT2 to the motor. I tried increasing the voltage to 7-8 V and still see no spinning. I just find it strange that with the motor disconnected, the OUT1 and OUT2 measure the voltage I expect, but when I connect the motor to the output pins, the voltage reading is 0 and there is no motion.

You never said what your motor was or what its stall current rating was. The L298 is OK for driving motors with a stall current of 1A or less at 12V or more (preferable more). For 5V its hopeless anyway, but certainly won't
provide stall current for anything but a tiny motor at those voltages.

The only selling point of the L298 is that its through-hole. Its a primitive decades old device that's never used
in new designs nor has been for 20 years, as modern MOSFET chips far exceed its performance with way less
heat dissipation to deal with. If you do have to use it I'd recommend sticking to high voltage low current loads.

Hi,
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Can you please post an image of your project so we can see your component layout?

Thanks.. Tom.. :slight_smile: