TimerAlarms Help Please Save my Aquarium Life

Hello everybody. I have big problem with TimeAlarms library. I am using arduino for my saltwater aquarium lighting. I am using power leds and use Meanwell analog led driver. Actually ı dont have any problem about led or anythng. I have problem with TimeAlarms :slight_smile:

Actually everythng was good before. Program was working well for 2 weeks. But After add new digital outputs somethngs changed. Maybe this is not about this but I am not sure.

But my aquarium life is on danger these days. Please help me. then save my fishs and corals.

Copy codes here; And attahed code file

#include <Time.h>
#include <TimeAlarms.h>

int redled = 6; // Kırmızı led grubu adresleme
int blueled = 9; // Mavi led grubu adresleme
int whiteled = 10; // Beyaz led grubu adresleme
int uvled = 11; // UV led grubu adresleme
float brightness = 0; // Genel Aydınlık şiddeti
float brightnesswhite = 0; // Beyaz Aydınlık şiddeti
float fadeAmount = 0.15; // Genel Aydınlık şiddeti kat sayısı 0,15
float fadeAmountwhite = 0.25; // Beyaz Aydınlık şiddeti kat sayısı 0,25

void setup() {

setTime(11,25,0,18,10,16); // Zamanı ayarlıyoruz
Alarm.alarmRepeat(11,26,0, MorningAlarm); // Sabah led uyanma başlangıcı
Alarm.alarmRepeat(17,11,0,EveningAlarm1); // Akşam led uyuma başlangıcı 1
Alarm.alarmRepeat(23,11,0,EveningAlarm2); // Akşam led uyuma başlangıcı 2

pinMode(redled,OUTPUT); // Çıkış pin tanımlama
pinMode(blueled,OUTPUT); // Çıkış pin tanımlama
pinMode(whiteled,OUTPUT); // Çıkış pin tanımlama
pinMode(uvled,OUTPUT); // Çıkış pin tanımlama
pinMode(7,OUTPUT); // Çıkış pin tanımlama T5 AYDINLATMA
pinMode(12,OUTPUT); // Çıkış pin tanımlama LED FAN

}

void loop(){

Alarm.delay(1000);

}

void MorningAlarm(){

uyan:

if (brightness > 250)
{
analogWrite(redled,255);
analogWrite(blueled,255);
analogWrite(whiteled,255);
analogWrite(uvled,255);
digitalWrite ( 7 , HIGH );
digitalWrite ( 12 , HIGH );
}
else
{
analogWrite(redled,brightness);
analogWrite(blueled,brightness);
analogWrite(whiteled,brightness);
analogWrite(uvled,brightness);

brightness = brightness + fadeAmount; // Her 500 milisaniyelik döngüde katsayı ile ışık şiddetini arttır
brightnesswhite = brightnesswhite + fadeAmount; // Her 500 milisaniyelik döngüde katsayı ile ışık şiddetini arttır

delay(500);
}
goto uyan;

}

void EveningAlarm1(){

digitalWrite ( 7 , LOW);

uyu1:

if (brightnesswhite < 1)
{
analogWrite(whiteled,0);
analogWrite(redled,0);
}
else
{
analogWrite(whiteled,brightnesswhite);
analogWrite(redled,brightnesswhite);

brightnesswhite = brightnesswhite - fadeAmountwhite; // Her 500 milisaniyelik döngüde katsayı ile beyaz ışık şiddetini azaltır

delay(500);

goto uyu1;
}
}

void EveningAlarm2(){

digitalWrite ( 12 , LOW );

uyu2:

if (brightness < 1)
{
analogWrite(uvled,0);
analogWrite(blueled,0);
}
else
{
analogWrite(uvled,brightness);
analogWrite(blueled,brightness);

brightness = brightness - fadeAmount; // Her 500 milisaniyelik döngüde katsayı ile tüm ışık şiddetini azaltır

delay(500);
goto uyu2;
}
}

led_19.05_wht_k_sma.ino (2.56 KB)

delay(500) keeps you from doing anything useful for 1/2 a second.

I think that Alarm.delay(1000) will keep you from doing many useful things for 1 second.

It would be helpful to post the working code and the non-working code using the guidelines below.

However, I am certain that the Arduino is doing what you told it to do. Therefore, you must tell us:

  1. What did you intend for the Arduino to do?
  2. What does the Arduino do instead?

To post code and/or error messages:

  1. Use CTRL-T in the Arduino IDE to autoformat your complete code.
  2. Paste the complete autoformatted code between code tags (the </> button)
    so that we can easily see and deal with your code.
  3. Paste the complete error message between code tags (the </> button)
    so that we can easily see and deal with your messages.
  4. If you already posted without code tags, you may add the code tags by
    editing your post. Do not change your existing posts in any other way.
    You may make additional posts as needed.

Before posting again, you should read the three locked topics at the top of the Programming Questions forum, and any links to which these posts point.

If your project involves wiring, please provide a schematic and/or a wiring diagram and/or a clear photograph of the wiring.

Good Luck!

All three of those functions use a goto that basically turns them into blocking loops. That's not good for program flow. You should let the loop function keep running and let it call those functions over and over to take one step of fade at a time instead of trying to stay in the one function until it fades all the way.

You say in your post that it worked good and then some things changed. It would really help if you told us what the symptom is instead of making us guess. What does it do or not do and how does that compare with your expectations? What code was added that broke it? Give us the details.

ErcanTR:
Actually everythng was good before. Program was working well for 2 weeks. But After add new digital outputs somethngs changed. Maybe this is not about this but I am not sure.

Do you have the old version of your program, from when it was working? If you do, please show us.

What "digital outputs" did you add?

You say that the program, as you now have it, does not work. What exactly did you expect it to do, and what is it actually doing?

First thanks everybody for your answers

Actually old version and new version is same now. I just added digitial out 7 and 12.

dijitalwrite commands are working fine But time librarary is looking not working well

for example;

setTime(11,25,0,18,10,16);

Alarm.alarmRepeat(11,26,0, MorningAlarm);

Alarm.alarmRepeat(17,11,0,EveningAlarm1);

Alarm.alarmRepeat(23,11,0,EveningAlarm2);

after dowload these codes maybe 5 minutes later EveingAlarm1 is working.

or MorningAlarm dont start.

or EveningAlarm2 never work

ErcanTR:
First thanks everybody for your answers

Actually old version and new version is same now. I just added digitial out 7 and 12.

Let's see if I got this right: pin 7 is for a light, and pin 12 is for a fan.

My guess is that it's a problem with power. Maybe you are trying to draw too much power, and that is causing your Arduino to reset. I do not know.

But I am using 4 channel relay board. it can be problem?