Arduino Ultra Mega Timers

6,436

30

39

Hi! "Arduino Timer with on/off setpoint" is my most viewed instructable by far, so i got a lot of questions in the comments, inbox and youtube, about how to add minutes,seconds, days and save settings on the eeprom.... so i decided to bring an old code, made with PIC, to arduino, easier to share and make.

I tried to make this project compact, easy to use and set up, with 3 buttons and a 16x2 lcd.The interface is based on my previous instructable "Turn single screen into multiple screens". If you want to learn how this interface was made, please visit:

https://www.instructables.com/id/Arduino-LCD-16x2-Turn-Single-Screen-Into-Multiple-/

Here you have 6 codes to choose:

All timers are hours,minutes and seconds (on/off) programmables. Save data on the eeprom.

-1Timer for everyday,

-1Timer, selectable day

-4 Timers. 1 relay, for everyday

All timers has a "simple" version, that means, without lcd interface. Useful if you want to save money or don't need to chage the settings periodically.

These timers can recover the data and work even in case of power failure. The code was made to activate the relay at any moment.

We'll start from the basic timer to the more complete one.With this timer you can even turn on something for a second!

You will need:

-Arduino UNO

-LCD 16x2 (I2C)

-RTC 3231 module

-Push buttons x3

-10K resistors x3

-Relay module x1

-Breadboard,wires,etc

Watch the video!

Step 1: First Steps

First of all, we need to set up the LCD,RTC and clear the arduinos eeprom.

-LCD The lcd must have an address, declared at the beginning of the code:

LiquidCrystal_I2C lcd(0x3F,16,2);//0x3F is my lcd address, maybe not yours!

If you don't know your address, use the utility "I2C scanner" . Connect your lcd as follows:

-VCC to arduino 5V

-GND to arduino GND

-SDA to arduino analog pin 4

-SCL to arduino analog pin 5

Upload the code and open the serial monitor, the address will be displayed. Replace the address if it's not the same (0x3F) in the codes of the next steps.

Download:

https://gist.github.com/tfeldmann/5411375

-RTC We'll use the RTC 3231, but the rigth time must be programmed. Add the RTClib-master to your Arduino library. Go to File/examples/RTClib/ds3231 .Upload the code. This sketch take the Date and Time according the computer you're using (right when you compile the code) and uses that to program the RTC. If your computer time is not set right you should fix that first. Then you must press the Upload button to compile and then immediately upload.

Warning !:If you compile and then upload later, the clock will be off by that amount of time. Then open up the Serial monitor window to show that the time has been set.

Connect your rtc as follows:

-VCC to arduino 5V
-GND to arduino GND

-SDA to arduino analog pin 4

-SCL to arduino analog pin 5

If you don't know, the lcd and the rtc can be connected at the same time to the I2C bus (analog 4 SDA, analog 5 SCL).

-EEPROM clear Commonly ,eeprom values are 255 x address and we need to set these values to 0. The eeprom library is already included on your arduino IDE.

Go to File/Examples/EEPROM/eeprom_clear.

Upload the code and wait for the pin 13 led to turn on. You can check your values with the eeprom_read code.

Watch the video!

The RTC and LCD libraries used in this tutorial:

Step 2: Timer's Trick

One of the challenges here is to compare the "on time" and "off time" with the current time at every moment. One can think in something like this:

if(now hour==on hour &&now minute==on minute && now second==on second)

relay on

if(now hour==off hour&&now minute==off minute&&now second==off second)

relay off

This might work, but what if your on setpoint is 12:30:00, your off setpoint 15:45:15 and the current time is 13:00:00 ? Well, you will wait until the next day to turn on your device ! Or what if you lose power beetwen 12:30:00 and 15:45:15? The same thing:to wait for the settings to be triggered.

If you looked at my previous timer, there are a lot of if/else statements to control the relay, because time is cyclic and we need to cover all the possible scenarios. But to add minutes and seconds it´s something else. All values can be higher or lower than the on/off settings or current time and try to compare it will be a mess.

So i thought in something like military time or string number from 0 to 235959, and that's the trick of these timers. So, we convert the current time, on setpoint and off setpoint into single number.

