DIY Sunrise/Sunset for fishtank

Hello everybody ! Im a newbie to arduino but im getting better as everyday goes by. I try to learn from youtube, google, books, and now I decided to ask for som help in this forum because I cant get to were I want with my program.

I am using:

Arduino UNO board
RTC DS3231
3 volt led
220 ohm resistor
Breadboard

I got my program from a guy on youtube and it is made for a “Wake-Up light” actually. I try to modify it into a sunrise/Sunset for my Aquarium Lights.

The program looks like this:

#include <DS3231.h> //Include the clock library

// Changable Vars
int fadeTime = 1; // How long the light will fade to max
int setHour = 15; // Set hours to wake (military time)
int setMin = 8; // Set minute to wake
int uled = 9; // Set pinout with with PWM

// Set up Vars
DS3231 rtc(SDA, SCL);
Time t;
void start();

void setup()
{
pinMode(uled, OUTPUT);
Serial.begin(9600); // Match to serial monitor
rtc.begin();
}

void loop()
{
t = rtc.getTime(); // Make a time class called ‘t’

// Send Day-of-Week
Serial.print(rtc.getDOWStr());
Serial.print(" ");

// Send date
Serial.print(rtc.getDateStr());
Serial.print(" – ");

// Send time
Serial.println(rtc.getTimeStr());

if (t.hour == setHour && t.min == setMin) // Check if it’s time to wake up!
{
start();
}

// Wait one second before repeating
delay (1000);
}

void start()
{
// Fix for SB LED
analogWrite(uled, 1);
delay((fadeTime * 60000)/50);
analogWrite(uled, 2);
delay((fadeTime * 60000)/50);
analogWrite(uled, 3);
delay((fadeTime * 60000)/50);
analogWrite(uled, 4);
delay((fadeTime * 60000)/50);
analogWrite(uled, 4);
delay((fadeTime * 60000)/50);
analogWrite(uled, 5);
delay((fadeTime * 60000)/50);

// Fade script
for (int i = 6 ; i <= 255; i++)
{
analogWrite(uled, i);
delay(((fadeTime * 60000)/306));
Serial.print(" mil sec “);
Serial.print(((fadeTime * 60000)/306));
Serial.print(” PWM " );
Serial.print(i);

}

delay(20000); // Stay Bright
analogWrite(uled, 0); // Turn off

}

Now the question: How can I continue so that the program also turns of at a specific time ? (Just turn everything around) ?

Thanks

because I cant get to were I want with my program.

Where did you want to be?
The Maldives?

Please remember to use code tags when posting code.

Thanks for such a good answer. Really helpful ! Thumbs up !
My English is not the best and my programming experiance is low so I may not be correct in everything I write.

Not the Maldiwes, Thailand would be better.

Sorry for the Code. Havent get used to this forum yet, I will try to fix it.

And still we know nothing about your problems

Your clock knows what time it is, if you've told it properly, and it has a properly charged battery installed. It does NOT know what time the sun comes up. It does not know what time the sun sets.

The code you posted does something. You have not told us what it does.

You expect the code to do something. You have not told us what you expect it to do.

We can not explain why your expectations are wrong, without knowing what they are.

May I humbly suggest this library for handling solar position. You can use it to translate RTC times into exact sunrise/sunset times for your location and time zone.