Very newbie Q? re 3 channel timers and relays

I hope that my newbie question is tolerated, and replied to.

Having browsed the Topics, it's obvious that the full strength of Arduino is above my pay grade.
I've spent years programming, during the days of MS-DOS and then MS-Windows (ahh, the world of possibilities that opened with OOP), so I'm not totally naïve to programming concepts, but completely new to this.
I have used Borland Pascal, Borland C, Borland C++ (all quite some time ago)

Goal:
To have 3 timers. On powering/triggering each timer I want it to close a replay for the duration of the chosen time, and then start Timer2/Relay2 in the same manner, and finally Timer3/Relay3.

I have spent many hours trawling the internet looking at various timers, mostly based upon the 555, from one-shot timers, sequential timers, decade counters, and anything else I can think of.

I note that on eBay are simple timer-relay modules, which may serve the purpose of initiating the final sequence of Timer1/Relay1 - Timer3/Relay3, but, I am not sure (translate to no idea) how to trigger them within a set order.

I have found a sequential timer, using 555's, which comes close, but each 'channel'/timer group remains On as they progress through the sequence of following timers.

After stumbling upon discrete timer-relay modules on eBay, from 1-channel to8+-channels, they may solve the final section, but I am not sure how to trigger each one of them On, for nn period, then turn each Off, as the next in the sequence begins times.

Flowchart:
Button pressed

  • Timer 1 begins counting
  • Relay 1 closes
  • Timer 1 finishes
  • Timer 1 stops
    ::: at the end of Timer 1
  • Timer 2 begins counting
  • Relay 2 closes
  • Timer 2 finishes
  • Timer 2 stops

and so on to Timer3/Relay3.

My searches on the internet invariably led me to Arduino, and whilst it's capabilities far exceed my little requirement, it may be ideal as a one-stop shop to accomplish the above.

I hope that this request won't be designated as RTFM, and that someone will take the time to either explain how to do this with Arduino (or possibly something entirely different, or a hybrid).
Nothing flashy, such as LCD timer display, just switching relay 1-3 on, for nn duration and then off.

Thanks in advance for any assistance offered.

PS: It has been a very long time since I partook in any forums, and so apologise for responding incorrectly

You could indeed do it with an Arduino and those relay modules you found give you most of the solution - they're simple to connect to an Arduino.

Then you need a push button to trigger the relay and the Arduino's built in timer - millis, to control the timing.

Thanks wildbill.

That was the impression I had after reading about Arduino, but I don't have the slightest idea of how use the Arduino, which chip(s).

I really need The Idiots Guide 101 on how to use the Arduino for such.
It is undoubtedly obvious and quite a silly request to those who use Arduino, but unfortunately I don't.

Are you able to provide any insights, hand-holding, other threads where this may have been addressed, (I have tried searching the forums), or even a "this is how to do it"?

The easiest Arduino to do breadboarding with is the Uno, in my opinion.
Buy bunches of Dupont cables of 6" to 12 " length in male-female male-male configs:
lots of black and red (for power and GND)
many other colors
A medium sized breadboard
You will need a separate power supply for anything other than LEDs.

What you want to do is sequentially activate 3 timers:

Pseudo-code would be:
Set lastTime to = currentTime
Check to see if currentTime - lastTime > waitNo1:
do something, like change the state of a digital pin to activate the relay
set lastTime to currentTime
repeat above sequence for waitNo2 and waitNo3

Arduino C++ does have a few quirks

Here's some info about relays, etc.
https://www.circuitbasics.com/setting-up-a-5v-relay-on-the-arduino/

There is a tutorials section on the forum - I don't see one on relay modules at first glance though. Off forum, I expect you can find many e.g. tutorial.

One word of caution - you will notice that those relay modules are very inexpensive, which seems great until you consider what that likely means regarding the quality of components used. Those ubiquitous little blue relays aren't very durable.

