half stepping l298

I was looking for the very basics of steppers bit it seems the posts all use the library stepper.h I wanted to walk through the basics.

The first sketch was to turn one coil on, then off, then the next coil and so on.
The results were interesting in that with a delay of 2 on and 2 off, the motor ran very smoothly. As the delay was increased, the motor started to jump on the desk. It shook quite alarmingly.

I added a pot to alter the delay, connected both the on and off delay to one pot.
The only time the motor ran smooth was when it had a delay of about 2.

My set-up is a 5V to the L298. UNO is powered from the USB.
Motor is connected to the L298 driver. UNO uses 4 pins. Common ground.
All very simple and straight forward.

The shaking was bothersome as I need to run this at low speed. I decided to half step the motor. Half step is coil1, then coil1 and coil3, then only coil2, then coil3 and coil2, then only coil2…

This is to apply power to 2 coils at the same time during the half step so the motor would move between the two coils half way. This results in 2 coils being powered so that the half step is about 30% stronger than a full step. But, the coil moving half way between full steps really smooths out the motor vibrations.

This sketch uses delay based on the pot input.
(Feel free to post code of not using delay if you do not like using delay when testing )

The problem comes with the power at half step. The driver lacks a sense resistor that would use the L298 internal circuitry to limit amps to the motor. The proper technique would be to have one resistance for full step and a second for half step and change these as the motor changes from step to half to step to full to half… Alas, this cheap driver lacks that ability.

The result here is that the stepper motor runs verify smoothly at low step rates.

Now I need to make the motor run faster. : )

  stepper with L298 board running half steps to have smoother low speed movement
int step1 = 6;
int step2 = 7;
int step3 = 8;
int step4 = 9;

int delay1 = 2;
int delay2 = 2;

int potIn = A0;    // select the input pin for the potentiometer
int ledPin = 13;      // select the pin for the LED
int potValue = 0;  // variable to store the value coming from the sensor

String stringOne, stringTwo, stringThree;

void setup() {                

  pinMode(step1, OUTPUT);     
  pinMode(step2, OUTPUT);   
  pinMode(step3, OUTPUT);   
  pinMode(step4, OUTPUT);   
  pinMode(ledPin, OUTPUT);  
void loop() {
  digitalWrite(step1, HIGH);    
  digitalWrite(step4, LOW);    
  digitalWrite(step3, HIGH);      
  digitalWrite(step1, LOW);    
  digitalWrite(step2, HIGH);    
  digitalWrite(step3, LOW);    
  digitalWrite(step4, HIGH);    
  digitalWrite(step2, LOW);    
  potValue = analogRead(potIn);     // read the value from the pot:
  delay1=(potValue / 10); //reduces pot value to 1/10th to limit delay to 100
  if(delay1<2){                 //limits the delay to minimum of 1
  String stringOne = "potValue ";
  String stringTwo = "  delay1 ";
  String stringThree = stringOne + potValue + stringTwo + delay1;

How much current does your motor need?

The A4988 stepper driver boards are available cheaply on Ebay if you don't want to pay the Pololu price. Microstepping options are built in, as is current limiting.

The L298 is not designed to control steppers.


A lot of people use the L298 as a dual H-bridge to control steppers. and the sellers list it for just that use.

It will work on steppers because the dual H-bridge is how one controls steppers. Alas, one problem is that it uses 4 output pins on the Arduino. As for power, the data sheet lists 4 amps as the max.

The low cost, the high current and the free shipping seem to attract a lot of people.

For high power, I use Gecko-201 stepper drivers, up to 70 volts, 7 amps, with step and direction and 10 microsteps. has a lot of design into it, including correction of mid-band harmonics.... all well and good for the high power CNC crowd, but not needed for the hobby market.

I keep seeing posts about using these L298 boards and figured I'd toss my hat into the ring.

your chip, the A4988 is HIGHLY RECOMMENDED (by me) as the starter chip for those who did not already go out and buy the L298.

using a microstepper will dramatically smooth out the stepping and the motor vibration will be greatly reduced. the down side is output step count.

The problem is that for a 200 step per rotation motor, and a full step driver, one needs to output 200 steps. on a half step, that becomes 400 steps. An 8 microstep motor would be 200x8 or 1,600 steps per revolution.

a HUGE benefit is that the Allegro A4988 chip has external sense resistors. these limit the amp output current to that of the motor as long as the user makes the correct selection. and A4988 is designed for 2 pins, step and direction, thus freeing up 2 pins that the L298 uses. microstepping can be by using a pin, but more commonly by jumpers.

Robin2: The L298 is not designed to control steppers.

I take it you haven't read the datasheet?

Unless you are meaning "driving" is different from "control", then I can give you that; the L297 (companion part to the 298 for stepper "control") is the part needed...

@dave-in-nj, "Granny" and "Eggs" come to mind. Sorry. I assumed you were looking for information rather than providing it.

@cr0sh, the L298 has no specialized features for stepper motors such as microstepping or current limiting and it relies on the Arduino to figure out when to switch current for the individual coils. It can be used to drive a stepper motor but it is not the best choice by a long way.


Robin2: @dave-in-nj, "Granny" and "Eggs" come to mind. Sorry. I assumed you were looking for information rather than providing it.

I should have been more direct.

any suggestions to spin faster ?

What about getting your software to change from half stepping to full stepping when the speed is high enough for full steps to be smooth enough?

Personally I don't see the point in helping people to use an L298 to drive a stepper when it would be much easier for them to get a proper stepper driver. I wish something could be done to stop retailers saying that the L298 is suitable. Apart from anything else it is a very poor introduction to stepper motors.

To my mind The L298 is only suitable in the sense that a 1 inch paint brush is suitable for painting the outside walls of a house.


half to full will work with the L298, and the program will work for any h-bridge or transistors. lots of people use some from of transistors to controll steppers.

for this problem, going from half to full step will double the step rate, but that is still much slower than the motors are capable of performing.

I have one project that will use a stepper and a pot. the stepper will rotate foam for a hot wire cutter to cut out shapes for metal casting. no need for a microstepper for that project. in fact the whose reason to go to half step was to smooth out the motor.

alas, for the fast step rate, . I guess the pulse rsignal needs to come from a different source.