i found a topic some where on google that showed me how i can activate a relay and then after a amount of time deactivate the relay so the device that is connected to the relay stops running.
I got that part…
now my problem starts…
While i activate the relay, i also want to activate a stepper motor with the same amount of time that the relay is active.
i cannot figure out how to do this.
if someone can help me that would be great!
#include <Stepper.h>
int buttonPin = 6;
int buttonPin1 = 5;
int Relay = 7;
int stateRelay = LOW;
int statebutton = 0;
int reading;
int previous = LOW;
long time = 0;
long debounce = 500;
int stayON = 5000;
const int steps = 200;
Stepper motor(steps, 8, 9, 10, 11);
void setup()
{
pinMode(buttonPin, INPUT);
pinMode(Relay, OUTPUT);
Serial.begin(9600);
motor.setSpeed(100);
}
void loop()
{
statebutton = digitalRead(buttonPin);
if(statebutton == HIGH && previous == LOW && millis() - time > debounce)
{
if(stateRelay == HIGH)
{
digitalWrite(Relay, LOW);
}
else
{
digitalWrite(Relay, HIGH);
delay(stayON);
digitalWrite(Relay, LOW);
}
time = millis ();
}
digitalWrite(Relay, stateRelay);
previous == statebutton;
}
this is what i have now.