I just will explain how the timers work,because the interface to change settings and display values,etc, can be studied in my instructable of multiple screens. Link in the intro.

First, we create the variables for the timer (on/off):

//------First Timer
byte onhour1;

byte onmin1;

byte onsec1;

byte offhour1;

byte offmin1;

byte offsec1;

A byte data type (0 to 255 unsigned) was used to store the values. A byte can be easily stored on the eeprom (1 data x address) and the bigger number will be 59 (minute or second). We take the values from the eeprom, 0 at the very beginning, because the eeprom was cleared.Where ( ) is the eeprom address.

void setup.......

//--------eePROM read values-------//
//------First Timer

onhour1=EEPROM.read(0);

onmin1=EEPROM.read(1);

onsec1=EEPROM.read(2);

offhour1=EEPROM.read(3);

offmin1=EEPROM.read(4);

offsec1=EEPROM.read(5);

These values can be changed and saved, later on with the buttons interface.

But we can't do the maths (conversion to single number) with bytes because our bigger number will be 235,959 or int =32,767 (positive) or unsigned int=65,535. So, unsigned long will be.

We create another variable to convert byte into unsigned long. Also, the final values to work with: on_Time1 and off_Time1

//------To convert first timer into Single number
unsigned long on_Time1;

unsigned long on_hour1;

unsigned long on_min1;

unsigned long on_sec1;

unsigned long off_Time1;

unsigned long off_hour1;

unsigned long off_min1;

unsigned long off_sec1;

//-------To convert clock into single number
unsigned long Time;

unsigned long Hour;

unsigned long Min;

unsigned long Sec;

The conversion is executed in the void loop. For the current time, we take the values from the rtc with the library function now() ,hour, minute, second and assign this values to Hour,Min and Sec. "Time" is the result of the sum of Hour*10000 ; Min*100 and Sec.

Example: 15:45:34 = (15*10000 + 45*100 + 34) = 154,534

//-------------Conversion----------//

//---------Converting clock time into single number

Hour = now.hour();

Min = now.minute();

Sec = now.second();

Time = (Hour*10000+ Min*100 +Sec*1);

And the same with the on/off settings. Here we take the values from the beginning (byte) and assign these values as follows:

//--------Converting firt timer on/off into single number

on_hour1=onhour1;

on_min1=onmin1;

on_sec1=onsec1;

on_Time1=(on_hour1*10000 + on_min1*100 + on_sec1);

off_hour1=offhour1;

off_min1=offmin1;

off_sec1=offsec1;

off_Time1=(off_hour1*10000 + off_min1*100 + off_sec1);

The final result are the 3 variables with we will work : Time, on_Time1 and off_Time1

Now the relay function. Here we compare "Time" with "on_Time1" and "off_Time1" to turn on or off the relay. We have 3 main "if" statements:

1)if(onhour1 == offhour1 && onmin1==offmin1 && onsec1==offsec1){

digitalWrite(Relay, LOW); }

This statement is an enable/disable function. We use the byte values, because we don't need any conversion here. If all values are the same the relay is off. If you change , even a second, the timer will work.

2)if(on_Time1 < off_Time1){

if(Time >= on_Time1 && Time < off_Time1){ //Start

digitalWrite(Relay, HIGH);

}

else if(Time >= off_Time1) {

digitalWrite(Relay, LOW);

}

else{

digitalWrite(Relay, LOW);

}

}

3)if (on_Time1 > off_Time1){

if(Time >= on_Time1 && Time <= 235959){ //Start

digitalWrite(Relay, HIGH);

}

else if(Time < off_Time1 ){

digitalWrite(Relay, HIGH);

}

else if(Time >= off_Time1 && Time < on_Time1){

digitalWrite(Relay, LOW); } }

These 2 functions cover the 2 possible settings: "on time" lower than "off time" and "on time" higher than "off time".Inside each one you can find 3 statements more to control the relay at any moment.The functions can be easily understand with a graphic demo. Watch the pictures!

With the buttons interface we can change the values (on/off) and store our new ones.This is the structure to store the values. As i have said, we store the byte values on a single address. where:

