@alto777 I will thnx,
Follow up:
Guys I spend the afternoon figuring out how to set a specific time to a relay. And I am sure it is easy. But I don't get it right and I don't find the right example.
This is the code I came up with. (see down below)
I am messing with these lines.
DateTime now = rtc.now();
t = DateTime();
Serial.print(t.hour);
Serial.print(" hour(s), ");
Serial.print(t.min);
Serial.print(" minute(s)");
Serial.println(" ");
delay (1000);
if(t.hour == OnHour && t.min == OnMin){
it is on and of with all kind of errors.
I think this t in t.hour must be defined in one way. And this example comes from somebody who uses the ds3231.h library
So I allready found out.. you have to set it to:
RTC_DS3231 rtc;
DateTime t;
And he is using the command: t = rtc.getTime(); before Serial.print(t.hour)
But that one didn't work either, so I found the rtc.now() is working... at least working? It doesn't show an error.. ..
Probably there is again a much easier way to do things... And I am open for suggestions
Just trying to learn.
Current error:
/usr/local/bin/arduino-cli compile --fqbn arduino:avr:uno --libraries /home/builder/opt/libraries/latest --build-cache-path /tmp --output-dir /tmp/873723759/build --build-path /tmp/arduino-build-2726D92D2A6DEDCB60FEA3C1D826D46E --library /mnt/create-efs/webide/d7/bc/d7bcb425b103b8f19b6b2212ece2edc8:b-art86/libraries_v2/DallasTemperature --library /mnt/create-efs/webide/d7/bc/d7bcb425b103b8f19b6b2212ece2edc8:b-art86/libraries_v2/LiquidCrystal I2C --library /mnt/create-efs/webide/d7/bc/d7bcb425b103b8f19b6b2212ece2edc8:b-art86/libraries_v2/OneWire --library /mnt/create-efs/webide/d7/bc/d7bcb425b103b8f19b6b2212ece2edc8:b-art86/libraries_v2/RTClib --library /mnt/create-efs/webide/d7/bc/d7bcb425b103b8f19b6b2212ece2edc8:b-art86/libraries_v2/SimpleAlarmClock /tmp/873723759/Succes_2_sensors_copy
Using library adafruit_busio_1_11_6 at version 1.11.6 in folder: /home/builder/opt/libraries/adafruit_busio_1_11_6
Using library SPI at version 1.0 in folder: /home/builder/.arduino15/packages/arduino/hardware/avr/1.8.4/libraries/SPI
/tmp/873723759/Succes_2_sensors_copy/Succes_2_sensors_copy.ino: In function 'void loop()':
/tmp/873723759/Succes_2_sensors_copy/Succes_2_sensors_copy.ino:83:22: error: invalid use of non-static member function 'uint8_t DateTime::hour() const'
Serial.print(t.hour);
^
In file included from /tmp/873723759/Succes_2_sensors_copy/Succes_2_sensors_copy.ino:6:0:
/mnt/create-efs/webide/d7/bc/d7bcb425b103b8f19b6b2212ece2edc8:b-art86/libraries_v2/RTClib/src/RTClib.h:174:11: note: declared here
uint8_t hour() const { return hh; }
^~~~
/tmp/873723759/Succes_2_sensors_copy/Succes_2_sensors_copy.ino:85:18: error: 'class DateTime' has no member named 'min'
Serial.print(t.min);
^~~
/tmp/873723759/Succes_2_sensors_copy/Succes_2_sensors_copy.ino:90:8: error: invalid use of member function 'uint8_t DateTime::hour() const' (did you forget the '()' ?)
if(t.hour == OnHour && t.min == OnMin){
~~^~~~
/tmp/873723759/Succes_2_sensors_copy/Succes_2_sensors_copy.ino:90:28: error: 'class DateTime' has no member named 'min'
if(t.hour == OnHour && t.min == OnMin){
^~~
/tmp/873723759/Succes_2_sensors_copy/Succes_2_sensors_copy.ino:93:15: error: invalid use of member function 'uint8_t DateTime::hour() const' (did you forget the '()' ?)
else if(t.hour == OffHour && t.min == OffMin){
~~^~~~
/tmp/873723759/Succes_2_sensors_copy/Succes_2_sensors_copy.ino:93:36: error: 'class DateTime' has no member named 'min'
else if(t.hour == OffHour && t.min == OffMin){
^~~
/tmp/873723759/Succes_2_sensors_copy/Succes_2_sensors_copy.ino:102:10: error: 'digtialRead' was not declared in this scope
else(digtialRead(switchPin1) == LOW){
^~~~~~~~~~~
/tmp/873723759/Succes_2_sensors_copy/Succes_2_sensors_copy.ino:102:10: note: suggested alternative: 'digitalRead'
else(digtialRead(switchPin1) == LOW){
^~~~~~~~~~~
digitalRead
/tmp/873723759/Succes_2_sensors_copy/Succes_2_sensors_copy.ino:111:8: error: 'digtialRead' was not declared in this scope
else(digtialRead(switchPin2) == LOW){
^~~~~~~~~~~
/tmp/873723759/Succes_2_sensors_copy/Succes_2_sensors_copy.ino:111:8: note: suggested alternative: 'digitalRead'
else(digtialRead(switchPin2) == LOW){
^~~~~~~~~~~
digitalRead
Error during build: exit status 1
code:
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
#include <LiquidCrystal_I2C.h>
#include "RTClib.h"
#define RELAY1 8
#define RELAY2 12
int switchPin1 = 7;
int switchPin2 = 4;
OneWire ds(2);
RTC_DS3231 rtc;
DateTime t;
DallasTemperature sensors(&oneWire);
LiquidCrystal_I2C lcd(0x27, 16, 2);
const int OnHour = 06; //SET TIME TO ON RELAY (24 HOUR FORMAT)
const int OnMin = 30;
const int OffHour = 06; //SET TIME TO OFF RELAY
const int OffMin = 55;
void setup()
{
sensors.begin();
Serial.begin(9600);
rtc.begin();
// lcd.begin();
lcd.init ();
lcd.clear();
lcd.backlight();
pinMode(switchPin1, INPUT);
pinMode(switchPin2, INPUT);
pinMode(RELAY1, OUTPUT);
digitalWrite(RELAY1, LOW);
pinMode(RELAY2, OUTPUT);
digitalWrite(RELAY2, LOW);
}
void loop()
{
sensors.requestTemperatures();
float temp1C = sensors.getTempCByIndex(0);
float temp2C = sensors.getTempCByIndex(1);
int tempC = (int)(temp1C + temp2C) / 2;
Serial.println("==================");
Serial.println(tempC);
//-----------------
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Temperature:");
lcd.setCursor(0, 1);
lcd.print("C:");
lcd.setCursor(2, 1);
lcd.print(sensors.getTempCByIndex(0));
lcd.setCursor(10,1);
lcd.print(sensors.getTempCByIndex(1));
if (tempC > 21)
{
digitalWrite(RELAY1, HIGH);
lcd.setCursor(13,0);
lcd.print("ON");
} else{
digitalWrite(RELAY1,LOW);
lcd.setCursor(13,0);
lcd.print("OFF");
}
delay(2000);
DateTime now = rtc.now();
t = DateTime();
Serial.print(t.hour);
Serial.print(" hour(s), ");
Serial.print(t.min);
Serial.print(" minute(s)");
Serial.println(" ");
delay (1000);
if(t.hour == OnHour && t.min == OnMin){
digitalWrite(RELAY2,HIGH);
}
else if(t.hour == OffHour && t.min == OffMin){
digitalWrite(RELAY2,LOW);
}
if(digitalRead(switchPin1) == HIGH){
digitalWrite(RELAY1, HIGH);
lcd.setCursor(13,0);
lcd.print("ON");
}
else(digtialRead(switchPin1) == LOW){
digitalWrite(RELAY1, LOW);
lcd.setCursor(13,0);
lcd.print("OFF");
}
if(digitalRead(switchPin2) == HIGH){
digitalWrite(RELAY2, HIGH);
}
else(digtialRead(switchPin2) == LOW){
digitalWrite(RELAY2, LOW);
}
}