Hey everyone! I've been on here for help before and I'm making a lot of progress for a beginner. Now I'm stuck on the RTC module and having things on a schedule. I need to have relay 1 activate for 12 hours starting at 0700. The programming says 1900 because I'm actively trying to get it to work. The problem is, I don't think it's recognizing what I'm telling it. I'm honestly not sure how to word the "if" statement. Any and all help is greatly appreciated. Thank you!
/*
Godzilla monitor v1. Monitor temperature and humidity with 2x DHT22's. Temperature parameters are >75 <90*F.
Humidity parameters are >40 <60%. Humidity is controlled by a submersible waterpump that activates when humidity falls
below 40%, connected to an IoT relay, should only need 1 relay switch. A UVB light is also connected to an IoT and will
cycle between 12hrs on / 12hrs off, should also need 1 relay switch here as well. Temperature and humidity will be
displayed on a 16x2 LCD. A red LED will illuminate when temp or humidity is out of parameters. A blue LED will
illuminate when the water pump is active. A green LED will illuminate when a relay is activated.
-Eventually I want to connect it to the internet, possibly a different arduino board.
*/
#include <DHT.h>
#include <LiquidCrystal.h>
#include <I2C_RTC.h>
#include <time.h>
static DS3231 RTC;
//DHT11 signal pin
#define DHT_1 dht_1(2);
#define DHT_2 dht_2(3);
//Type of DHT
DHT dht_1(2, DHT22);
DHT dht_2(3, DHT22);
//LED pins
//RED DHT1-32
//RED DHT2-33
//Yellow DHT1-34
//Yellow DHT2-35
//BLUE-36
//GREEN-31
//GREEN-30
//LCD signal pins
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 13, en = 12, d4 = 5, d5 = 6, d6 = 7, d7 = 8;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
Serial.begin(9600);
//starting various things
//RTC Starting - MUST change time and day if changing program
RTC.begin();
RTC.setHourMode(CLOCK_H24);
RTC.setDate(8,10,24);
RTC.setTime(19,16,30);
//DHTs Starting
dht_1.begin();
dht_2.begin();
//LCD Start
lcd.begin(16, 1);
// Print a message to the LCD.
lcd.print("Godzilla's House");
delay(3000);
lcd.clear();
lcd.println("Since Apr30,2024");
delay(3000);
lcd.clear();
}
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(16, 1);
//RTC calling date and time
switch (RTC.getWeek());
Serial.print(RTC.getHours());
Serial.print(":");
Serial.print(RTC.getMinutes());
Serial.print(":");
Serial.print(RTC.getSeconds());
Serial.print(" ");
RTC.startClock();
Serial.println("Monitoring");
//This is DHT_1
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht_1.readHumidity();
// Read temperature as Celsius (the default)
float t = dht_1.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht_1.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println(F("Failed to read from DHT_1!"));
lcd.println(F("Failed to read from DHT_1!"));
return;
}
Serial.print(F("Hum: "));
Serial.print(h);
Serial.print(F("% Temp: "));
Serial.print(f);
Serial.print(F("°F"));
lcd.print(F("Hum: "));
lcd.print(F("% Temp: "));
lcd.print(F("°F"));
delay(600);
//This is DHT_2
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h2 = dht_2.readHumidity();
// Read temperature as Celsius (the default)
float t2 = dht_2.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f2 = dht_2.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println(F("Failed to read from DHT_2!"));
lcd.println(F("Failed to read from DHT_2!"));
return;
}
Serial.print(F("Hum: "));
Serial.print(h2);
Serial.print(F("% Temp: "));
Serial.print(f2);
Serial.print(F("°F"));
//If temp above 73 on DHT1/2 turn on Red LEDs
if (dht_1.readTemperature(); f < 75.00, f > 90.00) digitalWrite(32, HIGH);
else digitalWrite(32, LOW);
if (dht_2.readTemperature(); f2 < 75.00, f2 > 90.00) digitalWrite(33, HIGH);
else digitalWrite(33, LOW);
//added lcd write for temp high
if (dht_1.readTemperature(); f < 75.00, f > 90.00)
Serial.write("Temp High");
lcd.write("Temp High");
if (dht_2.readTemperature(); f < 75.00, f > 90.00)
Serial.write("Temp High");
lcd.write("Temp High");
delay(600);
//IF Humidity below 40% turn on Yellow LEDs
if (dht_1.readHumidity(); h < 40, h > 60) digitalWrite(34, HIGH);
else digitalWrite(34, LOW);
if (dht_2.readHumidity(); h2 < 40, h2 > 60) digitalWrite(35, HIGH);
else digitalWrite(35, LOW);
//Added lcd write for humidity high
if (dht_1.readHumidity(); h < 40, f > 60)
Serial.write("Humidity High");
lcd.write("Humidity High");
if (dht_2.readHumidity(); h < 40, f > 60)
Serial.write("Humidity High");
lcd.write("Humidity High");
//Relay 1 for UVB light, 12hrs on, 12hrs off, 2 green LEDs show when active
//12hrs in milliseconds: 43200000 ms
if (RTC.getHours() >= 1900)
digitalWrite(30, HIGH);
else if (RTC.getHours() >= 1917)
digitalWrite(30, LOW);
//delay(600);
//digitalWrite(30, HIGH);
//delay(600);
//digitalWrite(30, LOW);
//Relay 2
digitalWrite(31, HIGH);
delay(50);
digitalWrite(31, LOW);
delay(1000);
//digitalWrite(31, LOW);
//Waterpump operation - Change parameters before going LIVE, currently set-up for testing
if (h < 40, h2 < 40){
digitalWrite(40, HIGH);
digitalWrite(36, HIGH);
}
else if (h >= 60, h2 >= 60) {
(digitalWrite(40, LOW));
digitalWrite(36, LOW);
return;
}
}
//if (h2 < 3); digitalWrite(40, HIGH);
// }else digitalWrite(40, LOW);
//if (digitalWrite(40,HIGH), digitalWrite(40, HIGH);
// }else digitalWrite(36, LOW);