Good Evening All!
I am having some issues troubleshooting an issue I’m having with a microclimate controller I’m building and was hoping somebody here might take a crack at it!
This project is running on a Mega2650 board I have and a prototype shield with a DS3231 RTC module and DHT11 Humidity/Temp sensor. These two will hopefully control a 4 Relay shield I have wired in. The code so far is designed to activate my #2 relay for the first 5 minutes of every hour, and activate the #3 relay from 5am to 5pm. I want to set this up so that it will also activate the first relay under the condition that the DHT11 reads <90% RH. Everything compiles so far but It seems to be glitching somewhere. Regardless of time, the #2 relay stays active and nothing else will some on or go off.
Code is as follows
#include <DS3231.h>
#include <Wire.h>
const int RELAY1 = 4;
const int RELAY2 = 5;
const int RELAY3 = 6;
const int RELAY4 = 7;
DS3231 Clock;
bool Century = false;
bool h12;
bool PM;
byte ADay, AHour, AMinute, ASecond, ABits;
bool ADy, A12h, Apm;
byte year, month, date, DoW, hour, minute, second;
void setup() {
// Start I2C interface
Wire.begin();
Clock.setSecond(00);//Set the second
Clock.setMinute(53);//Set the minute
Clock.setHour(18); //Set the hour
Clock.setDoW(7); //Set the day of the week
Clock.setDate(20); //Set the date of the month
Clock.setMonth(2); //Set the month of the year
Clock.setYear(16); //Set the year (Last two digits of the year)
Serial.begin(115200);
}
void ReadDS3231()
{
// Initialize variables for time
int second, minute, hour, date, month, year, temperature;
second = Clock.getSecond();
minute = Clock.getMinute();
hour = Clock.getHour(h12, PM);
date = Clock.getDate();
month = Clock.getMonth(Century);
year = Clock.getYear();
// Print time
Serial.print("20");
Serial.print(year, DEC);
Serial.print('-');
Serial.print(month, DEC);
Serial.print('-');
Serial.print(date, DEC);
Serial.print(' ');
Serial.print(hour, DEC);
Serial.print(':');
Serial.print(minute, DEC);
Serial.print(':');
Serial.print(second, DEC);
Serial.print('\n');
}
void loop() {
ReadDS3231();
delay(1000);
// Turn on relay for the first 5 minutes of the hour
// Sets fan interval for FRESH AIR EXCHANGE
if ( minute >= 0 && minute < 5 )
{
digitalWrite ( RELAY2, HIGH );
}
else
{
digitalWrite ( RELAY2, LOW );
}
if ( hour >= 5 && hour < 17 )
{
digitalWrite ( RELAY3, HIGH );
}
else
{
digitalWrite ( RELAY3, LOW );
}
}