Devices & Components
Arduino Uno Rev3
28BYJ-48 DC 5V Stepper Motor
Analog joystick (Generic)
Jumper wires (generic)
Breadboard (generic)
ULN2003 stepper motor Driver
Project description
Code
CODE:
c_cpp
please make sure to add all libraries that is include in this code
1//this project is made by BEASTIDREES62 https://id.arduino.cc/?code=MTxqeHweG6vL2cur&state=amxEcTB2bnNiYjluTUxmRExWaWZnOXIzUk1BLWRqZTZYUGtJNGtxODB%2Bdg%3D%3D 2 3 4// include Arduino stepper motor library 5#include <Stepper.h> 6 7// define number of steps per revolution 8#define STEPS 32 9 10// define stepper motor control pins 11#define IN1 11 12#define IN2 10 13#define IN3 9 14#define IN4 8 15 16// initialize stepper library 17Stepper stepper(STEPS, IN4, IN2, IN3, IN1); 18 19// joystick pot output is connected to Arduino A0 20#define joystick A0 21 22void setup() 23{ 24 25} 26 27void loop() 28{ 29 // read analog value from the potentiometer 30 int val = analogRead(joystick); 31 32 // if the joystic is in the middle ===> stop the motor 33 if( (val > 500) && (val < 523) ) 34 { 35 digitalWrite(IN1, LOW); 36 digitalWrite(IN2, LOW); 37 digitalWrite(IN3, LOW); 38 digitalWrite(IN4, LOW); 39 } 40 41 else 42 { 43 // move the motor in the first direction 44 while (val >= 523) 45 { 46 // map the speed between 5 and 500 rpm 47 int speed_ = map(val, 523, 1023, 5, 500); 48 // set motor speed 49 stepper.setSpeed(speed_); 50 51 // move the motor (1 step) 52 stepper.step(1); 53 54 val = analogRead(joystick); 55 } 56 57 // move the motor in the other direction 58 while (val <= 500) 59 { 60 // map the speed between 5 and 500 rpm 61 int speed_ = map(val, 500, 0, 5, 500); 62 // set motor speed 63 stepper.setSpeed(speed_); 64 65 // move the motor (1 step) 66 stepper.step(-1); 67 68 val = analogRead(joystick); 69 } 70 71 } 72 73}
Downloadable files
Schematics of this projects
Schematics of this projects

Schematics of this projects
Schematics of this projects

Comments
Only logged in users can leave comments