Arduino Stepper Motor Driver

Arduino Stepper Motor Driver

In this tutorial I will explain how to drive a stepper motor using Arduino microcontroller. For this project, in addition to the microcontroller and the stepper motor, an L298N H-bridge module is necessary. The L298N H-bridge dual motor driver module is inexpensive and available from many online components vendors including eBay. This let me in for a big surprise!

Stepper Motor

With a stepper motor you can “step” exactly an applied angle. Further, a stepper motor can hold its current position when it is not moving. Although stepper motors are available in unipolar and bipolar varieties, the bipolar type is the strongest type of stepper motor. Bipolar stepper motor and usually have four leads connected to two sets of internal electromagnetic coils. The “stepping” is achieved by changing the direction of current through the coils.

stepper motor

(stepper motor)

Stepper Motor Driver

Stepper motors are not like simple dc motors and cannot be driven by feeding just a dc voltage. Dedicated driver circuit (and quite often a microcontroller) is needed to control the speed and direction of a stepper motor. Here, I am using a pre-wired L298N H-bridge dual motor driver module as the stepper motor driver. The module is really a “standalone” type includes power connectors, flywheel diodes, visual indicators, and even an onboard voltage regulator chip. I am sure, this is the right way to save money, time, and effort!

stepper motor controller module

(stepper motor controller module)

Arduino Controller Hookup

My initial experiment was carried out with the help of a 12V bipolar stepper motor. Based on that experimentation, instructions are given below for you to proceed with your own experiments. At first, Connect the twin-wires (A-B) from the stepper motor to the driver module connection points MA+, MA-, MB+ and MB- respectively. Leave all jumpers of the driver module in place, and connect headers IN1, IN2, IN3 and IN4 to Arduino digital pins D8, D9, D10 and D11 respectively. Next, connect Arduino GND to point GND , and Arduino Vin to +5V OUT point on the module. Finally, connect a 12V/1A external power supply to points +12V IN and GND of the driver module.


Now you can control the stepper motor from your sketches, thanks to built-in Stepper library in the Arduino IDE. For pre-flight test, you can load the stepper_oneRevolution sketch included with the Stepper library. So have fun and build something!


#include   const int stepsPerRevolution = 200; // steps per revolution of 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(60);     // 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);  }  
hardware used

((hardware used for the experiment at author’s lab))

Important points to take note

  • Refer the datasheet of your bipolar stepper motor
  • You will need to determine the A+, A-, B+, and B- wires of your stepper motor. If you stepper motor shudders but does not move, it is likely an error in the ordering of the coils
  • Check the value for const int stepsPerRevolution = 200; in the sketch, and change the 200 to the number of steps per revolution for your stepper motor. For example, change the value to 48 for a “7.5º Step” type stepper motor
  • Also check and tweak the RPM value (presetted to 60) in the line myStepper.setSpeed(60);