Controlling Stepper Motor with Joystick and Arduino:
In this post, we will learn about Controlling Stepper Motor with Joystick and Arduino. Here we will control stepper motor speed and direction of rotation using Arduino UNO board and PS2 joystick.
We will be using 28BYJ-48 unipolar 5V DC Stepper Motor which comes with an internal driver. So there is no need for any Easy Step Driver. Rather we will use ULN2003A Darlington Pair Motor Driver IC. The PS2 Joystick consists of two potentiometers of 10k ohm, i.e one for the X-axis and the other for the Y-axis. It also consists a push-button. But we will use only the X-axis to control the stepper motor movement.
Components Required:
1. Arduino UNO Board
2. 28BYJ-48 5V DC Stepper Motor
3. ULN2003 Motor Diver IC
4. PS2 Joystick
5. 5V DC Supply
What is Stepper Motor?
A stepper motor or step motor or stepping motor is a brushless DC electric motor that divides a full rotation into a number of equal steps. The motor’s position can then be commanded to move and hold at one of these steps without any position sensor for feedback (an open-loop controller), as long as the motor is carefully sized to the application with respect to torque and speed.
Stepper Motor 28-BYJ48 Connection:
Stepper Motor 28-BYJ48 is a Unipolar motor with a 5-lead coil arrangement. There are four coils that have to be energized in a particular sequence. The Red wires will be supplied with +5V and the remaining four wires will be pulled to the ground for triggering the respective coil. We used the Arduino board to energize these coils in a particular sequence and make the motor perform the required number of steps.
Need of ULN2003 as Driver:
Stepper Motors operates with the help of the driver IC. The reason is the controller requires high current for operation but the stepper motor alone will not be able to provide enough current from its I/O pins for the motor to operate. So with the application of ULN2003 as a driver module current is amplified.
Circuit Diagram & Connection:
For Controlling Stepper Motor with Joystick and Arduino, assemble the circuit as shown in the figure below.
Steps Calculations:
There is a need for calculations of steps before uploading code to Arduino board for Stepper motor Control with Potentiometer and Arduino
In Arduino, we will be operating the motor in a 4-step sequence so the stride angle calculation is necessary.
1 2 3 4 |
Stride Angle = 5.625° Arduino Step Sequence = 4 Required Step Sequence = 8 Steps per Revolution = 5.625*2 = 11.25 |
Source Code/Program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
#include <Stepper.h> #define STEPS 32 // define stepper motor control pins #define IN1 7 #define IN2 6 #define IN3 5 #define IN4 4 // 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 int val = analogRead(joystick); // 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); val = analogRead(joystick); } // 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); val = analogRead(joystick); } } } |
1 Comment
hello, im so interested with that project, but i have a question. How can i used x and y axis on joystick to control the stepper ? I have tried to control the stepper using x and y axis but it’s getting error :'(