Timed relays from a single momentery switch - help / advice needed please

Hi guys,

I have a charity car project that is ongoing. Our vehicle will be customised with lights, motors and sounds.

I have a standard arduino and a 4-relay board which is working well using various sketches I have found on the net.

I was wondering if anyone could help me with a sketch that will turn on 3, or 4 of these relays at a time interval that I can set from a single N/O momentery switch. I also need it to reset after a certain time so that when the button is pressed again the sequence will start again.

I have an HD44780 LCD that I'd like to work into the design that could display text just before the relevent relay becomes active.

I know this is a big ask but i severely lack the programming knowledge to do this.

I hope someone can help, i'm sure it's not too difficult for you pros!

Cheers

VB

The LCD part is not essential just now. I really need to get the relays operating off the pushbutton. Many thanks again.

something like this?
code not tested and yes it does contain the famous millis() overflow bug (after ~47 days) but it should get you started

#define BUTTON 2

int relay[4] = { 3,4,5,6 };  // pinnumbers of the relay

uint32_t  start[4];            //   4 start times
uint32_t  stop[4];             //   4 stop times

void setup()
{
  for (int i=0; i< 4; i++)
  {
    pinMode(i, OUTPUT);
    digitalWrite(i, LOW);
  }
  pinMode(BUTTON, INPUT);
  digitalWrite(BUTTON, HIGH);  // internal pull up resistor => connect button between pin and GND.
}

void loop()
{
  if (digitalRead(BUTTON) == LOW)
  {
    // different start times
    start[0] = millis() + 1000L;
    start[1] = millis() + 1500L;
    start[2] = millis() + 2000L;
    start[3] = millis() + 3000L;

    // different durations
    stop[0] = start[0] + 1000L;
    stop[1] = start[1] + 2000L;
    stop[2] = start[2] + 3000L;
    stop[3] = start[3] + 4000L;
  }

  // and go !
  for (int i=0; i < 4; i++)
  {
    if (millis() > start[i] && start[i] != 0)
    {
       digitalWrite(relay[i], HIGH);
    }
    if (millis() > stop[i] )
    {
       digitalWrite(relay[i], LOW);
       start[i] = 0;
    }
  }
}

Thanks for that Rob,

I have tried to have a look at it but as I'm a beginner I dont fully understand it.

I am ok with pin numbers and how the resistor with the switch works. As it stands my relay 1-4 are connected to pins 2-5 although I don't need the 4th relay at this time.

Basically the car will loosely resemble a helicopter and will have a set up of lights, motors and a cheap MP3 player that has a physical switch that when made instantly starts the helicopter sound file.

If I'm totally honest i think I need a 'pro' to write me a sketch that is really basic as I lack the skills to do it myself.

The lights, motors and mp3 will be powered externally and will be initiated with the arduino like this:

  1. User presses a N/O momentery switch.

  2. Relay 1 makes & MP3 plays, engine start up - and remains on for duration of file (1:52).

  3. After 10 secs - Relay 2 makes and Navigation lights iluminate.

  4. After engine warm-up 22secs relay 3 makes and 'rotors' start.

  5. After 1:40 relay 3 breaks, rotors stop.

  6. After 1:52 relays 1 & 2 break.

  7. Next press of button, steps 1-6 start again.

If it is easier I can use a locking switch, would that would solve the re-set?

I really appreciate people reading this and taking the time to reply.

Many thanks in advance.

VB

Can anyone assist me please. It is for charity :slight_smile: