Rotating bank-switching through 5+ banks

Hello all. I am on a quest to make a rotating circuit that will trigger relays in sequential order after "X" amount of time (around 20 minutes).

Setup is to:

  1. Have Arduino set to apply 5v through/too relay #1
  2. After "X" minutes (around 20 minutes) holding relay closed with voltage, Arduino turns off relay connection #1
  3. Arduino then energizes relay #2 and hold relay closed for "x" minutes"
  4. This scenario continues to relays 1,2,3,4 etc.
  5. Need to be capable to scale up to 6 relays.

Anyone have any ideas? I cant seem to find code on something like this.

Thanks in advance

Hi @ceedawg ,
Welcome to the forum..

hmm, Kind of sounds like something i've already done..
Check this.. Uno Switch Mins..

counts minutes, state machine used to step..
button resets..
easily expandable..

should get you started anyways..

good luck.. ~q

1 Like

Just use a counter. Count millis() and increment a minutes counter when it's time. If counter is between 0 and 19 minutes energize relay #1, else deenergize relay #1. If counter is between 20 and 39 minutes energize relay #2, else deenergize relay #2. Lather, rinse, repeat.

Hi dougp, yea, I figured it was something simple like that but I have soap in the eyes, ha ha, and, A) I have NO coding experience (least in theory of principles) and I have so much going on, I sadly dont have time to learn anything (just not enough time in the day). I have other things a little higher on the list I "have" to get done and I need to be careful cause I could start geeking out on this forum again and spend many a sleepless nights. Been there, done that back in 2014 on this site. was fun, but I paid for it, lol. Was hoping someone would have a script ready to go that was close I could deconstruct a little code here and there to make it work. I am pretty good with working on something thats already there, but cant come up with squat from scratch :frowning: . But I see what you did there, I will add that to the clues, thank you.

qubits-us
Thank you, I will take a look at your script and see if I can do a little reverse engineering on that code, much appreciated.

Looks like I also need to do a little searching on "counters", as doug said, to find code. I was not sure what kind of circuit my request would fall into. More clues :slight_smile: !!!

Thanks all.

1 Like

Don't make the mistake of trying to get the whole thing working at once. Put together a little bit of code to count millis(). Using that success increment a memory location called 'counter'. Now use counter as a variable in a compare statement. Use the compare result to turn on/off the relay. Building blocks.

Hello ceedawg

Welcome to the worldbest Arduino forum ever.

Take a search engine of your choice and ask the WWW for ' LED sequencer / traffic lights ' to collect some data to be sorted out to get the needed information.

Have a nice day and enjoy coding in C++.

ah I think what you need is chatgpt. He loves explaining things and writing code for you. Not everything he does is even correct, and if you push him he'll just say that you are right, even if your wrong. But for somehting like this he can come up with something. hell lets see what he says:

const int numRelays = 6;   // Total number of relays
const int relayPins[] = {2, 3, 4, 5, 6, 7};  // Pin numbers connected to relays

const unsigned long relayDelay = 20 * 60 * 1000;  // Delay in milliseconds (20 minutes)

void setup() {
  for (int i = 0; i < numRelays; i++) {
    pinMode(relayPins[i], OUTPUT);
    digitalWrite(relayPins[i], LOW);  // Initialize relays as OFF
  }
}

void loop() {
  for (int i = 0; i < numRelays; i++) {
    digitalWrite(relayPins[i], HIGH);  // Turn on the current relay
    delay(relayDelay);                 // Wait for the specified delay
    digitalWrite(relayPins[i], LOW);   // Turn off the current relay
    delay(1000);                       // Small delay for stability
  }
}

In this example, the Arduino sequentially turns on each relay, waits for the specified delay (20 minutes), turns off the current relay, and then moves on to the next relay. This loop continues indefinitely.

Please note that using the delay() function will block the entire program during the delay, so if you want to add more advanced functionality or responsiveness, you might consider using the millis() function for non-blocking timing.

  1. Scaling Up: The code provided above is for 6 relays. If you want to scale up to a different number of relays, adjust the numRelays variable and the relayPins array accordingly.

Remember that safety is important when working with high-voltage circuits and relays. Ensure that you follow appropriate safety precautions and guidelines when setting up your circuit.

Keep in mind that this is a basic example to get you started. Depending on your exact requirements, you might need to fine-tune and expand the code to include error handling, manual control, or other features.

Have fun

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