i am a noob to code and have been trying to write a code for a aquarium controller. so far i think things are going ok but i cant get the lights to turn on at a set time. it has somethig to do with the “if” statement as far as i can tell but i am not sure.here is a list of what i have and the code i have so far.
mega 2560
tiny rtc 12c (like this http://www.rcmodelpart.com/i2c-ds1307-r … _p314.html)
an 8 relay module (http://www.sainsmart.com/8-channel-dc-5 … logic.html)
2 pc fans
float switch
code:
//waysifs aquarium
#include <DS1307.h>
#include "Wire.h"
#define DS1307_ADDRESS 0x68
byte zero = 0x00; //workaround for issue #527
/*
pin layout
Digital Pin rx0 0 =
Digital Pin tx0 1 =
Digital Pin 2 = relay 1 (dusk/dawn white leds)
Digital Pin 3 = relay 2 (daylight leds)
Digital Pin 4 = relay 3 (moonlight leds)
Digital Pin 5 = relay 4 (auto topoff pump)
Digital Pin 6 = relay 5 ()
Digital Pin 7 = relay 6 ()
Digital Pin 8 = relay 7 ()
Digital Pin 9 = relay 8 (cfl day lights)
Digital Pin 10 = hood fan
Digital Pin 11 = sump fan
Digital Pin 12 = auto topoff sensor (ato)
Digital Pin 20SDA = rtc SDA
Digital Pin 21SCL = rtc SCL
*/
int hood_fan = 10; //hod fan pin 10
int sump_fan = 12; // sump fan pin 12
int dusk_dawn = 2; //dusk/dawn pin 2
int day_light = 3; //daylights pin 3
int cfl_light = 9; // cfl lights pin 9
int moon_light = 4; //moon lights pin 4
int ato_pump = 5; //auto top off pump pin 5
int dusk_dawn_on_time = 8; //Turn dusk_dawn lights on at this time military time
int dusk_dawn_off_time = 20; //Turn dusk-dawn lights off at this time
int day_light_on_time = 9; // turn day lights on at this time
int day_lights_off_time = 20; //turn day lights off at this time
int cfl_light_on_time = 10; // turn cfls on at this time
int cfl_light_off_time = 19; //turn cfls off at this time
int moonl_on_time = 20; //Turn on moon lights at this time
int moonl_off_time = 90; //Turn off moon lights at this time
int second = bcdToDec(Wire.read());
int minute = bcdToDec(Wire.read());
int hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
int weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
int monthDay = bcdToDec(Wire.read());
int month = bcdToDec(Wire.read());
int year = bcdToDec(Wire.read());
int High = 0;
int Low = 10000;
void setup(){
Wire.begin();
Serial.begin(9600);
pinMode (dusk_dawn, OUTPUT); //pin 2 output
pinMode (day_light, OUTPUT); //pin 3 output
pinMode (cfl_light, OUTPUT); //pin 9 output
pinMode (moon_light, OUTPUT); //pin 4 output
pinMode (ato_pump, OUTPUT); //pin 5 output
pinMode (hood_fan, OUTPUT); //pin 10 output
pinMode (sump_fan, OUTPUT); // pin 11 output
//pinMode (ato_sensor, INPUT); // pin 12 float sensor
}
void loop (){
printDate();
delay(1000);
}
void setDateTime(){
byte second = 45; //0-59
byte minute = 40; //0-59
byte hour = 0; //0-23
byte weekDay = 2; //1-7
byte monthDay = 1; //1-31
byte month = 3; //1-12
byte year = 11; //0-99
Wire.beginTransmission(DS1307_ADDRESS);
Wire.write(zero); //stop Oscillator
Wire.write(decToBcd(second));
Wire.write(decToBcd(minute));
Wire.write(decToBcd(hour));
Wire.write(decToBcd(weekDay));
Wire.write(decToBcd(monthDay));
Wire.write(decToBcd(month));
Wire.write(decToBcd(year));
Wire.write(zero); //start
Wire.endTransmission();
}
byte decToBcd(byte val){
// Convert normal decimal numbers to binary coded decimal
return ( (val/10*16) + (val%10) );
}
byte bcdToDec(byte val) {
// Convert binary coded decimal to normal decimal numbers
return ( (val/16*10) + (val%16) );
}
void printDate(){
// Reset the register pointer
Wire.beginTransmission(DS1307_ADDRESS);
Wire.write(zero);
Wire.endTransmission();
Wire.requestFrom(DS1307_ADDRESS, 7);
//print the date EG 3/1/11 23:59:59
Serial.print(month);
Serial.print("/");
Serial.print(monthDay);
Serial.print("/");
Serial.print(year);
Serial.print(" ");
Serial.print(hour);
Serial.print(":");
Serial.print(minute);
Serial.print(":");
Serial.println(second);
}
//dusk_dawn lights
if (dusk_dawn_on_time) >= hour && <= (dusk_dawn_off_time){
digitalWrite(dusk_dawn, High);
}
else {
digitalWrite(dusk_dawn, Low);
}
//day_lights
if(day_light_on_time) >= hour && <= (day_light_off_time){
digitalWrite(day_light, High)
}
else {
digitalWrite(day_light, Low)
}
//cfl_light
if (cfl_light_on_time >= hour && <= cfl_light_off_time){
digitalWrite(cfl_light, High)
}
else{
digitalWrite(cfl_light, Low)
}
//moon_light
//ato pump
//hood fan
…
any help would be greatly appreciated
cheers
waysif
//sump fan