Part 1
#include <Wire.h>
#include "RTClib.h"
#include "Time.h"
#include "TimeAlarms.h"
#include <dht11.h>
#define RELAY1 7 // Setup and Define the Relays
#define RELAY2 8
#define RELAY3 9
#define RELAY4 10
#define DHT11PIN 6 // Pin 6 for the DHT
int dialone = 11; // Analogue Dial Connected to digital pin 11 - Temp
int dialtwo = 5; // Analogue Dial Connected to digital pin 5 - Light
int dialthree = 3; // Analogue Dial Connected to digital pin 3 - Stats
int pushButton = 13; // Digital Button Connected to digital pin 13 - Light Swap
int lightstate = 0; // Light state for advance and reset
int lastlight = 0; // Last light setting used
int powerled = 2; // Yellow Power LED Connected to digital pin 2
int pin = 0; // Analog pin for Temp
int tempc = 0;// Temperature variable in C
int samples[8]; // variables to make a better precision
int tempi; // Increment variable for temp taking
int htemp = 0; // value of hood temp
int hhume = 0; // value of hood humidity
int hoodcheck = 0; // value to hold hood check value, is it hot or humid (temp)
int hoodfan =0; // Is the fan on or off. 1 On 0 Off
RTC_DS1307 RTC; // RTC call
dht11 DHT11; // DHT11 call
void setup()
{
// Initialise the Arduino data pins for Relay OUTPUT
pinMode(RELAY1, OUTPUT);
pinMode(RELAY2, OUTPUT);
pinMode(RELAY3, OUTPUT);
pinMode(RELAY4, OUTPUT);
// Initialise the Power LED for OUTPUT
pinMode(powerled, OUTPUT);
//pinMode(buttonPin, INPUT);
Serial.begin(9600); // start serial communication for logging to PC
pinMode(pushButton, INPUT); // Set Button to an Input
// Starts the sets thr RTC Real Time Clock
RTC.begin();
Wire.begin();
if (! RTC.isrunning()) {
Serial.println("RTC is NOT running!");
RTC.adjust(DateTime(__DATE__, __TIME__)); // Sets the RTC to the date & time this sketch was compiled
}
DateTime now = RTC.now();
setTime(hour(), minute(), second(), day(), month(), year());
setTime(now.hour(),now.minute(),now.second(),now.day(),now.month(),now.year());
// Relay Time Controls ---------->
RelaySet(); // Reset Relays Off Procedure Call
// Times on and off settings : (arduino lost 1.5 hours)
//Royal Blue ON
Alarm.alarmRepeat(9,30,0, LightBlue); // 10:00am Turn Blue Lights On & Turn Dial2 to Blue
// White ON
Alarm.alarmRepeat(9,30,0, LightWhite); // 11:00am Turn White Lights On & urn Dial2 to White
// White OFF
Alarm.alarmRepeat(18,30,0, LightBlue); // 8:00pm Turn White Lights Off & Turn Dial2 to Blue
// Royal Blue OFF
Alarm.alarmRepeat(20,30,30, LightOff); // 10:00pm Turn Blue Lights Off & Turn Dial2 to Zero
// Dose NoPoX
Alarm.alarmRepeat(13,00,00, Relay3ON); // 11:00pm Turn Dosing Pump On
Alarm.alarmRepeat(13,03,00, Relay3OFF); // 11:01pm Turn Dosing Pump Off
Alarm.alarmRepeat(13,00,00, DialDose); // 11:00pm Turn Dial3 to Dose
Alarm.alarmRepeat(13,03,00, DialDoseSet); // 11:01pm Turn Dial2 to Zero and Dial 3 back to Fan status
}
void loop()
{
// *****************************----------------------------------------------------------------------------------
// Print Time out for Serial port logs
// *****************************
DateTime now = RTC.now();
setTime(now.hour(),now.minute(),now.second(),now.day(),now.month(),now.year());
Serial.print("Arduino Time : ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
// *****************************----------------------------------------------------------------------------------
// Light Manual Button Control
// *****************************
int buttonState = digitalRead(pushButton); // read the input pin for button state:
Serial.print("Button State : ");
Serial.println(buttonState); // print out the state of the button:
Serial.print("Light State : ");
Serial.println(lightstate); // print out the light state number:
if (buttonState == 1) // If the buttom is pressed change light state number from 0 to 3
{
if (lightstate == 4)
{
lightstate = 0;
}
else
{
lightstate = (lightstate+1);
}
}
// *****************************----------------------------------------------------------------------------------
// Light State Control
// *****************************
// lightstate 0 is Off
// lightstate 1 is Blue Only
// lightstate 2 is Blue & White
// lightstate 3 is White (Not used in Time setting)
if (lightstate == 0)
{
if (lastlight != 0)
{
Relay1OFF(); //White Lights Off
Relay2OFF(); //Blue Lights Off
DialSet(); //Turn Dial2 to Off
lastlight = 0;
}
}
if (lightstate == 1)
{
if (lastlight != 1)
{
Relay2ON(); //Turn Blue Lights On
Relay1OFF(); //White Lights Off
DialBlue(); //Turn Dial2 to Blue
lastlight = 1;
}
}
if (lightstate == 2)
{
if (lastlight != 2)
{
Relay2ON(); //Turn Blue Lights On
Relay1ON(); //Turn White Lights On
DialWhite(); //Turn Dial2 to White
lastlight = 2;
}
}
if (lightstate == 3) // Only used as a Manual setting
{
if (lastlight != 3)
{
Relay1ON(); //White Lights Off
Relay2OFF(); //Blue Lights Off
DialSet(); //Turn Dial2 to Off
lastlight = 3;
}
}
// *****************************----------------------------------------------------------------------------------
// LED Control
// *****************************
digitalWrite(powerled, HIGH); // turn the LED on (HIGH is the voltage level)
Alarm.delay(0); // Alarm Script needs this delay call even if 0