digitalWrite - alarmRepeat

I use timealarms to control led light (42w). I use 17 alarm.Repeat per day.
In test mode(1minute) everything works fine, but in 24h cycle it stops working correctly.

To avoid power failure problems is after every hour alarm.Repeat digitalWrite(HIGH) or LOW for relays.
I think this is problem.

#include <DS1307RTC.h>
#include <Time.h>
#include <TimeAlarms.h>  // accepts 23 alarmRepeat
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

const int MW = 6;        //leds power supply (relay on / off)
const int W = 9;        //white led (relay ON /off)  
const int BLUE = 10;         //blue led PWM module (PWM or withoutPWM 100%) 

LiquidCrystal_I2C lcd(0x27,16,2);

void setup()
{
 Serial.begin(9600);
 //setTime(9,29,55,12,30,12);      // TEST


  setSyncProvider(RTC.get);   // the function to get the time from the RTC
    if(timeStatus()!= timeSet) 
       Serial.println("Unable to sync with the RTC");
    else
        Serial.println("RTC has set the system time"); 

  lcd.init(); // initialize the lcd
  lcd.backlight();
  lcd.setCursor(0, 1);
  lcd.print("RESTART");
  
  pinMode (MW, OUTPUT);
  pinMode (W, OUTPUT);
  pinMode (BLUE, OUTPUT);
  
  digitalWrite(MW, HIGH);      //power supply OFF
  digitalWrite(W, HIGH);      //white leds OFF
  
  // ***** TEST ****
  /*
  Alarm.alarmRepeat(9,30,00, H06M30);        
  Alarm.alarmRepeat(9,30,05, H07M30);       
  Alarm.alarmRepeat(9,30,10, H08M30);        
  Alarm.alarmRepeat(9,30,15, H10M30);        
  Alarm.alarmRepeat(9,30,20, H10M30);        
  Alarm.alarmRepeat(9,30,25, H11M30);        
  Alarm.alarmRepeat(9,30,30, H12M30);        
  Alarm.alarmRepeat(9,30,35, H13M30);        
  Alarm.alarmRepeat(9,30,40, H14M30);        
  Alarm.alarmRepeat(9,30,44, H15M30);        
  Alarm.alarmRepeat(9,30,50, H16M30);        
  Alarm.alarmRepeat(9,30,55, H17M30);        
  Alarm.alarmRepeat(9,31,05, H18M30);        
  Alarm.alarmRepeat(9,31,10, H19M30);        
  Alarm.alarmRepeat(9,31,15, H20M30);       
  Alarm.alarmRepeat(9,31,20, H21M30);        
  Alarm.alarmRepeat(9,31,25, H22M30);       
  Alarm.alarmRepeat(9,31,30, H23M30);       
  */
  
  ///LED control times        
                   
  Alarm.alarmRepeat(6,30,00, H06M30);        
  Alarm.alarmRepeat(7,30,05, H07M30);        
  Alarm.alarmRepeat(8,30,10, H08M30);        
  Alarm.alarmRepeat(9,30,15, H09M30);       
  Alarm.alarmRepeat(10,30,20, H10M30);        
  Alarm.alarmRepeat(11,30,25, H11M30);        
  Alarm.alarmRepeat(12,30,30, H12M30);        
  Alarm.alarmRepeat(13,30,35, H13M30);        
  Alarm.alarmRepeat(14,30,40, H14M30);        
  Alarm.alarmRepeat(15,30,44, H15M30);        
  Alarm.alarmRepeat(16,30,50, H16M30);        
  Alarm.alarmRepeat(17,30,55, H17M30);        
  Alarm.alarmRepeat(18,31,05, H18M30);      
  Alarm.alarmRepeat(19,31,10, H19M30);        
  Alarm.alarmRepeat(20,31,15, H20M30);       
  Alarm.alarmRepeat(21,31,20, H21M30);        
  Alarm.alarmRepeat(22,31,25, H22M30);        
  Alarm.alarmRepeat(23,31,30, H23M30);       
  
}

void loop() {
  digitalClockDisplay();
  Alarm.delay(1000);
  
}
   
void H06M30() {                            
  Serial.println("BLUE 33% WHITE 00% POWER ON"); 
  lcd.setCursor(0, 1);
  lcd.print("B33% W00% P ON ");
  analogWrite(BLUE, 84);        // blue leds 33% 
  digitalWrite(MW, LOW);        // power supply ON
  digitalWrite(W, HIGH);        // white leds OFF
 }
  
 void H07M30() {                            
  Serial.println("BLUE 33% WHITE 00% POWER ON"); 
  lcd.setCursor(0, 1);
  lcd.print("B33% W00% M ON "); 
  analogWrite(BLUE, 84);           
  digitalWrite(MW, LOW);          
  digitalWrite(W, HIGH);           
 }
 
