RTC+Relay

Hello guys so i finaly desided that i want to learn arduino… so i had some parts laying arround … so i first what i did i got my rtc ds3231 connected to arduino then my lcd screen ywrobot lcm1602c and then i was trying to get something like if time is 20:00 turn relay off or on but i kinda fail’d with that ! I found some people asking about the same question but what i found is that they use different rtc and differnet library even try’d other library but that didnt help too! so maybe someone knows how its done the right way with this library ?!

DS3231.zip (379 KB)

so maybe someone knows how its done the right way with this library ?!

Well, first you write a sketch that uses that library. Have you done that? What is it supposed to do? What does it actually do?

Right now my sketch looks like this its only displaying time on screen

#include <DS3231.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h> // Using version 1.2.1
 
// The LCD constructor - address shown is 0x27 - may or may not be correct for yours
// Also based on YWRobot LCM1602 IIC V1
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  
DS3231  rtc(SDA, SCL);

void setup()
{
Serial.begin(115200);
Wire.begin();
rtc.begin();

  lcd.begin(16,2); // sixteen characters across - 2 lines
  lcd.backlight();
  
   pinMode(4, OUTPUT);
 }
 

 
void loop()
{

  lcd.setCursor(12,0);         //Display Time On LCD Right Upper corner !
  lcd.print(rtc.getTimeStr()); //---------------////--------------------

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

}

all what i want is just when time hits 20:00 it turns off my Relay and when its 7:00 its turns it back on !
i try’d something like

 #define LED1  7   
#include <Wire.h>
#include "RTClib.h"

RTC_DS3231 rtc;
DateTime now = rtc.now();
   
void setup()

{    


Serial.begin(9600);
  pinMode(LED1, OUTPUT);       

}

  void loop()
  
 
{
  
 DateTime now = rtc.now();
    if(now.hour() == 24)

   digitalWrite(LED1,0);           // Turns ON LED 1
   Serial.println("Light ON");
   delay(2000);                                      // Wait 2 seconds

   digitalWrite(LED1,1);          // Turns OFF LED 1
   Serial.println("Light OFF");
   delay(2000);
   
}/code]

 but didnt work because my library what i use dont have something like DateTime now = rtc.now();
it seems that it works with no problem for DS1307 rtc..
i have add a zip file with my library what i use ..

i try'd something like

That hasn't a hope in hell of working. Spend a whole day watching the output when you Serial.print(now.hour()). Do you EVER see a 24?

in my own sketch i tried if(now.hour() == 12) this sketch was take from other post!

artursm15:
in my own sketch i tried if(now.hour() == 12) this sketch was take from other post!

So please post your own sketch. It's a bit of a waste of time for us to analyse a sketch that does not reflect what gives you problems