Nema 17 with L298N

Hi.

I've tried out many examples and tutorials to get a Nema17 stepper motor working with a L298N - the issue is that my Nema17 has 4 wires (instead of 5 in some examples) - Red, Blue, Green and Black. Others have 4 wires but these are 2 x Red and 2 x Black.

I've messed around trying to get it to work, but I'm getting nothing at all. I can see the Serial output so I know the Arduino is running the code (the stepper example from the menu), but nothing from the motor at all.

Does anyone know of an example that uses these wires that I could follow?

Nema 17 only defines the size of the front face of the motor - 1.7 inches. There are hundreds of different Nema17 motors and many (most?) of them are not suitable for use with an L298. Usually a specialized stepper motor driver is a better option but without details of your motor I can't recommend any.

You need to post a link to the datasheet for your motor.

You should use your multimeter to determine which pair of wires belongs to each of the two motor coils. The two wires for a single coil go to one output on the L298 and the two wires for the other coil go to the other output.

...R
Stepper Motor Basics
Simple Stepper Code

Hi, thank you. It's a 17HS 1415.

Initially, I used this instructable: https://www.instructables.com/id/Control-DC-and-stepper-motors-with-L298N-Dual-Moto/

I've got it working, but with some quite bizarre behaviour.

I have the following code:

void loop() {
  // step one revolution  in one direction:
  Serial.println("clockwise");
  myStepper.step(stepsPerRevolution);
  delay(500);

  // step one revolution in the other direction:
  Serial.println("counterclockwise");
  myStepper.step(-stepsPerRevolution);
  delay(500);
}

You would expect that it would spin in one direction, then stop for 500 milliseconds and then spin in the opposite direction.

It does...sometimes. It will spin in one direction, then stop, then spin in the same direction 2 or 3 times, then spin the other way for 1 or 2 spins, then back the other way...almost randomly.

dchurch24:
Hi, thank you. It's a 17HS 1415.

Please post a link to the datsheet so we can read the technical details.

You would expect that it would spin in one direction, then stop for 500 milliseconds and then spin in the opposite direction.

You have not posted the complete program so we can't know how fast you are trying to move the motor. Always start testing with a very slow speed of (say) 2 or 5 steps per second.

And you have told us nothing about how you are powering the motors.

...R

Best to use a step motor driver rated to handle your motors. Pololu has the best selection, and they support their products.

Avoid Instructables, most of them are crap produced by people who have no idea what they are doing.

Fair enough.

#include <Stepper.h>

const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution
// for your motor

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

void setup() {
  // set the speed at 60 rpm:
  myStepper.setSpeed(190);
  // initialize the serial port:
  Serial.begin(9600);
}

void loop() {
  // step one revolution  in one direction:
  Serial.println("clockwise");
  myStepper.step(stepsPerRevolution);
  delay(500);

  // step one revolution in the other direction:
  Serial.println("counterclockwise");
  myStepper.step(-stepsPerRevolution);
  delay(500);
}

I can't find a datasheet for it anywhere.

It seems to have stabilised now, somehow!

dchurch24:
I can't find a datasheet for it anywhere.

In that case please measure the coil resistance with your multimeter and tell us what it is.

...R

Robin2:
In that case please measure the coil resistance with your multimeter and tell us what it is.

...R

To be honest, if there's the slightest resistance, the motor starts going back the other way, making it useless for anything.

Of the two motors I purchased, this one is the only one that actually moves at all. The other just makes a noise and doesn't move.

I purchased a brand new one that arrived today (a HS0423), and that one is as dead as a doornail.

I'm just going to give up I think.

You'd think making a stepper motor turn would be a simple thing to do.

dchurch24:
To be honest, if there's the slightest resistance,

I meant the electrical resistance measured in Ohms with your multimeter.

...R

Robin2:
I meant the electrical resistance measured in Ohms with your multimeter.

...R

I know.

I'm remarking that the moment the motor encounters any force (or resistance), it starts to spin in the opposite direction.

dchurch24:
I know.

So what value have measured? You are the person looking for help.

...R