VERY new to this....need code help PLEASE!!!!!!

Ok. So I am in the process of making an aquarium controller. The first thing I did (which was the first time I ever touched an Arduino) was make a 2 socket powerhead controller. Basically, I plug the powerheads in to the sockets, which are wired to relays, that the arduino alternates the power to for a set period of time. Example: Powerhead 1 (Plug A) on for 15 sec. while powerhead 2 (Plug B) is off for 15 sec, etc., etc.,etc. It works amazingly. Here is the code I used. I copied and pasted it then made changes as I needed, so please excuse any inaccurate description info.

// Basic 4 Realy board connection // Each relay is turned on for 2 seconds and then off. // You can here them click as there state changes from off to on and on to // off. // You will also see the corresponding Red LED on the 4 Relay board // light up when the relay is on.

// define names for the 4 Digital pins On the Arduino 7,8,9,10 // These data pins link to 4 Relay board pins IN1, IN2, IN3, IN4

define RELAY1 8

define RELAY2 9

void setup() { // Initialise the Arduino data pins for OUTPUT pinMode(RELAY1, OUTPUT); pinMode(RELAY2, OUTPUT); }

void loop() { digitalWrite(RELAY1,LOW); // Turns ON Relays 1 delay(15000); // Wait 2 seconds digitalWrite(RELAY1,HIGH); // Turns Relay Off

digitalWrite(RELAY2,LOW); // Turns ON Relays 2 delay(15000); // Wait 2 seconds digitalWrite(RELAY2,HIGH); // Turns Relay Off

}

Here is where I need help. I want to install a button to pause the above program for 10 minutes, then automatically restart. If possible, I would also like to be able to restart the program manually by pressing the button again. How would I write this code? Please keep in mind I have almost no idea what I am doing. I am trying to learn as I go, so please, don't try flexing your intellect and berate me. I'm sure this is easy, I just need some help. Thanks.

delay(15000);                                      // Wait 2 seconds

No.

But that's OK, because you're going to remove the delay()s, and you're going to read the blink without delay example in the IDE.

Before you go any further I suggest that you rewrite your current program without the delay() command. If you do not do it now you will regret it later. Whilst the delay() is occurring the Arduino can do nothing else such as reading buttons or temperatures etc.

So, how do you get rid of the delay() but still have a delay I hear you ask ? The answer is to use the principle shown by the BlinkWithoutDelay example in the IDE. Note the start time of an event, such as a relay turning on then periodically check if it is time to do something else, such as turn it off. If so, then do it, but if not do something else like reading inputs and reacting.

Using this principle it becomes easier to incorporate reading a switch and acting upon its input. Have you tried any of the examples in the IDE ? They will show how to read input and react to it.

Another concept that you will find helpful is that of a Finite State Machine. It sounds scary but isn't. At any one time your system is in one of several states (relay 1 on, relay 2 on etc) You write the program so that when it is in a particular state then actions or time passing cause a change of state and the program moves into that state. Combined with the use of millis() timing (BlinkWithoutDelay) this means that you can write a responsive and flexible program that is easier to maintain.

To implement the FSM I favour using switch/case over multiple if tests, using the current state number as the cases. To me it makes more sense but either way works.

Longer term you will almost certainly need to incorporate a Real Time Clock in your project because the Arduino is no good for accurate long term timing.

I realise that there is a lot to take in but take it slow and you will make progress towards your goal.

Welcome to the Forum. Make sure you read the first two entries at the top of this Forum, as it gives you guidelines that will make it easier for others to help you. For example, using code tags, via the '#' symbol makes your code look like this:

#define RELAY1  8                        
#define RELAY2  9                        

void setup()
{    
// Initialise the Arduino data pins for OUTPUT
  pinMode(RELAY1, OUTPUT);       
  pinMode(RELAY2, OUTPUT);
}

 void loop()
{
   digitalWrite(RELAY1,LOW);           // Turns ON Relays 1
   delay(15000);                                      // Wait 2 seconds
   digitalWrite(RELAY1,HIGH);          // Turns Relay Off

   digitalWrite(RELAY2,LOW);           // Turns ON Relays 2
   delay(15000);                                      // Wait 2 seconds
   digitalWrite(RELAY2,HIGH);          // Turns Relay Off

   
 }

Placing it in a scrollable window makes it easier for all to read, plus it takes fewer nano acres on a page.

So I just delete the word delay???

No you re write the code using the blink without delay technique, otherwise known as a state machine:- http://www.thebox.myzen.co.uk/Tutorial/State_Machine.html