L298N and bipolar stepper motor

On an ebay whim, I picked up a couple steppers. I'm not really sure the exact specs, but I think they are the variety used for 3d printers (driven at 24v). 4 wires, must be bipolar

Minebea Motor, 17PM-K404-05W

I also picked up a couple L298N driver boards. With a 12v power supply to the L298N board, the motor just vibrates with delay(10) between the steps. Or when doing the "one step at a time" example sketch with a delay(500) between the individual steps, I think it might actually be stepping. But something is clearly not right.

Any idea if I can drive this motor with an L298n? Will 12v not be enough?

And FWIW, I used an ohm meter to determine the wire pairs.

Have you tried swapping a coil winding over?

Grumpy_Mike:
Have you tried swapping a coil winding over?

Pretty sure I've identified the correct pairs of wires (using an Ohm meter). I did try swapping the connection of one pair.

In which case can you post your schematic and the code you are trying to run.

Schematic is too simple to draw. I've got one of these L298N boards:

ENA and ENB are jumpered on.

Arduino #8 --> IN1
Arduion #9 --> IN2
#10 --> IN3
#11 --> IN4

OUT1/2 to one pair of stepper wires. Out 3/4 to the other pair

12V supply to the 12V pin on the L298N board. Same for ground. Nothing connected to the 5V pin on the L298N board.

I've tried various example code.

I guess my questions whether this should work.

int IN1=8;//connected to Arduino's port 3
int IN2=9;//connected to Arduino's port 4
int IN3=10;//connected to Arduino's port 6
int IN4=11;//connected to Arduino's port 7

void setup()
{
pinMode(IN1,OUTPUT);
pinMode(IN2,OUTPUT);
pinMode(IN3,OUTPUT);
pinMode(IN4,OUTPUT);
}
void loop()
{/*In the way of 4 beats to drive the stepping motor,A group connected to motorA,B
B group connected to motorB,Suppose A representing the forward current of A group,
A- representing the reverse current of A group,B representing the forward current of B group,
B- representing the reverse current of B group.
this way run as follow:
AB A-B A-B- AB-
or
AB AB- A-B- A-B
*/
digitalWrite(IN1,LOW);
digitalWrite(IN2,HIGH);
digitalWrite(IN3,HIGH);
digitalWrite(IN4,LOW);
delay(10);
digitalWrite(IN1,LOW);
digitalWrite(IN2,HIGH);
digitalWrite(IN3,LOW);
digitalWrite(IN4,HIGH);
delay(10);
digitalWrite(IN1,HIGH);
digitalWrite(IN2,LOW);
digitalWrite(IN3,LOW);
digitalWrite(IN4,HIGH);
delay(10);
digitalWrite(IN1,HIGH);
digitalWrite(IN2,LOW);
digitalWrite(IN3,HIGH);
digitalWrite(IN4,LOW);
delay(10);
}

DISREGARD! Connecting the +5V volt (as well as the +12V) worked! Not sure what I was thinking :slight_smile:

Hey, man. I did this same thing. It's actually the ground. These L298 boards have a 5v supply voltage on them. If you power your arduino with the 5v supply from the L298 and use the same ground, it all works fine.

However, when I got my motor spinning using the most basic code with the Stepper class, powered down, and then powered back up... something was wrong. I think it's the L298. Just doesn't seem right. I don't know if these are good drivers or not.

I'm a noob, so I'm not entirely sure of the issue, but to have it work and then not makes me feel like the L298 has failed. I'm going to try your code tomorrow and see what happens though. It might be the Stepper class.

The very first time I got on this forums to search for a specific problem, and I got to this post, concerning the very same driver I bought on the very same auction. I have read plenty of examples elsewhere on connecting the drivers, but not until I read here that I need to power up the Arduino from the driver (I had separate sources of power for each one). So it works now like I wanted.
I have modified the scheme and added the wire to the ENA pin, so I could set the speed (motor is from a toy powered by a 1.5V).
So, the scheme: 12&13 PWM to driver IN1&IN2, 10 PWM to driver ENA (I have removed the jumper). Power (7.5V) to the +12V, wire from the +5V goes to the Arduino power. It doesn't says this in the manual.

The code:

int dir1PinA = 13;
int dir2PinA = 12;
int speedPinA = 10;  // to enable pin


void setup() {
  
pinMode (dir1PinA, OUTPUT);
pinMode (dir2PinA, OUTPUT);
pinMode (speedPinA, OUTPUT); 


}


void loop() {

analogWrite (speedPinA, 128);  
digitalWrite (dir1PinA, HIGH);
digitalWrite (dir2PinA, LOW);
delay(1500);
// slow down
analogWrite (speedPinA, 80);
delay(200);
analogWrite (speedPinA, 60);
delay(200);
analogWrite (speedPinA, 10);
delay(200);

//reversing the rotation
digitalWrite (dir1PinA, LOW);
digitalWrite (dir2PinA, HIGH);
analogWrite (speedPinA, 50);
delay(200);
analogWrite (speedPinA, 90);
delay(200);
analogWrite (speedPinA, 105);
delay(1500);
//halt it
analogWrite (speedPinA, 0);
delay(400);
}

Yup. Absolutely nowhere does it mention this info. You have two options.

  1. You can pull the power jumper on the L298n board directly behind the 12v input and give it the 5v supply from the arduino as long as the two input voltages are grounded together.

  2. Leaving the power jumper in enables the onboard 5v supply from the 12v input voltage. You can use this supply to power your arduino. The arduino must be ground to the 12v supply ground. You'll need to make sure your main supply voltage is enough to power your motors and your arduino.

I wouldn't recommend the second option if you're trying to push higher voltage to your motors. It'd be better to supply the 5v for logic from the arduino in that case as described in option 1.

Having said that, with my experience so far using the L298n, I would recommend keeping the project at 12v or under, even though it's rated up to 46v and 4amps. I have experienced failure with two of these boards trying to drive a 24v 2a motor. Those having success with this board seem to be staying at around 12v.

Some drivers to consider for higher voltage are the DRV8825 and the Pololu A4988.