School project

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);

void loop()
  statebutton = digitalRead(buttonPin);
  if(statebutton == HIGH && previous == LOW && millis() - time > debounce)
    if(stateRelay == HIGH)
       digitalWrite(Relay, LOW);

    digitalWrite(Relay, HIGH);
    digitalWrite(Relay, LOW);
      time = millis ();

            digitalWrite(Relay, stateRelay);
            previous == statebutton;

this is what i have now.

You need to use millis() for all of the timing and not mix/match with delay().
Have a look at Several things at the same time

It seems that the OP decided not to take notice of my signature line and PM'd me for help.

Where are you stuck ? What part of millis() timing do you not understand ?

Save the millis() value at the time that the start action happens. In your case that is when the relay comes on. Then, each time through loop(), check whether the required wait period has elapsed by subtracting the start time from the millis() value now. If the period has elapsed then act accordingly and maybe save the start time for the next activity. If not, then go round loop() again, perhaps taking other actions and/or reading inputs, but don't block the free running of loop().