DS3231 Read

Hello!
I am need help to modify the code below, the code works fine but I want to read the date values and watch and store them in variables to compare with the values that are the auxiliary variables and then turn off or on a relay! !

Below marking the red where I need help!
I thank you help.

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "DHT.h"
#include <DS3231.h>
#define DHTPIN 7
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27,20,4); //set the LCD address to 0x27 for a 16 chars and 2 line display
DS3231  rtc(SDA, SCL);

//Set the DS3231 values

int year=2016;
int mon=10;
int day=30;
int hour=8;
int min=3;
int sec=0;

[color=red][b]/// How to compare the value of these variables with the TIMER DS3231 ??[/b][/color]

[color=red]int hourK=22;
int minK= 30;

int dayK=22;
int monK= 12;
int yearK=2016;[/color]

////////////////////////////////////////////////////////////////////////////

void setup() { 
  dht.begin();
  rtc.begin(); // Initialize the rtc object
  rtc.setDate(day, mon, year);   // Set the date to  1st, 2016
  rtc.setTime(hour ,min,sec);     // Set the time to 12:00:00 (24hr format)
   
  lcd.backlight();
  
  lcd.init();
}

void loop() {
//  int readDataM = dht.readData();
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  lcd.setCursor(0,0); // Sets the location at which subsequent text written to the LCD will be displayed
  lcd.print("Temp.: "); // Prints string "Temp." on the LCD
  lcd.print(t); // Prints the temperature value from the sensor
  lcd.print(" C");
  lcd.setCursor(0,1);
  lcd.print("Humi.: ");
  lcd.print(h);
  lcd.print(" %");
   
 lcd.setCursor(0,2);
 lcd.print("Time: ");
 lcd.print(rtc.getTimeStr());
 lcd.setCursor(0,3);
 lcd.print("Date: ");
 lcd.print(rtc.getDateStr());
 
 //delay(1000); 
}
if (year ==yearK &&
     month == monthK &&
     ... &&
     ... &&
     second == secondK )
{
    // match
}

Hello everyone!!

sterretje I made changes in my code (marked in red) but does not work!
I put in Ds3231 an initial schedule later deleted the lines //rtc.setDate(day, mon, year); and
//rtc.setTime(hour ,min,sec);
then put in hourK and Mink auxiliary variable a value to compare, again put the code in arduino but did not work,
just I did with( hour and min )for testing
Anyone can tell how to solve this problem!

Thanks

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "DHT.h"
#include <DS3231.h>
#define DHTPIN 7
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27,20,4); //set the LCD address to 0x27 for a 16 chars and 2 line display
DS3231  rtc(SDA, SCL);

//Set the DS3231 values

int year=2016;
int mon=10;
int day=30;
int hour=16;
int min=40;
int sec=0;

/// How to compare the value of these variables with the TIMER DS3231 ??

int hourK=16;
int minK= 47;

int dayK=22;
int monK= 12;
int yearK=2016;

////////////////////////////////////////////////////////////////////////////

void setup() { 
 dht.begin();
 rtc.begin(); // Initialize the rtc object
 //rtc.setDate(day, mon, year);   // Set the date to  1st, 2016
 //rtc.setTime(hour ,min,sec);     // Set the time to 12:00:00 (24hr format)
  
 lcd.backlight();
 
 lcd.init();
}

void loop() {
//  int readDataM = dht.readData();
 float h = dht.readHumidity();
 float t = dht.readTemperature();
 lcd.setCursor(0,0); // Sets the location at which subsequent text written to the LCD will be displayed
 lcd.print("Temp.: "); // Prints string "Temp." on the LCD
 lcd.print(t); // Prints the temperature value from the sensor
 lcd.print(" C");
 lcd.setCursor(0,1);
 lcd.print("Humi.: ");
 lcd.print(h);
 lcd.print(" %");
  
lcd.setCursor(0,2);
lcd.print("Time: ");
lcd.print(rtc.getTimeStr());
lcd.setCursor(0,3);
lcd.print("Date: ");
lcd.print(rtc.getDateStr());
[color=red]
 if (hourK== hour&& minK==min )
{
  lcd.setCursor(16,2);
  lcd.print("OK ");
  delay(1000);
}
 [/color]

}

Please correct your post above and add code tags around your code. [code] // your code here [/code]. it should look like this:// your code here

your pb is that you do not extract the hour and min from your RTC before doing the comparison... so you compare with the initial values you set at the beginning of your code.

Look what call to make to the library to get the current hour and same for minute, then use that to update the variables before doing the if


side note

