# Salt Reef seasons IF Then Confusion!?

hello Setting up a reef tank and i have most code i think i need…? issues in my head with how seasons need to be read from rtc. i have included the file so you can see how its actually gonna work. Shortcuts would be awesome to learn…

if((month=<6 && dayOfWeek=<19)||(month=>3 && dayOfWeek=<20)||(month=>3 && month=<5)) else if // spring
{
}
elseif ((month=<9 && dayOfWeek=<21)||(month=>6 && dayOfWeek=<20)||(month=>7 && month=<8)) else if // summer
{
}
elseif ((month=<12 && dayOfWeek=<20)||(month=>9 && dayOfWeek=<22)||(month=>10 && month=<11)) else if // fall
{
}
elseif ((month=<3 && dayOfWeek=<19)||(month=>12 && dayOfWeek=<21)||(month=>1 && month=<2)) else if // winter
{
}

Even assuming you are in the northern hemisphere, your code won't work. For example, for Jan 1st (month ==1, dayOfWeek == 1) it will determine it's spring (first if condition is true).

Call me the cat but it should only run as code directs it should it not!?

if((month=<6 && dayOfWeek=<19)||(month=>3 && dayOfWeek=<20)||(month=>3 && month=<5)) else if // spring

The condition in the if statement is true when month==1 and dayOfWeek==1, isn’t it?
At the end, you make the comment “spring”, so I assume you are going to execute something specific to spring, are you not?

How would u suppose or direct me in a direction I need to go so I can get the seasons effect.

How about a switch case statement, if(months&&date) good switch

Case1 spring

Something like:

``````  switch (month)
{
case 1:   // January
case 2:   // and February
season = summer;
break;

case 3:    // March
if (day >= 21)
season = autumn;
else
season = summer;
break;

// ... and so on
} // end of switch
``````

I live in the southern hemisphere BTW, which is why it is autumn right now.

one thing about me is (and people may come to notice...) i really hate to over-complicate ANYTHING eg if it's not needed or an alternative is there take it anything reduce your memory usage or binary size.

but, and my understanding could be way off here.. but.. am I right in understanding you want certain actions depending on the time of year? eg if it's summer more daylight therefor the the lights come on at different times of the day, so the RTC is read and through a series of calculations you know exactly when to switch on and off the lights and other things like pumps and stuff.

if so?.. why an RTC at all?

run a cable (or invest in another small arduino with 2 wireless modules) to a window and on the end of the cable attach a photo resistor, feed the other end into your analogue in and read the values appropriately, or use another arduino to relay back the information if you want a clean setup... now when it "goes dark" or cloudy or a storm approaches and it's dark at 3pm, you don't need to guess what's going on, you actually have real world data coming in, based on how much light there is, you switch the lights on or off.

Now having said all that i could be completely wrong and you have to use the RTC and you can't use say a Temperature Sensor and Light Sensor to fully automate it.. imagine if street lamps only came on at a certain times based on the year date and time, no to consistently get it come on as it goes dark be the middle of the day or night time, a light sensor is used.

Yes, good idea.

Another approach would be to take the date, turn it into a Julian date (ie. day of year) ... I think there are quite a few short algorithms for that. Then simply do a straight compare. There will only be 4 break points then.

And here's another idea ... by reading in sunlight you can deduce the season. For example, very short days ... winter.

[quote author=Nick Gammon link=topic=101683.msg763010#msg763010 date=1334641274] Yes, good idea.

Another approach would be to take the date, turn it into a Julian date (ie. day of year) ... I think there are quite a few short algorithms for that. Then simply do a straight compare. There will only be 4 break points then.

And here's another idea ... by reading in sunlight you can deduce the season. For example, very short days ... winter. [/quote]

yeah, store how much light comes in and at the end of the day store it onto the eeprom, to get number hours of light, like it, very short days = nuclear winter (or just plain old winter) :D

The sketch posted already calculates the Julian date to get the moon phase.

Problem solved, then.

this was how i was gonna do the lights and fan but in my research i think there could be another way . and yes i im in the northern hemisphere

if(hours == 5 && minutes == 0 && !ledOff)//actinics off if(hours == 4 && minutes == 55 && !fluores1On)//fluorescents off if(hours == 9 && minutes == 0 && !mhOn)//metal halide on if(hours == 9 && minutes == 15 && !fanOn)//cooling fan on for metal halide if(hours == 3 && minutes == 0 && !mhoff)//metal halide off if(hours == 3 && minutes == 15 && !fanOff)//fan off if(hours == 19 && minutes == 0 && !fluores1Off)//fluorescents off if(hours == 18 && minutes == 55 && !ledOn)//actinics on {

mhOn = true; fluores1On = true; fluores2On = true; fanOn = true; ledOn = true; mhoff = true; fluores1Off = true; fluores2Off = true; fanOff = true; ledOff = true;

``````        fanOn = true;
ledOn = true;
...
fanOff = true;
ledOff = true;
``````

I honestly don't know what you are trying to do here. Is the fan both on and off? And the LED? How does that even work?

I knew I was gonna hear that.. that was an older sketch. I will be rewriting as If(times---------eg------!fanOn); Else = !fanOff;

Sorry but most of typing is done by phone

Is the fan both on and off?

Schrödinger's fan?

I will be rewriting as
If(times---------eg------!fanOn);
Else = !fanOff;

Not if you want the code to compile, you won’t.

I had originally laid out the sketch I sequence of operation after delving into the if else Statement I realized that if the times are true then fan will be off and else it would be off. I have off tomorrow and will be posting better sketchhooefully. I will be controlling a metal halide,fan ,compact fluorescent, led and (2power heads that Will be on a 15min alternating cycle.900,000millis.

I know I'm making it harder on myself then it needs to be but my programming days are years behind me and it was c++. With the tank my dad built I thought no better time than now to get back into it.

but my programming days are years behind me and it was c++.

Good thing the Arduino isn't programmed using C++ then. Oh, wait. It is.

I thought that arduino was written with c language not c++ persay. By the way hi Paul long time, no deal with my issues :D