Note: Relay modules for Arduino are very commonly Active LOW. That means you set the input to LOW to activate the relay.

A "Finite State Machine" design should be fairly easy for this task:

const byte ButtonPin = 2;
const byte Relay1Pin = 3;
const byte Relay2Pin = 4;
const byte Relay3Pin = 5;

const unsigned long Relay1OnTime = 3500; // 3.5 seconds
const unsigned long Relay2OnTime = 17000; // 17 seconds
const unsigned long Relay3OnTime = 35000; // 25 seconds

enum States {IdleState, Relay1On, Relay2On, Relay3On} CurrentState;

unsigned long StateStartTime;

void setup()
{
  pinMode(ButtonPin, INPUT_PULLUP);
  pinMode(Relay1Pin, OUTPUT);
  pinMode(Relay2Pin, OUTPUT);
  pinMode(Relay3Pin, OUTPUT);
}

void loop()
{
  unsigned long currentMillis = millis();

  switch (CurrentState)
  {
    case IdleState:
      // Waiting for a button press
      if (digitalRead(ButtonPin) == LOW)
      {
        CurrentState = Relay1On;
        digitalWrite(Relay1Pin, LOW);
        StateStartTime = currentMillis;
      }
      break;

    case Relay1On:
      // Waiting for end of cycle
      if (currentMillis - StateStartTime >= Relay1OnTime)
      {
        // Time is up
        digitalWrite(Relay1Pin, HIGH);  // 1 off

        CurrentState = Relay2On;
        digitalWrite(Relay2Pin, LOW); // 2 on
        StateStartTime = currentMillis;
      }
      break;

    case Relay2On:
      // Waiting for end of cycle
      if (currentMillis - StateStartTime >= Relay2OnTime)
      {
        // Time is up
        digitalWrite(Relay2Pin, HIGH);  // 2 off

        CurrentState = Relay3On;
        digitalWrite(Relay3Pin, LOW); // 3 on
        StateStartTime = currentMillis;
      }
      break;

    case Relay3On:
      // Waiting for end of cycle
      if (currentMillis - StateStartTime >= Relay1OnTime)
      {
        // Time is up
        digitalWrite(Relay3Pin, HIGH);  // 3 off

        CurrentState = IdleState;
      }
      break;
  }
}

Thank you again wildbill
Any pointers, such as you gave, are warmly welcomed and appreciated.
I just had a look at State Machine.
The simple example of driving 2 x LED's gave food for thought, and a possible way to approach this at the beginning, although I'll check your suggestions first, as there's no point in reinventing the wheel, and I'm quite sure I'm not the first to want such functionality.

In the State Machine article it moves on to discuss firing 2 x LED's.

If you could have a look please, and answer a simple question regarding that example:
In the short example, there is a function functionGo2(), which checks the state of the LED, and simply switches the LED from one state to another.

digitalWrite(2, HIGH);
LEDstate2 = HIGH;

Surely inside that one could add

digitalWrite(13, LOW);
LEDstate1 = LOW;

into that function, ensure that the first LED is off.

An interesting start, as instead of turning LED's on/off, those functions could be used to trigger the reset in the 555-relay units preceding the one in current use, ensuring that only one 555-relay unit is functioning at any given time, separating it from whatever follows next.

I would appreciate it if you glanced over that State Machine, and advise if my thought process is heading the right way, or flawed.

As for those little 555-relay units on eBay, they will not have extended use.
I have a number of new, unused, single 555-relay units, which can be used for prototyping or proof of concept.

Thank you again, I genuinely appreciate your replies. :+1:

As it early AM in Australia, that's all from myself for tonight. :zzz:

Hi cncnotes

Thank you for your advice, and the link, which most assuredly will be followed.

Cheers.

You could, but in GrumpyMike's example, there are supposed to be two independently flashing LEDs, so messing with one in the other's code would be confusing.

If you want to use a state machine, look at what John gave you, as far as code is concerned in that case, you're pretty much done.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.