I am a "TRUE NEWBIE" at this. What I would like is someone to assist me in creating a simple code set. I have an Arduino Uno, a 5v volt-5 wire-4 pin Stepper motor, 28BYJ-48 with an X113647 driver interface.
I need a simple code that would allow an input on one pin, of a high or low (whichever works) that would initiate the code sequence. I need the code to pause for 3 seconds once the input is applied, then turn the stepper 90 degrees in 1.5 seconds, wait 20 seconds and then return to the original position, stop and wait for the next input.
This should be simple but I do not know code and to be honest as I read it, it confuses me. My apologies if I am just not smart enough to be on this forum but your positive assistance would be greatly appreciated.
I presume you are able to make the motor work using the code in the link you posted. And I presume you know how to make the motor move enough steps to give 90 degrees in 1.5 seconds
From your original post I think you need something like this pseudo code
boolean buttonPushed = false;
boolean motorCWDone = false;
unsigned long buttonPressedMillis;
unsigned long motorCWDoneMillis;
unsigned int motorCWDelay = 3000; // millisecs
unsigned int motorCCWDelay = 20000;
void setup() {
// all the initial stuff
}
void loop() {
checkButton();
moveMotorCW();
}
void checkButton() {
if (digitalRead(buttonPin) == HIGH) {
buttonPushed = true;
buttonMillis = millis();
}
}
void moveMotorCW() {
if (buttonPushed && millis() - buttonPressedMillis >= buttonDelay) {
// code to move motor clockwise 90 degrees
motorCWDone = true;
motorCWDoneMillis = millis();
}
void moveMotorCCW() {
if (motorCWDone && millis() - motorCwDoneMillis >=motorCCWDelay) {
// code to move motor counter clockwise 90 degrees
buttonPushed = false; // ready for next button push
motorCWDone = false;
}
}