Got it!!! THANK YOU
the code works fine this is the updated!
#include <DHT.h> // Air Temp Humid Sensor
#include <OneWire.h>
#include <DallasTemperature.h> // Water Temp Sensor
#include <LiquidCrystal_I2C.h>
#include <Wire.h> // enables uno SCL SDL pins
#include <DS3231.h> // RTC
const int lightingPin = 8;
const int fanPin= 12;
int fanMode = 0;
int cycleState =0;
int val =0;
int ph_pin = A3; // Analoge input from ph sensor pin Po
unsigned long currentTime;
unsigned long previousTime = 0;
int marker = 0;
DS3231 clock;
RTCDateTime dt; // dt get date time
int alarmState = 0;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Lcd Display ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// set the LCD address to 0x3F for a 16 chars 2 line display
// Set the pins on the I2C chip used for LCD connections:
// addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Air Temperature & Humidity sensor ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#define DHTPIN 2 // what pin we're connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor
int chk;
float hum; //Stores humidity value
float temp; //Stores temperature value
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Water Temperature sensor ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#define ONE_WIRE_BUS 7
// Setup a oneWire instance to communicate with any OneWire devices
// (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
//################################################################# SETUP #################################################################################################
void setup()
{
Serial.begin(9600);
lcd.begin(16,2); // initialize the lcd for 16 chars 2 lines, turn on backlight
lcd.backlight(); // Turns backlight LCD on
Wire.begin(); // enables uno SCL SDL pins
sensors.begin(); // water temp sensor
pinMode(lightingPin, OUTPUT);
digitalWrite (lightingPin, LOW);
clock.begin(); // Initialize DS3231
clock.getDateTime(); // get the Time and Date
dht.begin(); // temp humid sensor
pinMode (fanPin, OUTPUT);
digitalWrite (fanPin, HIGH);
clock.armAlarm1(false);
clock.clearAlarm1();
clock.armAlarm2(false);
clock.clearAlarm2();
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Real time clock Settings ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//clock.setDateTime(2017, 4, 10, 07, 58, 0); // Set date/time (Year, Month, Day, Hour, Minute, Second) "//" Out if clock is already set
//~~~~~~~~~~~~~~~~~~~~~~~~~Alarm Timer Settings "Dont forget up update DAY/NIGHT SET TIMES in loop for quick reference ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Dont forget to update alarmState as lighting failsafe ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
clock.setAlarm1(0, 05, 00, 00, DS3231_MATCH_H_M_S); // Set Alarm 1 time and date
clock.setAlarm2(0,23, 00, DS3231_MATCH_H_M); // Set Alarm 2 time and date
checkAlarms(); // Check alarm settings
}
void checkAlarms() {
RTCAlarmTime a1;
RTCAlarmTime a2;
if (clock.isArmed1()){
a1 = clock.getAlarm1();
Serial.print("Alarm1 is triggered ");
switch (clock.getAlarmType1()) {
case DS3231_MATCH_H_M_S:
Serial.print("when hours, minutes and seconds match: ");
Serial.println(clock.dateFormat("__ H:i:s", a1));
break;
}
}
else {
Serial.println("Alarm1 is disarmed.");
}
if (clock.isArmed2()) {
a2 = clock.getAlarm2();
Serial.print("Alarm2 is triggered ");
switch (clock.getAlarmType2())
{
case DS3231_MATCH_H_M:
Serial.print("when hours and minutes match:");
Serial.println(clock.dateFormat("__ H:i:s", a2));
break;
}
}
else {
Serial.println("Alarm2 is disarmed.");
}
}
//########################################################################## LOOP ###################################################################################################
void loop(){
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ OUTPUT REAL TIME CLOCK ON SERIAL ~~~~~~~~~~~~~~~~~~~~~~~~~~
dt = clock.getDateTime();
Serial.println(clock.dateFormat("d-m-Y H:i:s - l", dt));
{
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ALARM RELAY ACTION ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alarmState = dt.hour*60 + dt.minute;
// take the hours in 24 hour clock and times the hour by 60 then add the minutes so 2:15am will be (2*60+15=135)
if (alarmState >= 300 && alarmState < 1380){
digitalWrite (lightingPin, HIGH);
}
if (alarmState >= 1380 && alarmState < 300){
digitalWrite (lightingPin, LOW);
}
if(clock.isAlarm1()) {
Serial.println("ALARM 1 TRIGGERED!");
digitalWrite (lightingPin, HIGH);
}
if(clock.isAlarm2()) {
Serial.println("ALARM 2 TRIGGERED!");
digitalWrite (lightingPin, LOW);
}
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Fan Mode ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fanMode = digitalRead (fanPin);
if (temp <24)
{
Serial.println ("Fan OFF");
digitalWrite (fanPin, HIGH);
}
else if (temp >=24)
{
Serial.println ("Fan On");
digitalWrite (fanPin, LOW);
}
if (temp >=28)
{
digitalWrite (lightingPin, LOW);
Serial.print ("WARNING TENT OVERHEAT");
}
once again thank you for all your help ;D