Using DS1307RTC to turn on LEDs

Hello all,
I am pretty new to the forum and have tinkered with a few of the Arduino projects in the past few years, although I am still very much a novice so any help would be much appreciated. The project I am making is a Medication reminder. using an UNO, LCD2004a, DS1307, and a few LED lights. I have successfully programmed so far to dislplay the correct date and time but am having a hard time turning on the LED at specific days. I would like for one LED (Green) to be turned on Monday @ 09:00PM and stay on until Friday morning @ 03:00 am, at that point the Green would turn off and a yellow LED would turn on until Friday @ 12:00pm, when it would turn off and the Green would again turn on until Monday @ 03:00 Ive included the code im working with so far

#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4);  // set the LCD address to 0x27 for a 16 chars and 2 line display
#include "Arduino.h"
#include "uRTCLib.h"


// uRTCLib rtc;
uRTCLib rtc(0x68);
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

void setup()
{delay (2000);
 Serial.begin(9600);
  Serial.println("Serial OK");
#ifdef ARDUINO_ARCH_ESP8266
    URTCLIB_WIRE.begin(0, 2); // D3 and D4 on ESP8266
  #else
    URTCLIB_WIRE.begin();
  #endif

  rtc.set(0, 29, 11, 7, 13, 7, 24);
  // rtc.set(second, minute, hour, dayOfWeek, dayOfMonth, month, year)
  // set day of week (1=Sunday, 7=Saturday)
}


void loop()
{
  rtc.refresh();
  digitalWrite(13, LOW);
  lcd.init();                      
  lcd.backlight();
  lcd.setCursor(2,0);
  lcd.print(rtc.month() );
  lcd.print("/");
  lcd.print(rtc.day() );
  lcd.print("/");
  lcd.print(rtc.year() );
  lcd.print(" ");
  lcd.print(rtc.hour() );
  lcd.print(":");
  lcd.print(rtc.minute() );
  lcd.print(":");
  lcd.print(rtc.second() );
  lcd.setCursor(6,1);
  lcd.print(daysOfTheWeek[rtc.dayOfWeek()-1]);
  lcd.setCursor(0,2);
  lcd.print("Temperature:");
  lcd.setCursor(0,3);
  lcd.print("Humidity:");
  
  • You can use if( . . . ) { . . . } to determine if it is time to do something.



@LarryD
I get the gist of what your saying about the if statements; I'm unsure how to write what i want into code:

if( rtc.dayOfWeek() == 1 && rtc.hour() == 9 && rtc.minute() == 0 && rtc.second() == 0)
{
   digitalWrite(13, LEDon);
}

What do the above lines of code do ? :thinking:

Those rtc's are not worth a cracker.
Use DS3231.

1 Like

And if you use a DS3231 you can use the alarms and probably simplify you code.