top of page

Controlling stepper motor with Joystick Sensor and Arduino

Updated: Jul 10, 2022

A stepper motor is a brushless synchronous electric motor that divides a complete rotation into steps of equal length. The motor position can be controlled precisely without any feedback mechanism, as long as the motor is designed as per the requirement and application. Based on the number of steps per rotation, different types of stepper motors are available. They are usually found in 3D-printers, desktop printers, CNC milling machines, and any other application that requires accurate positioning control.

It converts a chain of input pulses into a precisely defined increment in the mechanical shaft position, where each pulse moves the shaft by a fixed angle, which makes the shaft rotate in series of discrete angular steps.

Step Angle = 360/(Stator Phases * Rotor Teeth) degrees

Types of stepper motors:

  • variable Reluctance Stepper Motor

  • Permanent Magnet Stepper Motor

  • Hybrid Stepper Motor

Hardware Requirements:

1. Breadboard:


A #breadboard is a flat piece of wood that is provided with holes that allow users to build a circuit including the components and connections without the need for soldering due to which it is reusable and finds its best usage for the students who are new to build circuits. The holes in any horizontal line will be in series whereas the vertical holes remain at an equipotential state. There are different sizes of breadboards available in the market which include "full size", "half-size" and, "mini size" breadboards.

You can purchase breadboard here.

2 .ULN2003A- Driver Board:

ULN2003A - Driver Board
ULN2003A - Driver Board

ULN2003A is a 16 pin integrated circuit. It has seven Darlington transistors installed which would aid to control 7-loads at a time. The voltage and current limits for any load are 50V and 500mA. ULN2003 is provided with internal safety protection from back EMF. The Driver Circuit consists of 7-input and 7-output pins and 1-common and 1-ground pin.

You can purchase breadboard here.

3. Arduino UNO: The Arduino is a Programmable #microcontroller, it's an open-source electronics proto-type platform. It interacts with the user by receiving input with the aid of sensors and provides the output employing LED, buzzer, etc.,

NOTE: To know more about Arduino UNO, go through this article.

You can purchase Arduino UNO here.

4.28BYJ48 Stepper Motor: The 28BYJ48 is a 5-wire unipolar stepper motor that runs on 5 volts. The motor can be positioned accurately, each high pulse given as an input, energize the coil and attracts the nearest teeth of the cogged wheel, and drives the motor one step ahead. The Stepper motor is connected to a driver which converts the command pulses into actual motor driving steps. The stepper motor consists of 5-leads in which 4-unipolar coil leads and one supply lead (5V).

28BYJ48 -Stepper Motor
28BYJ48- Stepper Motor

You can purchase a Stepper motor here.

5. Jumping wires: Jumper wires are used to establish connections between different components in the circuit.

Jumping wires
Jumping wires

You can purchase Jumping wires here.

6. Joystick Sensor Module: Joystick Sensor has two individual potentiometers one for each x and y axes to read the user's input. It is equipped with a freewheeling holder, that allows changing the knob of the potentiometer which changes resistance and inturn the analog output.

The potentiometers are connected between Vcc and Ground. It is used to control the pointer movement in two dimensions and is sometimes also called a Control Stick.

Joystick Sensor Module
Joystick Sensor Module

You can purchase the Joystick sensor here.

Circuit Connection:

Circuit Diagram
Circuit Diagram

Circuit connection involves the following steps:

  • First, we connect the Stepper Motor to Arduino through the driver board.

  • The pins IN1 to IN4 of the driver board are connected to 5-8 PWM pins of Arduino.

  • The X-axis pin of the Joystick is connected to Ao pin of the Arduino.

  • We provide a power supply to the Joystick by connecting 5V to the Vcc and ground to the ground pin.

  • Similarly, with the driver, we connect the positive terminal to 5V and the negative terminal to ground of the Arduino.

Complete Code:

Note: Please change the file format to .ino(Arduino IDE) format before you upload the code.


After uploading the code, you can control the motion of the stepper motor using the joystick. If you move the joystick in a particular direction, the motor starts to move and the values of x will be appearing on the serial monitor. If the direction of the joystick is changed, then the motor will rotate in the opposite direction. If the joystick is present in the center then there will not be any motion in the motor.

Watch this video for a practical explanation of the code and circuit connections.

Video By - Aishwarya Balaji


See also:

Interfacing Tilt Sensor with Arduino Uno

How to interface a DC motor with Arduino UNO using TinkerCAD?

Interfacing Soil/Moisture Sensor with Arduino

629 views2 comments

Related Posts

See All
bottom of page