Can anyone help me on my project, i am new in using Arduino and cannot quite figure out how to control the stepper motor using a mouse wheel rotary encoder…
This is my code for the stepper motor using serial control.
#include “BasicStepperDriver.h”
#define MOTOR_STEPS 200
#define DIR 2
#define STEP 7
#define MICROSTEPS 1
BasicStepperDriver stepper(MOTOR_STEPS, DIR, STEP);
int led = 13;
int val = 0;
int state = 0;
void setup() {
Serial.begin(9600); // Default communication rate of the Bluetooth module
stepper.setRPM(60);
stepper.disable();
pinMode(led, OUTPUT);
}
void loop() {
stepper.setMicrostep(MICROSTEPS);
val = digitalRead(led);
if (Serial.available()) { // Checks whether data is coming from the serial port
state = Serial.read(); // Reads the data from the serial port
}
if (state == ‘0’) {
Serial.println(“Move 20 DOWN”); // Send back, to the phone, the String “LED: ON”
stepper.rotate(-10);
state = 0;
}
else if (state == ‘1’) {
Serial.println(“Move 20 UP”);
stepper.rotate(10);
state = 0;
}
}