I'm currently programming an Arduino program for my final school project, and I need help.
The task is to control two stepper motors. One of the two motors has two buttons, when the button is pressed, the motor goes one step to the right, when the other one goes to the left. The second motor has three buttons, the first two for the same thing, but when the third is pressed, the motor goes to an already fixed start position (reset button).
I use two bipolars with four connections as stepping motors (description as photo in German). I use Az-Delivery's A4988 driver module (one driver for each motor). As for the code itself, I already have the controls to turn the motor left and right, but I need help resetting the motor.
It would be a really big help if someone could help me with the programming.
P.S. I write everything in German and then translate it into English, so I'm sorry if the spelling isn't correct
//there is no Libary needed
int buttonResetpin = 10; //Taster Reset
int buttonLeftpin = 9; //Taster nach Links
int buttonRightpin = 8; //Taster nach Rechts
#define dirPin 2
#define stepPin 3
#define stepsPerRevolution 50 //wie viele Schritte Der Motor macht
void setup() {
pinMode(buttonResetpin, INPUT_PULLUP);
pinMode(buttonLeftpin, INPUT_PULLUP);
pinMode(buttonRightpin, INPUT_PULLUP);
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
// initialize the serial port:
Serial.begin(9600);
}
void loop() {
if (digitalRead(buttonLeftpin) == LOW)//Taster für Linkssdreh
{
//Stell die Drehrichtung im Uhrzeigersinn
digitalWrite(dirPin, HIGH);
// Spin the stepper motor 1 revolution slowly:
for (int i = 0; i < stepsPerRevolution; i++) {
// These four lines result in 1 step:
digitalWrite(stepPin, HIGH);
delayMicroseconds(5000);
digitalWrite(stepPin, LOW);
delayMicroseconds(5000);
}
}
if (digitalRead(buttonRightpin) == LOW)//Taster für Rechtssdreh
{
// Stell die Drehrichtung gegen dem Uhrzeigersinn
digitalWrite(dirPin, LOW);
// Spin the stepper motor 1 revolution quickly:
for (int i = 0; i < stepsPerRevolution; i++) {
// These four lines result in 1 step:
digitalWrite(stepPin, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin, LOW);
delayMicroseconds(2000);
}
}
if (digitalRead(buttonResetpin) == LOW)//Taster für Reset
{
Serial.println("test");
}
}