Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
eemaan05
Published © GPL3+

Control 2 stepper motors with a joystick

Control two 28BYJ-48 stepper motors with a joystick

IntermediateShowcase (no instructions)15,073
Control 2 stepper motors with a joystick

Things used in this project

Hardware components

Analog joystick (Generic)
×1
28BYJ-48 stepper motor
×2
Arduino UNO
Arduino UNO
×1
ULN2003APG stepper driver
×2
Jumper wires (generic)
Jumper wires (generic)
×1

Story

Read more

Schematics

Two steppers with joystick

2 stepper with joystick

Code

Stepper with joystick code

C/C++
#include <Stepper.h>
#define STEPS 2038 // the number of steps in one revolution of your motor (28BYJ-48)
Stepper stepper(STEPS, 8, 10, 9, 11);
Stepper stepper1(2038, 2, 4, 3, 5);
int potState = 0; 
int pot1State = 0;
void setup() {
  Serial.begin(9600); 
 }
 void loop() {
  potState = analogRead(A0); //reads the values from the potentiometers
  pot1State = analogRead(A1); //
  
  Serial.println(pot1State); // sends joystick data to serial port for debuging
  stepper.setSpeed(5);
  stepper1.setSpeed(5);

  if (potState > 600){  //all code below controls movement
    stepper.step(10);
  }
  
  if (potState < 400){
    stepper.step(-10);
  }

  if (pot1State < 400){
    stepper1.step(-10);
    delay(5);
  }
  if (pot1State > 600){
    stepper1.step(10);
  }
  
 }

Credits

eemaan05
1 project • 0 followers

Comments