void H08M30() {                            
  Serial.println("BLUE 66% WHITE 00% POWER ON"); 
  lcd.setCursor(0, 1);
  lcd.print("B66% W00% M ON ");  
  analogWrite(BLUE, 168);
  digitalWrite(MW, LOW);
  digitalWrite(W, HIGH); 
 } 
 
void H09M30() {                            
  Serial.println("BLUE 100% WHITE OFF POWER ON"); 
  lcd.setCursor(0, 1);
  lcd.print("B100% W00% M ON ");  
  analogWrite(BLUE, 255);
  digitalWrite(MW, LOW);
  digitalWrite(W, HIGH);
  
 }  

void H10M30() {                            
  Serial.println("BLUE 100% WHITE OFF POWER ON"); 
  lcd.setCursor(0, 1);
  lcd.print("B100% W00% M ON ");  
  analogWrite(BLUE, 255);
 digitalWrite(MW, LOW);
  digitalWrite(W, HIGH);
 }  
 
void H11M30() {                            
  Serial.println("BLUE 100% WHITE ON POWER ON "); 
  lcd.setCursor(0, 1);
  lcd.print("B100% W100% M ON ");   
  analogWrite(BLUE, 255);
  digitalWrite(MW, LOW);
  digitalWrite(W, LOW);                // white leds on
 } 

void H12M30() {                            
  Serial.println("BLUE 100% WHITE ON POWER ON"); 
  lcd.setCursor(0, 1);
  lcd.print("B100% W100% M ON ");  
  analogWrite(BLUE, 255);
  digitalWrite(MW, LOW);
  digitalWrite(W, LOW);  
 } 
void H13M30() {                            
  Serial.println("BLUE 100% WHITE ON POWER ON"); 
  lcd.setCursor(0, 1);
  lcd.print("B100% W100% M ON ");  
  analogWrite(BLUE, 255);
  digitalWrite(MW, LOW);
  digitalWrite(W, LOW); 
 } 

void H14M30() {                            
  Serial.println("BLUE 100% WHITE ON POWER ON"); 
  lcd.setCursor(0, 1);
  lcd.print("B100% W100% M ON ");  
  analogWrite(BLUE, 255);
  digitalWrite(MW, LOW);
  digitalWrite(W, LOW); 
 }  

void H15M30() {                            
  Serial.println("BLUE 100% WHITE ON POWER ON"); 
  lcd.setCursor(0, 1);
  lcd.print("B100% W100% M ON ");  
  analogWrite(BLUE, 255);
  digitalWrite(MW, LOW);
  digitalWrite(W, LOW);  
 }  

void H16M30() {                            
  Serial.println("BLUE 100% WHITE ON POWER ON"); 
  lcd.setCursor(0, 1);
  lcd.print("B100% W100% M ON ");  
  analogWrite(BLUE, 255);
  digitalWrite(MW, LOW);
  digitalWrite(W, LOW);  
 } 

void H17M30() {                            
  Serial.println("BLUE 100% WHITE ON POWER ON"); 
  lcd.setCursor(0, 1);
  lcd.print("B100% W100% M ON ");  
  digitalWrite(MW, LOW);
  digitalWrite(W, LOW);  
 }

void H18M30() {                            
  Serial.println("BLUE 100% WHITE ON POWER ON"); 
  lcd.setCursor(0, 1);
  lcd.print("B100% W100% M ON ");  
  analogWrite(BLUE, 255);
  digitalWrite(MW, LOW);
  digitalWrite(W, LOW);  
 }

void H19M30() {                            
  Serial.println("BLUE 100% WHITE OFF POWER ON"); 
  lcd.setCursor(0, 1);
  lcd.print("B100% W00% M ON ");   
  analogWrite(BLUE, 255);
  digitalWrite(MW, LOW);
  digitalWrite(W, HIGH);        //white leds OFF
 }

void H20M30() {                            
  Serial.println("BLUE 66% WHITE OFF POWER ON"); 
  lcd.setCursor(0, 1);
  lcd.print("B66% W00% M ON ");   
  analogWrite(BLUE, 168);
  digitalWrite(MW, LOW);
  digitalWrite(W, HIGH);
 }


