aquaponic light and pump loop help

hello guys and thanks in advance,

i am in the process of setting up a small aquaponic system. what i have is a arduino nano and a sainsmart ssr board, i understand the schematics to hook the board up however, I am haveing trouble setting up the arduino to do what i would like. what i need the arduino to do is set a pin high for 2 minutes then go low for 3 then do that 3 times then go low for 45 minutes. the kicker is that while it is doing that i need it to run a analog read on a photocell and turn another pin high or low based on the photocell reading. What i did was use the blink without delay and modified it. i added a second interval so that the pin would go low for a different amount of time that it was high. but i got frusterated because this wouldnot work. so i decided to post on here for direction or if im lucky a code i can modify :wink:

thanks again guys

this is about as far as i got and you will notice i need help with the syntax too

const int pumpPin = 13;
int pumpState = LOW;
long previousMillis = 0;
long interval1 = 12000;
long interval2 = 18000;
long interval3 = 27000;

void setup() {

pinMode(pumpPin, OUTPUT);
}

void loop()

{
unsigned long currentMillis = millis();

if(currentMillis - previousMillis > interval1) {
previousMillis = currentMillis;

if (pumpState == LOW)
pumpState = HIGH;
else
pumpState = LOW;
digitalWrite(pumpPin, pumpState);
}

{

unsigned long currentMillis = millis();

if(currentMillis - previousMillis > interval2) {
previousMillis = currentMillis;

if (pumpState==LOW)
pumpState = HIGH;
else
pumpState = LOW;
digitalWrite(pumpPin, pumpState);
}

you will notice i need help with the syntax too

You need to understand the use of { and } brackets to define groups of statements that go together.

This:

  unsigned long currentMillis = millis();
 
  if(currentMillis - previousMillis > interval1) {
    previousMillis = currentMillis;   

    
    if (pumpState == LOW)
      pumpState = HIGH;
    else
      pumpState = LOW;                       // These two statements are NOT grouped together
    digitalWrite(pumpPin, pumpState);
  }

Does not work because you are not controlling which statements go together...

Try this kind of structure:

  unsigned long currentMillis = millis();
 
  if(currentMillis - previousMillis > interval1)

 {  // DO this if the interval has ended  
    previousMillis = currentMillis;   

    
    if (pumpState == LOW)
   {
      pumpState = HIGH;  
     digitalWrite(pumpPin, pumpState);   // MAYBE you were trying to do this ??
   }

  } // end of DO this if the interval has ended

Maybe look at this example of starting program structure:
http://arduino-info.wikispaces.com/YourDuinoStarter_SketchTemplate

As a golden rule I always put braces around a group after an if etc, even if its a single line

It'si a very common GotYa for programmers to write

if (a==b)
c=d;
else
c=e;

then decide that as well as doing c=e; they need to do g=h

if (a==b)
c=d;
else
c=e;
g=h;

Which then doesn't do what they expected.

Also... Although its hard to show using the code tags. I'd recommend that you always indent you code correctly and consistently.
It makes things easier to read and easier to spot mistakes