Stepper Motor Library


Sorry, I was unable to put library below.

So simple and yet so not so simple.

How do I get the library in the folder so the program compiles/?


library for 28BYJ48 Stepper motor and ULN2003 driver.
Here is the source code for our 28BYJ48 stepper motor, ULN2003 driver library, as well as an implementation. Check out the diagram for the wiring.

The header file:

#ifndef Stepper_h
#define Stepper_h

class StepperMotor {
    StepperMotor(int In1, int In2, int In3, int In4);    // Constructor that will set the inputs
    void setStepDuration(int duration);    // Function used to set the step duration in ms
    void step(int noOfSteps);    //    for(int sequenceNum = 0;  sequenceNum <= noOfSteps/8; sequenceNum++){
        for(int position = 0; ( position < 8 ) && ( position < ( noOfSteps - sequenceNum*8 )); position++){
            for(int inputCount = 0; inputCount < 4; inputCount++){
                digitalWrite(this->inputPins[inputCount], sequence[(int)(3.5 - (3.5*factor) + (factor*position))][inputCount]);
            } Arduino


An implementation:

#include <StepperMotor.h>

StepperMotor motor(8,9,10,11);

void setup(){

void loop(){

Step a certain number of steps. + for one way and - for the other

    int duration;    // Step duration in ms
    int inputPins[4];    // The input pin numbers



The cpp file:

#include <Arduino.h>
#include <StepperMotor.h>

StepperMotor::StepperMotor(int In1, int In2, int In3, int In4){
    // Record pin numbers in the inputPins array
    this->inputPins[0] = In1;
    this->inputPins[1] = In2;
    this->inputPins[2] = In3;
    this->inputPins[3] = In4;

    // Iterate through the inputPins array, setting each one to output mode
    for(int inputCount = 0; inputCount < 4; inputCount++){
        pinMode(this->inputPins[inputCount], OUTPUT);
    duration = 50;

void StepperMotor::setStepDuration(int duration){
    this->duration = duration;

void StepperMotor::step(int noOfSteps){
        The following 2D array represents the sequence that must be
        used to acheive rotation. The rows correspond to each step, and
        the columns correspond to each input. L
    bool sequence[][4] = {{LOW, LOW, LOW, HIGH },
                          {LOW, LOW, HIGH, HIGH},
                          {LOW, LOW, HIGH, LOW },
                          {LOW, HIGH, HIGH, LOW},
                          {LOW, HIGH, LOW, LOW },
                          {HIGH, HIGH, LOW, LOW},
                          {HIGH, LOW, LOW, LOW },
                          {HIGH, LOW, LOW, HIGH}};
    int factor = abs(noOfSteps) / noOfSteps;    // If noOfSteps is +, factor = 1. If noOfSteps is -, factor = -1
    noOfSteps = abs(noOfSteps);    // If noOfSteps was in fact negative, make positive for future operations

        The following algorithm runs through the sequence the specified number
        of times

Do you have a problem with the library? you can't compile the code?

56Frank (author)  AYassineLebouiha16 days ago


The problem I have is this:

The code and the library are all on one page.

I copied the code in Arduino IDE

Then copied the library on a folder Stepper_motor 28BJY_28

I compiled the the code and it did not compiled.

I had my work checked all was good, but it failed.



Why you don't use the pre installed arduino library called "Stepper"? Or do you want to use other functions?
Otherwise you can download a library called "Stepper_28BYJ_48" via the Arduino IDE