Thank you to DangerToMyself ... (hope all is good,
)
The relays I am have are responding to the RTC timers well, but I can't figure out how to make the serial display the status of the relays. Right now, the first relay (lights1) turns on and says 'on' in the serial. When the second relay (Lights2) turns on, it says on but the first relay serial goes blank.
I think there is something that I am just not seeing, because the system is essentially working well in terms of relays.
I think the problem is around line 149.
This project is an exercise in practicing how to monitor sensors and relays.
Having fun and thanking you all for your help.
#include <SimpleDHT.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h> // For I2C
#include <RTClib.h>
//Establishes pin for DHT11 sensor:
int pinDHT11 = 5;
SimpleDHT11 dht11;
//Establishes the pins for Lights relays..
int Lights1 = 6;
int Lights2 = 11;
//int Heater =
//int airpump =
//Establishes on & off times for Lights1
const int OnHour1 = 3; // Hour Value of Lights1 On Time (In 24 hour format)
const int OnMin1 = 57; // Minute Value of Lights1 On Time
const int OffHour1 = 3; // Hour Value of Lights1 Off Time (In 24 hour format)
const int OffMin1 = 59; // Minute Value of Lights1 On Time
//Establishes on & off times for Lights2
const int OnHour2 = 3; // Hour Value of Lights2 On Time (In 24 hour format)
const int OnMin2 = 58; // Minute Value of Lights2 On Time
const int OffHour2 = 4; // Hour Value of Lights2 Off Time (In 24 hour format)
const int OffMin2 = 0; // Minute Value of Lights2 On Time
RTC_DS1307 rtc;
//DS18b20:
#define ONE_WIRE_BUS 4
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
int deviceCount = 0;
float tempC;
LiquidCrystal_I2C lcd(0x27, 20, 4);
void setup() {
Serial.begin(9600);
sensors.begin();
lcd.init();
lcd.init();
lcd.backlight();
// Setting up Lights1 & Lights2 relay switches...
pinMode(Lights1, OUTPUT);
digitalWrite(Lights1, LOW);
pinMode(Lights2, OUTPUT);
digitalWrite(Lights2, LOW);
if(! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
else {
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
if(! rtc.isrunning()) {
Serial.println("RTC is NOT running!");
}
}
void loop()
{
Serial.println();
Serial.print("======================="); Serial.println();
Serial.print("|-.+.-.-.+.-.-.+.-.-.-|"); Serial.println();
Serial.print("|75 Gallon Paludarium:|"); Serial.println();
Serial.print("|||||||||||||||||||||||"); Serial.println();
Serial.print("======================="); Serial.println();
Serial.println();
DateTime now = rtc.now();
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(" | ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.println(now.second(), DEC);
//myFile.close();
byte temperature = 0;
byte humidity = 0;
byte data[40] = {0};
if (dht11.read(pinDHT11, &temperature, &humidity, data)) {
//Serial.print("Read DHT11 failed"); Serial.println();
sensors.requestTemperatures();
//Serial.println("");
}
//lcd.setCursor(0,0); lcd.print("75 Gallon Paludarium");
lcd.setCursor(0,0); lcd.print(now.year(), DEC);
lcd.setCursor(4,0); lcd.print("/");
lcd.setCursor(5,0); lcd.print(now.month(), DEC);
lcd.setCursor(7,0); lcd.print('/');
lcd.setCursor(8,0); lcd.print(now.day(), DEC);
lcd.setCursor(10,0); lcd.print(" | ");
lcd.setCursor(12,0); lcd.print(now.hour(), DEC);
lcd.setCursor(14,0); lcd.print(':');
lcd.setCursor(15,0); lcd.print(now.minute(), DEC);
lcd.setCursor(17,0); lcd.print(':');
lcd.setCursor(18,0); lcd.println(now.second(), DEC);
lcd.setCursor(0,1); lcd.print("Air:"); lcd.print(sensors.getTempCByIndex(1));
lcd.setCursor(11,1); lcd.print("RH%:"); lcd.print((int)humidity);
lcd.setCursor(0,2); lcd.print("h20:"); lcd.print(sensors.getTempCByIndex(0));
lcd.setCursor(11,2); lcd.print("LPH:");
lcd.setCursor(0,3); lcd.print("L1:"); if (Lights1, HIGH) { lcd.setCursor(3,3); lcd.print(" Off"); } else {(Lights1, LOW); lcd.print(" On"); }
lcd.setCursor(12,3); lcd.print("pH:");
Serial.println(".......................");
Serial.println();
Serial.print("Air Temperature: "); Serial.print(sensors.getTempCByIndex(0)); Serial.print("C"); Serial.println();
Serial.print("Relative Humidity: "); Serial.print((int)humidity); Serial.print("%"); Serial.println();
sensors.requestTemperatures();
Serial.print("H20 Temperature: "); Serial.print(sensors.getTempCByIndex(0)); Serial.print("C"); Serial.println();
Serial.print("Flow Rate:"); Serial.print((int)temperature); Serial.println(" Litres/hour"); //Serial.println();
Serial.print("Co2:"); Serial.println(" N/A");
Serial.print("Heater:"); Serial.println(" N/A");
Serial.print("Air Pumps:"); Serial.println(" N/A");
//trying this line... blurg...
Serial.print("Aquarium Light:");
if(now.hour() == OnHour1 && now.minute() == OnMin1)
{digitalWrite(Lights1, HIGH); Serial.print(" On");}
else if (now.hour() == OffHour1 && now.minute() == OffMin1)
{digitalWrite(Lights1, LOW); Serial.print(" Off");}
Serial.println();
/*
if (now.hour() == OnHour1 && now.minute() == OnMin1)
{
Serial.print(" On");}
else if (now.hour() == OffHour1 && now.minute() == OffMin1){
Serial.print(" Off");}*/
Serial.print("Sump Light:");
if(now.hour() == OnHour2 && now.minute() == OnMin2)
{digitalWrite(Lights2, HIGH); Serial.print(" On");}
else if (now.hour() == OffHour2 && now.minute() == OffMin2)
{digitalWrite(Lights2, LOW); Serial.print(" Off");}
Serial.println();
/*
if (now.hour() == OnHour2 && now.minute() == OnMin2)
{Serial.print(" On");}
else if (now.hour() == OffHour2 && now.minute() == OffMin2)
{Serial.print(" Off");} */
//Serial.print("Sump Light:"); if (Lights2, HIGH) { Serial.print(" Off"); } else if (Lights2, LOW) { Serial.print(" On"); } Serial.println();
Serial.print("Over Head:"); Serial.println(" N/A");
Serial.println();
Serial.print(".......................");
Serial.println();
//if(now.hour() == OnHour1 && now.minute() == OnMin1) {digitalWrite(Lights1, HIGH); }
//else if (now.hour() == OffHour1 && now.minute() == OffMin1) {digitalWrite(Lights1, LOW);}
//if(now.hour() == OnHour2 && now.minute() == OnMin2) {digitalWrite(Lights2, HIGH); }
//else if (now.hour() == OffHour2 && now.minute() == OffMin2) {digitalWrite(Lights2, LOW);}
delay(5000);
}