How to control step motor with Arduino?

Step motor is a type of motor that we can control angular. With this feature, you can use it in many applications. Step motors should buy with the driver circuit board.

How to connect the step motor to the Arduino board?

First, place the cable of the step motor in the drive card slot. As seen in the diagram of the driver circuit board;

  • In1 PIN number 8 of Arduino Pine,
  • In2 PIN number 9 of Arduino Pine,
  • In3 PIN number 10 of Arduino Pine,
  • In4 PIN number 11 of Arduino Pine,
  • + PIN (pozitive pin) 5V of Arduino Pine,
  • –  PIN (ground pin) connect the pin to the Arduino GND pin.


That’s all we have. Now it’s time to write the Arduino codes.

How to write stepper motor caduino codes?

Step 1: first download the VirtualWire library file which is required for stepper motor control by clicking on the link below. You need to copy it into the Libraries folder in the folder where Arduino is installed.

Click here to download the Arduino stepper motor library…

  • #include <X113647Stepper.h> : With this code, we include the step motor library file in the Arduino codes.
  • const int stepsPerRevolution = 32 * 32;  with this code, we determine how many steps we want the stepper motor to rotate. If you want the stepper motor to turn more turns, you can change the number here.
  • X113647Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);  à with this code, we select the arduino pins that we connect to the stepper motor circuit board.
  • setSpeed(100);  with this code we set the speed of rotation of the stepper motor. You can drive the step motor faster or slower according to your project needs.
  • myStepper.step(stepsPerRevolution);delay(50);myStepper.step(-stepsPerRevolution);


    with this codes, we can enable the stepper motor to turn in one direction and then in the opposite direction.

In the project, if the steps to return and forward are different, you can create a variable and move back to the different step number and back to the different step number.

In this tutorial, we have reviewed the step motor and the arduino connection diagram and the arduino codes that we will write in order to use the step motor.

You can write your questions from comments. Thanks for watching…

Leave a Reply

Your email address will not be published. Required fields are marked *