LiquidCrystal_I2C lcd(0x27,[color=red]20[/color],[color=green]4[/color]); //set the LCD address to 0x27 for a [color=red]16 chars[/color] and [color=green]2[/color] line display

it's better when you have comments that they are meaningful....

Hello J_M_L I appreciate the Attention!

You're right, I've seen the library but I understand how to make these changes, I must say that I am new to work with Arduino and I'm here to see if someone can help me!
I before posting here did several searches on google but not found anything that ma help yourself.
If you can enlighten me and help make this code thanks

The LCD I use the 20x4 è the comment is wrong

Please correct your posts above and add code tags around your code. [code] // your code here [/code]. it should look like this:// your code here

that's not difficult, just click quick edit and add [code] in front of the code and add[/code] at the end of your code.

thanks

So you do #include <DS3231.h>. where does this library come from? which one is it? is is this one ?

if so at the top of your code, declare

// declare a Time-data structure
Time  t;

and then in the loop before the if you do

  t = rtc.getTime();// Get data from the DS3231
  hour = t.hour; // the structure holds the info we want. the hours
  min = t.min; // and the minutes
  if (hourK== hour && minK==min) {
     lcd.setCursor(16,2);
     lcd.print("OK ");
   } else {
     lcd.setCursor(16,2);
     lcd.print("   "); // erase the OK in case it was there
   }

Thank you J-M-L

made changes that indicated me, the compiler give me error code that you sent me as below
exit status 1
request for member 'hour' in 't', Which is of non-class type 'float'
What is the reason??

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "DHT.h"
#include <DS3231.h>
#define DHTPIN 7
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27,20,4); //set the LCD address to 0x27 for a 16 chars and 2 line display
DS3231  rtc(SDA, SCL);
Time  t;
//Set the DS3231 values

int year=2016;
int mon=10;
int day=30;
int hour=16;
int min=40;
int sec=0;

/// How to compare the value of these variables with the TIMER DS3231 ??

int hourK=16;
int minK= 47;

int dayK=22;
int monK= 12;
int yearK=2016;

////////////////////////////////////////////////////////////////////////////

void setup() { 
  dht.begin();
  rtc.begin(); // Initialize the rtc object
  //rtc.setDate(day, mon, year);   // Set the date to  1st, 2016
  //rtc.setTime(hour ,min,sec);     // Set the time to 12:00:00 (24hr format)
   t = rtc.getTime();// Get data from the DS3231
  lcd.backlight();
  
  lcd.init();
}

void loop() {
//  int readDataM = dht.readData();
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  
  hour = t.hour; // the structure holds the info we want. the hours
  min = t.min; // and the minutes
  lcd.setCursor(0,0); // Sets the location at which subsequent text written to the LCD will be displayed
  lcd.print("Temp.: "); // Prints string "Temp." on the LCD
  lcd.print(t); // Prints the temperature value from the sensor
  lcd.print(" C");
  lcd.setCursor(0,1);
  lcd.print("Humi.: ");
  lcd.print(h);
  lcd.print(" %");
   
 lcd.setCursor(0,2);
 lcd.print("Time: ");
 lcd.print(rtc.getTimeStr());
 lcd.setCursor(0,3);
 lcd.print("Date: ");
 lcd.print(rtc.getDateStr());


  if (hourK== hour&& minK==min ) {
     lcd.setCursor(16,2);
     lcd.print("OK ");
   } else {
     lcd.setCursor(16,2);
     lcd.print("   "); // erase the OK in case it was there
   }
 

}

What is the reason??

 Time  t;
 float t = dht.readTemperature();

How many variables t do you have in your program? I see that you are a "newbie" but you should really try to read and understand your code before adding suggested snippets.

cattledog:

 Time  t;

float t = dht.readTemperature();




How many variables t do you have in your program? I see that you are a "newbie" but you should really try to read and understand your code before adding suggested snippets.

Hi cattledog
Yes I am newbie and I am here to learn, (so I ask your understanding) before posting anything here have already done several research to see if I can find the answer to my problem, but in this case not found anything that help me if and so I decided to ask for help here

The code is in the previous post you can see! but I do not understand why not compile the code

Fiasgardone:
... I do not understand why not compile the code

You have two variables named t. Maybe call the one that means temperature 'temp' (or temperature if you are not into the whole brevity thing.)

Sorry I did not check the rest of your code for the other variable named t.... change one of those..

Hello everyone!! Thanks for listening

Well, now the code compiles and runs, I thank everyone who helped and hopefully in the future when I have questions can count on your support.

Thank you