void H21M30() {                            
  Serial.println("BLUE 33% WHITE OFF POWER ON"); 
  lcd.setCursor(0, 1);
  lcd.print("B33% W00% M ON ");   
  analogWrite(BLUE, 84);
  digitalWrite(MW, LOW);
  digitalWrite(W, HIGH);
  
 }
void H22M30() {                            
  Serial.println("BLUE 33% WHITE OFF POWER ON"); 
  lcd.setCursor(0, 1);
  lcd.print("BS33% W00% M ON ");    
  analogWrite(BLUE, 84);
  digitalWrite(MW, LOW);
  digitalWrite(W, HIGH);  
 }

void H23M30() {                            
  Serial.println("BLUE OFF WHITE OFF POWER OFF"); 
  lcd.setCursor(0, 1);
  lcd.print("....GOOD BYE....");
  digitalWrite(BLUE, LOW);       // blue OFF
  digitalWrite(MW, HIGH);        // power supply OFF
  digitalWrite(W, HIGH);         // white leds OFF 

  
 }
 
void digitalClockDisplay()
{
  // digital clock display of the time
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.println(); 
  lcd.setCursor(0, 0);
  lcd.print(hour());
  LCDprintDigits(minute());
  LCDprintDigits(second());
}

void printDigits(int digits)
{
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

void LCDprintDigits(int LCDdigits)
{
  lcd.print(":");
  if(LCDdigits < 10)
    Serial.print('0');
  lcd.print(LCDdigits);
}

oringo,

I'm pretty sure someone here can help you, maybe even me!

But to do that we need to see your whole sketch. Be sure and post it between code tags ( the # button above the test edit box).

The code you posted was "way" not enough to tell what your problem is.

Cheers,
John

I add whole sketch.

Unless you have changed this line in TimeAlarms.h the maximum number of alarms that can be active is 6

#define dtNBR_ALARMS 6   // max is 255

Have you changed it ?

I have modified it up to 40.

"Time.h"
#define dtNBR_ALARMS 40

Incidentally, you have an insane number of functions in that code all doing basically the same thing. There are a number of ways to reduce the number of functions but the easiest to understand would be to have one function and to call it with parameters.

void showState(char serial.Message, char lcdMessage, int blueValue, int MWValue, int WValue)
{
  Serial.println(serial.Message); 
  lcd.setCursor(0, 1);
  lcd.print(lcd.Message);  
  analogWrite(BLUE, blueValue);
  digitalWrite(MW, MWValue);
  digitalWrite(W, WValue);  
}

Then at 18:30 call it like this :

showState("BLUE 100% WHITE ON POWER ON","B100% W100% M ON ",255,0,0);

and at 19:30 like this :

showState("BLUE 100% WHITE OFF POWER ON","B100% W00% M ON ",255,0,255);

You could have the function construct the text shown based on the values sent to remove the need to send the text explicitly and save space

Thank you! idea is good and simple. :slight_smile:

I add your sketch and i get error
invalid conversion from "const char*" to "char"

I am beginner.
What i must add more to sketch?

oringo:
I use timealarms to control led light (42w). I use 17 alarm.Repeat per day.
In test mode(1minute) everything works fine, but in 24h cycle it stops working correctly.

Do you mean that the it works properly throughout the first day but then the next day at 6:30 am it doesn't work?

For the "const char *" error I think for now you can just change

from this:
void showState(char serial.Message, char lcdMessage, int blueValue, int MWValue, int WValue)
to this:
void showState(const char* serialMessage, const char* lcdMessage, int blueValue, int MWValue, int WValue)

(there are some other issues but try this first)

John

Sorry, my fault for doing things in a hurry.

The function declaration should be

void showState(char* serialMessage, char* lcdMessage, int blueValue, int MWValue, int WValue)
{
  Serial.println(serialMessage); 
  lcd.setCursor(0, 1);
  lcd.print(lcdMessage);  
  analogWrite(BLUE, blueValue);
  digitalWrite(MW, MWValue);
  digitalWrite(W, WValue);  
}

johncc:
void showState(const char* serial.Message, const char* lcdMessage, int blueValue, int MWValue, int WValue)

That doesn't look right to me.

Ok, but I'm blaming UKHeliBob for that one :slight_smile:

edited/fixed, thanks

I will gladly take the blame as it was originally wrong in more ways than one.

Is it right now though I ask myself (and others) ?

The argument types don't exactly match the signatures for analogWrite() and digitalWrite(), but I don't suppose we're too concerned about type safety here.

I hear that, I still keep wanting digitalWrite to be digitalWrite(int, bool), but Mr. Nick has convinced me to "get over it" :slight_smile:

Cheers,
John

johncc:
Do you mean that the it works properly throughout the first day but then the next day at 6:30 am it doesn't work?

24 hours is ok, but 48 hours then it like stops and keeps old values. Short test it works correctly.

Thank you! New sketch looks nice and still is simple.

#include <DS1307RTC.h>
#include <Time.h>
#include <TimeAlarms.h>  // accepts 23 alarmRepeat
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

const int MW = 6;        //leds power supply (relay on / off)
const int W = 9;        //white led (relay ON /off)  
const int BLUE = 10;         //blue led PWM module (PWM or withoutPWM 100%) 



LiquidCrystal_I2C lcd(0x27,16,2);

void setup()
{
 Serial.begin(9600);
 setTime(9,29,55,12,30,12);      // TEST

/*
  setSyncProvider(RTC.get);   // the function to get the time from the RTC
    if(timeStatus()!= timeSet) 
       Serial.println("Unable to sync with the RTC");
    else
        Serial.println("RTC has set the system time"); 
*/

  lcd.init(); // initialize the lcd
  lcd.backlight();
  lcd.setCursor(0, 1);
  lcd.print("RESTART");
  
  pinMode (MW, OUTPUT);
  pinMode (W, OUTPUT);
  pinMode (BLUE, OUTPUT);
  
  digitalWrite(MW, HIGH);      //power supply OFF
  digitalWrite(W, HIGH);      //white leds OFF
  
  // ***** TEST ****
  
  Alarm.alarmRepeat(9,30,00, H06M30);        
  Alarm.alarmRepeat(9,30,05, H07M30);       
  Alarm.alarmRepeat(9,30,10, H08M30);        
  Alarm.alarmRepeat(9,30,15, H10M30);        
  Alarm.alarmRepeat(9,30,20, H10M30);        
  Alarm.alarmRepeat(9,30,25, H11M30);        
  Alarm.alarmRepeat(9,30,30, H12M30);        
  Alarm.alarmRepeat(9,30,35, H13M30);        
  Alarm.alarmRepeat(9,30,40, H14M30);        
  Alarm.alarmRepeat(9,30,44, H15M30);        
  Alarm.alarmRepeat(9,30,50, H16M30);        
  Alarm.alarmRepeat(9,30,55, H17M30);        
  Alarm.alarmRepeat(9,31,05, H18M30);        
  Alarm.alarmRepeat(9,31,10, H19M30);        
  Alarm.alarmRepeat(9,31,15, H20M30);       
  Alarm.alarmRepeat(9,31,20, H21M30);        
  Alarm.alarmRepeat(9,31,25, H22M30);       
  Alarm.alarmRepeat(9,31,30, H23M30);       
  
  
  ///LED control times        
  /*                 
  Alarm.alarmRepeat(6,30,00, H06M30);        
  Alarm.alarmRepeat(7,30,05, H07M30);        
  Alarm.alarmRepeat(8,30,10, H08M30);        
  Alarm.alarmRepeat(9,30,15, H09M30);       
  Alarm.alarmRepeat(10,30,20, H10M30);        
  Alarm.alarmRepeat(11,30,25, H11M30);        
  Alarm.alarmRepeat(12,30,30, H12M30);        
  Alarm.alarmRepeat(13,30,35, H13M30);        
  Alarm.alarmRepeat(14,30,40, H14M30);        
  Alarm.alarmRepeat(15,30,44, H15M30);        
  Alarm.alarmRepeat(16,30,50, H16M30);        
  Alarm.alarmRepeat(17,30,55, H17M30);        
  Alarm.alarmRepeat(18,31,05, H18M30);      
  Alarm.alarmRepeat(19,31,10, H19M30);        
  Alarm.alarmRepeat(20,31,15, H20M30);       
  Alarm.alarmRepeat(21,31,20, H21M30);        
  Alarm.alarmRepeat(22,31,25, H22M30);        
  Alarm.alarmRepeat(23,31,30, H23M30);       
  */
}

void loop() {
  digitalClockDisplay();
  Alarm.delay(1000);

}

void showState(char* serialMessage,char* lcdMessage,int blueValue,int MWValue,int WValue) 
{

  Serial.println(serialMessage); 
  lcd.setCursor(0, 1);
  lcd.print(lcdMessage);  
  analogWrite(BLUE, blueValue);
  digitalWrite(MW, MWValue);
  digitalWrite(W, WValue);  
}
   
void H06M30() {                            
 showState("BLUE 33% WHITE OFF POWER ON","B33% WOFF M ON ", 85,0,1);
 }
 void H07M30() {                            
  showState("BLUE 33% WHITE OFF POWER ON","B66% WOFF M ON ", 85,0,1);           
 }
void H08M30() {                            
showState("BLUE 66% WHITE OFF POWER ON","B66% WOFF M ON ", 170,0,1);
 }  
void H09M30() {                            
showState("BLUE 66% WHITE OFF POWER ON","B66% WOFF M ON ",170,0,1); 
 }  
void H10M30() {                            
showState("BLUE 100% WHITE ON POWER ON","B100% W100% M ON ",255,0,0);
 }  
void H11M30() {                            
showState("BLUE 100% WHITE ON POWER ON","B100% W100% M ON ",255,0,0);
 } 
void H12M30() {                            
showState("BLUE 100% WHITE ON POWER ON","B100% W100% M ON ",255,0,0);
 } 
void H13M30() {                            
showState("BLUE 100% WHITE ON POWER ON","B100% W100% M ON ",255,0,0);
 } 
void H14M30() {                            
showState("BLUE 100% WHITE ON POWER ON","B100% W100% M ON ",255,0,0);
 }  
void H15M30() {                            
showState("BLUE 100% WHITE ON POWER ON","B100% W100% M ON ",255,0,0);
 }  
void H16M30() {                            
showState("BLUE 100% WHITE ON POWER ON","B100% W100% M ON ",255,0,0);
 } 
void H17M30() {                            
showState("BLUE 100% WHITE ON POWER ON","B100% W100% M ON ",255,0,0);
 }
void H18M30() {                            
showState("BLUE 100% WHITE ON POWER ON","B100% W100% M ON ",255,0,0);
 }
void H19M30() {                            
showState("BLUE 100% WHITE OFF POWER ON","B100% W OFF M ON ",255,0,1);
 }
void H20M30() {                            
showState("BLUE 66% WHITE OFF POWER ON","B100% W OFF M ON ",170,0,1);
 }
void H21M30() {                            
showState("BLUE 66% WHITE OFF POWER ON","B66% W OFF M ON ",170,0,1);
 }
void H22M30() {                            
showState("BLUE 33% WHITE OFF POWER ON","B66% W OFF M ON ",85,0,1);
 }
void H23M30() {                            
showState("BLUE OFF WHITE OFF POWER OFF","....GOOD BYE....",0,1,1);
 }
 
void digitalClockDisplay()
{
  // digital clock display of the time
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.println(); 
  lcd.setCursor(0, 0);
  lcd.print(hour());
  LCDprintDigits(minute());
  LCDprintDigits(second());
}

void printDigits(int digits)
{
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

void LCDprintDigits(int LCDdigits)
{
  lcd.print(":");
  if(LCDdigits < 10)
    Serial.print('0');
  lcd.print(LCDdigits);
}
[/quote]

24 hours is ok, but 48 hours then it like stops and keeps old values. Short test it works correctly.

So you're saying that at 6:30 am 48 hours later, both the Serial Monitor and the LCD still says 23:31 or something like that?

void LCDprintDigits(int LCDdigits)
{
  lcd.print(":");
  if(LCDdigits < 10)
    Serial.print('0');
  lcd.print(LCDdigits);
}

(also you probably want lcd.print() here)

John

PeterH:
The argument types don't exactly match the signatures for analogWrite() and digitalWrite(), but I don't suppose we're too concerned about type safety here.

I wondered about how to pass HIGH and LOW when I suggested the function. What is the correct way to pass them ?

johncc:
So you're saying that at 6:30 am 48 hours later, both the Serial Monitor and the LCD still says 23:31 or something like that?

Last sketch stops in 48 hours, but not with last command - Alarm.alarmRepeat(23,31,30, H23M30);

New sketch:
i reset arduino yesterday evening at 22.00.
I checked it at 07.00 am and everything was ok.
before 18.00 was last alarm already done - Alarm.alarmRepeat(23,31,30, H23M30);
LCD.print was loop H23M30 print "...GOODBYE..."
LCD clock time was correct.

Sketch is correct if it is without RTC.

setTime(20,53,55,12,30,12);

Maybe problem is circuit or something in RTC settings.
DS1307 board and LCD display are connected parallel from sensor shield SDA, SCL, VCC, GDN

Please suggest how connect correctly RTC and LCD.

How are they connected now ?