(address, byte value)

EEPROM.write(0, onhour1);
EEPROM.write(1, onmin1);

EEPROM.write(2, onsec1);

EEPROM.write(3, offhour1);

EEPROM.write(4, offmin1);

EEPROM.write(5, offsec1);

Step 3: 1 Timer for Everyday

This timer is the base for the next ones. Mount the circuit following the schematic, remember RTC and LCD share the same pins (analog 4 SDA ; analog 5 SCL).

Upload the code, remember to add the libraries RTClib and LiquidCrystal_I2C.

You have 3 buttons to move the 3 main pages with the up/down buttons and select button to enter and move the submenus.

The first page shows you a message and the current time.

The second page is the on/off interface, here you can change the setpoints. Press the select button to enter to submenu, an arrow will be placed in front of each item, press up or down to set the on hour, minute, second and off hour, minute, second. Press the select button to move beetwen items (forward only) The final item is the "back" char, if you press up, it will exit the submenu and now you can move the main pages. If you press down, the arrow will be placed in front of the first item.

The third page is to save your settings. Just press the select buton and all your data will be stored on the eeprom. A message "SAVED!" will be displayed and automatically redirect to the main page.

This timer will work everyday and in case of power failure or disconnection will recover the data from the eeprom to start again.

With the relay you can control your devices. The relay is activated with a high signal (5V).

Warning! Be careful with the maximum load of the relay!

Step 4: 1 Timer, Selectable Day

This timer is for those who want to control the day where the timer is activated. For this, we'll use the RTC's function "now.dayOfTheWeek()" and it values can be 1 to 7 ; Monday to Sunday. To assign the day of the week to each number, we use this(global variables):

char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

To display it on the LCD (main page):

lcd.print(daysOfTheWeek[now.dayOfTheWeek()]);

We need new variables to know if the day is enebled/disabled.So:

//------Days of the week
boolean Sun1;

boolean Mon1;

boolean Tue1;

boolean Wed1;

boolean Thu1;

boolean Fri1;

boolean Sat1;

We use boolean values (1 or 0) and as the other variables, we take the values from the eeprom.Boolean can be stored in 1 address. The last address used was 5 (offsec1), so we continue with:

void setup.....

Sun1=EEPROM.read(6);
Mon1=EEPROM.read(7);

Tue1=EEPROM.read(8);

Wed1=EEPROM.read(9);

Thu1=EEPROM.read(10);

Fri1=EEPROM.read(11);

Sat1=EEPROM.read(12);

Remember, your first value will be 0 (eeprom clear). So 0 is for disable and 1 for enable day.

In order to control the relay, we need to check the current day and check if the timer is enabled/disabled for that day.

Another switch function is used, where every "case" will be the value of "now.dayOfTheWeek()" (1 to 7)

