Hi guys,
I am doing a project and I wanna control the stepper motor using a joystick remotely. I already have code to control the stepper motor with joystick( Not remotely). I have HC-12 two modules. I am planing to use one as a transmitter which include the Arduino Nano and the Joystick. For the receiver, I am using Arduino Uno Board, easy driver and stepper motor. I will put the code below for the stepper motor and joystick, and I would like to modify the code which I can control the stepper motor remotely.
Here is the code;(This is the code without using HC-12 Module)
#define step_pin 3 // Pin 3 connected to Steps pin on EasyDriver
#define dir_pin 2 // Pin 2 connected to Direction pin
#define MS1 5 // Pin 5 connected to MS1 pin
#define MS2 4 // Pin 4 connected to MS2 pin
#define SLEEP 7 // Pin 7 connected to SLEEP pin
#define X_pin A0 // Pin A0 connected to joystick x axis
int direction; // Variable to set Rotation (CW-CCW) of the motor
int steps = 1025; // Assumes the belt clip is in the Middle
void setup() {
pinMode(MS1, OUTPUT);
pinMode(MS2, OUTPUT);
pinMode(dir_pin, OUTPUT);
pinMode(step_pin, OUTPUT);
pinMode(SLEEP, OUTPUT);
digitalWrite(SLEEP, HIGH); // Wake up EasyDriver
delay(5); // Wait for EasyDriver wake up
/* Configure type of Steps on EasyDriver:
// MS1 MS2
//
// LOW LOW = Full Step //
// HIGH LOW = Half Step //
// LOW HIGH = A quarter of Step //
// HIGH HIGH = An eighth of Step //
*/
digitalWrite(MS1, LOW); // Configures to Full Steps
digitalWrite(MS2, LOW); // Configures to Full Steps
}
void loop() {
while (analogRead(X_pin) >= 0 && analogRead(X_pin) <= 100) {
if (steps > 0) {
digitalWrite(dir_pin, HIGH); // (HIGH = anti-clockwise / LOW = clockwise)
digitalWrite(step_pin, HIGH);
delay(1);
digitalWrite(step_pin, LOW);
delay(1);
steps--;
}
}
while (analogRead(X_pin) > 100 && analogRead(X_pin) <= 400) {
if (steps < 512) {
digitalWrite(dir_pin, LOW); // (HIGH = anti-clockwise / LOW = clockwise)
digitalWrite(step_pin, HIGH);
delay(1);
digitalWrite(step_pin, LOW);
delay(1);
steps++;
}
if (steps > 512) {
digitalWrite(dir_pin, HIGH);
digitalWrite(step_pin, HIGH);
delay(1);
digitalWrite(step_pin, LOW);
delay(1);
steps--;
}
}
while (analogRead(X_pin) > 401 && analogRead(X_pin) <= 600) {
if (steps < 1025) {
digitalWrite(dir_pin, LOW);
digitalWrite(step_pin, HIGH);
delay(1);
digitalWrite(step_pin, LOW);
delay(1);
steps++;
}
if (steps > 1025) {
digitalWrite(dir_pin, HIGH);
digitalWrite(step_pin, HIGH);
delay(1);
digitalWrite(step_pin, LOW);
delay(1);
steps--;
}
}
while (analogRead(X_pin) > 601 && analogRead(X_pin) <= 900) {
if (steps < 1535) {
digitalWrite(dir_pin, LOW);
digitalWrite(step_pin, HIGH);
delay(1);
digitalWrite(step_pin, LOW);
delay(1);
steps++;
}
if (steps > 1535) {
digitalWrite(dir_pin, HIGH);
digitalWrite(step_pin, HIGH);
delay(1);
digitalWrite(step_pin, LOW);
delay(1);
steps--;
}
}
while (analogRead(X_pin) > 900 && analogRead(X_pin) <= 1024) {
if (steps < 2050) {
digitalWrite(dir_pin, LOW);
digitalWrite(step_pin, HIGH);
delay(1);
digitalWrite(step_pin, LOW);
delay(1);
steps++;
}
}
}
Here is the link for the site, you can get a better idea looking the diagram
https://www.brainy-bits.com/stepper-motor-easy-driver/
Could anyone pls modify the code as I need? I would really appropriate if someone help me.
Thanks Guys!