# Driving 28BYJ-48 Stepper Motor Control with Joystick

This post shows how to control stepper motor speed and direction of rotation using Arduino UNO board and PS2 joystick.

BeginnerFull instructions provided12,202

## Things used in this project

### Hardware components

 Arduino UNO
×1
 28BYJ-48 DC 5V Stepper Motor
×1
 ULN2003 stepper motor Driver
×1
×1
 Jumper wires (generic)
×1
 Analog joystick (Generic)
×1

## Code

### CODE:

C/C++
please make sure to add all libraries that is include in this code
```//this project is made by BEASTIDREES62 https://id.arduino.cc/?code=MTxqeHweG6vL2cur&state=amxEcTB2bnNiYjluTUxmRExWaWZnOXIzUk1BLWRqZTZYUGtJNGtxODB%2Bdg%3D%3D

// include Arduino stepper motor library
#include <Stepper.h>

// define number of steps per revolution
#define STEPS 32

// define stepper motor control pins
#define IN1  11
#define IN2  10
#define IN3   9
#define IN4   8

// initialize stepper library
Stepper stepper(STEPS, IN4, IN2, IN3, IN1);

// joystick pot output is connected to Arduino A0
#define joystick  A0

void setup()
{

}

void loop()
{
// read analog value from the potentiometer

// if the joystic is in the middle ===> stop the motor
if(  (val > 500) && (val < 523) )
{
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
}

else
{
// move the motor in the first direction
while (val >= 523)
{
// map the speed between 5 and 500 rpm
int speed_ = map(val, 523, 1023, 5, 500);
// set motor speed
stepper.setSpeed(speed_);

// move the motor (1 step)
stepper.step(1);

}

// move the motor in the other direction
while (val <= 500)
{
// map the speed between 5 and 500 rpm
int speed_ = map(val, 500, 0, 5, 500);
// set motor speed
stepper.setSpeed(speed_);

// move the motor (1 step)
stepper.step(-1);

}

}

}
```

## Credits

### BEASTIDREES62

4 projects • 25 followers