//----Relay Function per day----//
switch(now.dayOfTheWeek()){ //now.dayOfTheWeek values 1 to 7, monday to sunday

case 1: //If monday

if(Mon1==1){

First_Timer();

}

else{

digitalWrite(Relay1, LOW);

}

break;

case 2: //If tuesday

if(Tue1==1){

First_Timer();

}

else{

digitalWrite(Relay1, LOW);

} break;

case 3: .......and so on...

For example: If today is monday (now.dayOfTheWeek() =1), we enter to the first case. if the boolean value Mon1==1 (day enabled), we call a custom function "First_Timer()", the same relay function from the previous timer, now working as a custom function, so we don't need to write it on every case. If we put a 0 the relay function will be LOW (day disabled). So we use one case per day and skip the others.

Now we need to add another screen to the interface to change the settings.

The main page shows you the current day and time.

The second page the on/off setings.

Here we introduce the new page where you can select the day to activate the relay and it works the same as the others: the arrow indicates the item, if you press the up button you will put a 1 on that day and it will be enabled. If you press down, you will put a 0 and the day will be disabled.

The fourth page save the settings, on/off time and day enabled/disabled. The structure to save:

EEPROM.write(0, onhour1);
EEPROM.write(1, onmin1);

EEPROM.write(2, onsec1);

EEPROM.write(3, offhour1);

EEPROM.write(4, offmin1);

EEPROM.write(5, offsec1);

EEPROM.write(6, Sun1);

EEPROM.write(7, Mon1);

EEPROM.write(8, Tue1);

EEPROM.write(9, Wed1);

EEPROM.write(10, Thu1);

EEPROM.write(11, Fri1);

EEPROM.write(12, Sat1);

Step 5: 4 Timers 1 Relay for Everyday

Another request from the users. This timer is able to control 4 event at day with a single output. No much to say about this because we only add more variables for the timer 2, 3, and 4, also the interface to move the settings. We continue reading and writting from the eeprom, from the last address used.

Note: Be careful to don't overlap the timers, because any of it can turn on or off the relay.

So, here you have 3 timers with a nice interface. For the "simple" version, you just need to change the values within "///////////".Default values are 0.

on/offhour1, 2,3,4 = 0-23

on/offmin1, 2,3,4 =0-59

on/offsec1, 2,3,4 =0-59

Day enabled/disabled =1 for enable 0 for disable.

"Simple" timers doesn't need eeprom save because you have already stored the values. This useful too, if you want to study the timer's code.

As you can see, more timers can be added, following the logic,and you can use the "selectable day" function on it.

If you are a beginner, this project it's easy to make and run, but if you want to go deep into the code, that's another story. This is not rocket science, but you need some knowledge to face the codes. That's why i've separeted the codes for better understanding. i'm just saying this because i get a lot of question from users about how to modify codes and i can't do that for you, I can always help you, of course.I hope you understand.

Share

    Recommendations

    • Toys Contest

      Toys Contest
    • First Time Author

      First Time Author
    • Make it Glow Contest 2018

      Make it Glow Contest 2018

    39 Discussions

    0
    None
    SatishK105

    23 days ago

    i tried to build this but there are some problems which i am facing..
    The display is not showing time, instead it is showing what is in pic.

    IMG_20181117_031952.jpg
    2 replies
    0
    None
    NicolasJ7SatishK105

    Reply 23 days ago

    Is your LCD address set right? Are you using the LCD library from step 1?
    Try to test the lcd with the library examples, the same with the RTC

    0
    None
    SatishK105NicolasJ7

    Reply 23 days ago

    error is in code
    LiquidCrystal_I2C lcd(0x3F,2,1,0,4,5,6,7,3,POSITIVE);
    The above code was needed.
    And also thanks for the project , I made it and it is working fine....

    0
    None
    VaggelhsK

    4 weeks ago

    error guys can help me any one?

    Ultra_Mega_Timer_RTC3231:12: error: invalid conversion from 'int' to 't_backlighPol' [-fpermissive]
    LiquidCrystal_I2C lcd(0x3F,16,2);//0x3F is my lcd address, maybe not yours!
    ^
    In file included from C:\Users\Vaggelhs\Downloads\Ultra_Mega_Timer_RTC3231\Ultra_Mega_Timer_RTC3231.ino:11:0:
    C:\Users\Vaggelhs\Documents\Arduino\libraries\LiquidCrystal_I2C/LiquidCrystal_I2C.h:53:4: error: initializing argument 3 of 'LiquidCrystal_I2C::LiquidCrystal_I2C(uint8_t, uint8_t, t_backlighPol)' [-fpermissive]
    LiquidCrystal_I2C (uint8_t lcd_Addr, uint8_t backlighPin, t_backlighPol pol);
    ^
    exit status 1
    invalid conversion from 'int' to 't_backlighPol' [-fpermissive]

    4 replies
    0
    None
    NicolasJ7VaggelhsK

    Reply 4 weeks ago

    Try this:
    delete " ,16,2 "
    LiquidCrystal_I2C lcd(0x3F);//0x3F is my lcd address, maybe not yours!

    delete " lcd.init(); " and change for:
    lcd.begin(16,2)

    Are you using the library from step 1?


    0
    None
    VaggelhsKNicolasJ7

    Reply 4 weeks ago

    yes now its work save and upload but i have lcd keypad shield and no work my screen now!

    0
    None
    charliebrown666

    5 weeks ago

    Awesome work Nicolas, my 30year old boiler has a new timer !
    .. There s only one bug in code of Simple_Sel_Day_timer.ino file

    switch(now.dayOfTheWeek()) actually returns "0" for Sun, not "7"... hence why we were cold for breakfast this morning hahah ;-)

    1 reply
    0
    None
    NicolasJ7charliebrown666

    Reply 4 weeks ago

    Great! I will fix the day of the week. If you want, you can share your project " I Made It" button .

    0
    None
    backspace27

    6 weeks ago

    hi, very nice tutorial! is it possible to make 3 timers with 8 channel relays or more?

    1 reply
    0
    None
    NicolasJ7backspace27

    Reply 6 weeks ago

    Thanks for the comment!
    From step 5:

    "As you can see, more timers can be added, following the logic, and you can use the "selectable day" function on it."
    I can't get enough of this question XD, of course, you can add timers until you full the memory. I've uploaded a "2 timers 2 relays" (step 5). Follow that code if you want more relays and outputs.

    0
    None
    lakyou

    Question 7 weeks ago

    I have a program
    of a daily timer but i have to replace (in the program) the LCD_I2C by
    lcd 16 * 2 and the RTC1307 by RTC3231.i have tried but without result
    ....
    thank you

    */
    #include <LiquidCrystal_I2C.h>
    #include <Time.h>
    #include <DS1307RTC.h>
    #include <Wire.h>
    #include <AnalogButtons.h>
    #include <EEPROM.h>
    int sonnet = 13; // sortie vers le relais

    LiquidCrystal_I2C lcd(0x3F,2,1,0,4,5,6,7); // lcd(addr,RW,RS,E,D4,D5,D6;D7)
    String Jour[]={"Dim ", "Lun ", "Mar ", "Mer ", "Jeu ", "Ven ", "Sam "};
    byte memo=0, hautbas=0, droite=0, HrAlarm=0, MinAlarm=0, ConfigAlarm=0;
    byte CurCol[6]={6,9,14,5,8,11};
    byte CurColAlarm[10]={1,4,7,9,10,11,12,13,14,15};
    tmElements_t tmps;
    boolean actualiser=0;

    AnalogButtons pressBouton(A0, 100, &selectBouton);// Cmd les bouttons
    Button b1 = Button(1,670,800);
    Button b2 = Button(2,0,10);
    Button b3 = Button(3,500,530);

    void selectBouton(int id,boolean longAppui){
    switch (id) {
    case 1: // haut = incrémenter
    if(hautbas==0){
    switch (droite) {
    case 0:
    hautbas+=1;
    HrAlarm = EEPROM.read(hautbas*3);
    MinAlarm = EEPROM.read(hautbas*3 + 1);
    ConfigAlarm = EEPROM.read(hautbas*3 + 2);
    actualiser=1;
    break;
    case 1:
    tmps.Day+=1;
    if(tmps.Day >31) tmps.Day=1;
    memo -=1;
    break;
    case 2:
    tmps.Month+=1;
    if(tmps.Month >12) tmps.Month=1;
    memo -=1;
    break;
    case 3:
    tmps.Year+=1;
    memo -=1;
    break;
    case 4:
    tmps.Hour+=1;
    if(tmps.Hour >23) tmps.Hour=0;
    memo -=1;
    break;
    case 5:
    tmps.Minute+=1;
    if(tmps.Minute >59) tmps.Minute=0;
    memo -=1;
    break;
    case 6:
    tmps.Second+=1;
    if(tmps.Second >59) tmps.Second=0;
    memo -=1;
    break;
    }
    } else {
    switch (droite) {
    case 0:
    if(hautbas==30){ // Nombre de sonnerie
    hautbas=0;
    }else{
    hautbas+=1;
    HrAlarm = EEPROM.read(hautbas*3);
    MinAlarm = EEPROM.read(hautbas*3 + 1);
    ConfigAlarm = EEPROM.read(hautbas*3 + 2);
    }
    break;
    case 1:
    HrAlarm+=1;
    if(HrAlarm >23) HrAlarm=0;
    break;
    case 2:
    MinAlarm+=1;
    if(MinAlarm >59) MinAlarm=0;
    break;
    default:
    bitWrite(ConfigAlarm, droite-2, !bitRead(ConfigAlarm, droite-2));
    break;
    }
    actualiser=1;
    }

    break;
    case 2: // bas = décrémenter
    if(hautbas==0){
    switch (droite) {
    case 0:
    hautbas=30; // Nombre de sonnerie
    HrAlarm = EEPROM.read(hautbas*3);
    MinAlarm = EEPROM.read(hautbas*3 + 1);
    ConfigAlarm = EEPROM.read(hautbas*3 + 2);
    actualiser=1;
    break;
    case 1:
    tmps.Day-=1;
    if(tmps.Day <1) tmps.Day=31;
    memo -=1;
    break;
    case 2:
    tmps.Month-=1;
    if(tmps.Month <1) tmps.Month=12;
    memo -=1;
    break;
    case 3:
    tmps.Year-=1;
    if(tmps.Year <45) tmps.Year=45; // YearMin = 2015
    memo -=1;
    break;
    case 4:
    tmps.Hour-=1;
    if(tmps.Hour >23) tmps.Hour=23;
    memo -=1;
    break;
    case 5:
    tmps.Minute-=1;
    if(tmps.Minute >59) tmps.Minute=59;
    memo -=1;
    break;
    case 6:
    tmps.Second-=1;
    if(tmps.Second >59) tmps.Second=59;
    memo =tmps.Second-1;
    break;
    }
    } else {
    switch (droite) {
    case 0:
    hautbas-=1;
    HrAlarm = EEPROM.read(hautbas*3);
    MinAlarm = EEPROM.read(hautbas*3 + 1);
    ConfigAlarm = EEPROM.read(hautbas*3 + 2);
    break;
    case 1:
    HrAlarm-=1;
    if(HrAlarm >23) HrAlarm=23;
    break;
    case 2:
    MinAlarm-=1;
    if(MinAlarm >59) MinAlarm=59;
    break;
    default:
    bitWrite(ConfigAlarm, droite-2, !bitRead(ConfigAlarm, droite-2));
    break;
    }
    actualiser=1;
    }
    break;
    case 3: // droite = OK = Valider
    droite +=1;
    if (hautbas == 0 && droite > 6 ){
    RTC.write(tmps); // écrire le temps sur RTC
    setSyncProvider(RTC.get); //synchronisation du système avec RTC
    droite=0;
    }
    if(droite > 9){
    EEPROM.write(hautbas*3, HrAlarm);
    EEPROM.write(hautbas*3 + 1, MinAlarm);
    EEPROM.write(hautbas*3 + 2, ConfigAlarm);
    droite=0;
    }
    actualiser=1;
    break;
    }
    }

    void affichage(){
    if(hautbas==0){
    if(droite==0) breakTime(now(),tmps) ;
    if(memo!=tmps.Second){
    lcd.setCursor(0,0);
    lcd.print(' ');
    lcd.print(Jour[tmps.Wday-1]);
    aff(tmps.Day,"/");
    aff(tmps.Month,"/");
    aff(tmYearToCalendar(tmps.Year)," ");
    lcd.setCursor(0,1);
    lcd.print(" "); // 4 espaces
    aff(tmps.Hour,":");
    aff(tmps.Minute,":");
    aff(tmps.Second," "); // 4 espaces
    memo =tmps.Second;
    }
    if(droite==0){
    lcd.noBlink();
    } else {
    lcd.setCursor(CurCol[droite-1],droite/4); //positionner le curseur selon droite
    lcd.cursor(); //afficher le curseur
    }
    } else {
    if(actualiser){
    lcd.setCursor(0,0);
    lcd.print("AL Heure DLMMJVS");
    lcd.setCursor(0,1);
    aff(hautbas," ");
    aff(HrAlarm,":");
    aff(MinAlarm," ");
    for (byte j=1; j <= 7; j++) lcd.print(bitRead(ConfigAlarm, j));
    lcd.setCursor(CurColAlarm[droite],1); //positionner le curseur selon droite
    lcd.blink(); //afficher le curseur
    actualiser=0;
    }
    }
    }

    void aff(int nbr,String chaine){
    if(nbr < 10) lcd.print('0');
    lcd.print(String(nbr)+chaine);
    }

    void setup() {
    //Serial.begin(9600);
    pinMode(sonnet, OUTPUT);
    digitalWrite(sonnet, 1); /// puisque c un module
    lcd.begin(16,2);
    lcd.setBacklightPin(3,POSITIVE);
    lcd.setBacklight(HIGH); // lumiere arriere plan lcd
    setSyncProvider(RTC.get); // config la lecture du temps RTC

    pressBouton.addButton(b1);
    pressBouton.addButton(b2);
    pressBouton.addButton(b3);

    }


    void loop() {
    //AnalogButtons::configure(A0); // nzawlo
    affichage();
    pressBouton.checkButtons(); // vérifier si un bouton est appuyer

    if( !second() ){ // Nombre de sonnerie + 1
    for (byte k=1; k < 31 ; k++){ // vérifier si l'heure d'un alarme est arrivée
    byte HrA = EEPROM.read(k*3);
    byte MinA = EEPROM.read(k*3 + 1);
    byte ConfigA = EEPROM.read(k*3 + 2);
    if( hour() == HrA && minute() == MinA && bitRead(ConfigA, weekday())==1 ){
    digitalWrite(sonnet, 0);// 0 /// puisque c un module
    break;
    }
    }
    }
    // temps de la sonnerie: 6 second
    if(second() > 6 && !digitalRead(sonnet)) digitalWrite(sonnet, 1); //stop alarme après 6s ///1 puisque c un module

    }

    1 more answer
    0
    None
    NicolasJ7lakyou

    Answer 7 weeks ago

    Hi! I can see some mistakes and wrong statements. This is your code or something you are modifying? If you want to make an alarm there are a lot of tutorial covering that topic. It's really hard to explain what's wrong here. You can use my code to trigger an alarm custom function, will be more easier.

    0
    None
    saiko

    Question 7 weeks ago

    Hi NicolasJ7.
    Thanks a lot for this tutorial. I have been trying to create time to run a watering pump for my balcony garden.
    I have got all the components but the I2C LCD. I have a 1602 LCD module without the I2C driver - is it possible do this project without i2C module? what part of the code I need to update?

    Thanks again!!

    1 more answer
    0
    None
    NicolasJ7saiko

    Answer 7 weeks ago

    Hi, thanks for the comment! I recommend you to get one, they are really cheap, around 2 dollars and you will find a lot of projects with this configuration.
    Here what you need to do:
    Hardware
    LCD pins to Arduino pins and contrast pot
    1 VSS to GND
    2 VDD to 5V
    3 VO to pot center
    4 RS to pin 2
    5 RW to GND
    6 EN or E to pin 3
    7 D0 NC
    8 D1 NC
    9 D2 NC
    10 D3 NC
    11 D4 to pin 4
    12 D5 to pin 5
    13 D6 to pin 6
    14 D7 to pin 7
    15 A to 5V
    16 K to GND by 1K resistor(or jumper)
    The extremes of the trimpot to 5V and GND
    Buttons
    Up pin 8
    Select pin 9
    Down pin 10
    Software (you must have the LiquidCrystal library)
    variables

    #include // Delete the other lcd library
    LiquidCrystal lcd(2, 3, 4, 5, 6, 7); //DeleteLiquidCrystal_I2C lcd(0x3F,16,2);

    int up=8; //Up button to pin 8 //Change the pin numbers
    int sel=9; //Select button to pin 9
    int down=10; //Down button to pin 10
    void setup
    lcd.begin(16, 2);//Delete lcd.init and lcd.backlight. Don't delete lcd.clear
    void loop
    //No changes

    That's all. Let me know if works

    0
    None
    kadird4

    2 months ago

    Hello there
    my project attracted my interest

    "Sel_day_ultra_mega_timer_3231" Is it possible to make a 5-memory timer?

    1 reply