hello guys ,
iam now currently building a aurdino project for automating my aquarium very simple stuff like
auto topoff
turning on light with relay
automated water change
i have really no idea about engineering and codes cause im a a doctor
i managed to scavenge codes from other projects and managed to build very basic code for the system and for now i managed to make the auto top off and light relay to work and also an rtc to work was a big headache …
now i am having problem with the auto top off code, i want the system to turn on at 12 everyday run for 3min. then shutdown itried using delay but it is causing the other systems to halt so can u guys guide me how to make it work
and also i want the auto top off pump to run for an extra 3 sec before it shuts down , heard about using mills. but really i dont know how to use it , dont want to use delay cause it is delaying everything , please help me out with this guys
thanks in advance!
#include "Wire.h"
#define DS1307_I2C_ADDRESS 0x68
////Convert normal decimal numbers to binary coded decimal.
byte decToBcd(byte val)
{
return ( (val/10*16) + (val%10) );
}
////Convert binary coded decimal to normal decimal numbers.
byte bcdToDec(byte val)
{
return ( (val/16*10) + (val%16) );
}
////Stops the clock, but it has the side effect of setting seconds to 0.
/*void stopDs1307()
{
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.write(0);
Wire.writeWire.writeWire.write(0x80);
Wire.endTransmission();
}*/
////1) Sets date and time on the clock.
////2) Starts the clock.
////3) Sets hour mode to 24 hours.
void setDateDs1307(
byte second, ////0-59
byte minute, ////0-59
byte hour, ////1-23
byte dayOfWeek, ////1-7
byte dayOfMonth, ////1-28/29/30/31
byte month, ////1-12
byte year) ////0-99
{
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.write(0);
Wire.write(decToBcd(second)); ////0 to bit 7 starts the clock
Wire.write(decToBcd(minute));
Wire.write(decToBcd(hour)); ////If you want 12 hours (am/pm) you need to set
////bit 6 (also need to change getDateDs1307)
Wire.write(decToBcd(dayOfWeek));
Wire.write(decToBcd(dayOfMonth));
Wire.write(decToBcd(month));
Wire.write(decToBcd(year));
Wire.endTransmission();
}
////Reads date and time from the clock,
void getDateDs1307(
byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
////Reset the register pointer.
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.write(0);
Wire.endTransmission();
Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
////A few of these need masks because certain bits are control bits.
*second = bcdToDec(Wire.read() & 0x7f);
*minute = bcdToDec(Wire.read());
*hour = bcdToDec(Wire.read() & 0x3f); ////Need to change this for 12 hours (am/pm)
*dayOfWeek = bcdToDec(Wire.read());
*dayOfMonth = bcdToDec(Wire.read());
*month = bcdToDec(Wire.read());
*year = bcdToDec(Wire.read());
}
////Define pump pin outs.
int flushpin = 2; //Pump 1 – Flourish Excel
int lightpin = 3; //Pump 2 – Flourish Iron
int flowerpump =4 ; //Pump 3 – Flourish
int plantpump = 5;
int flowersensor = 6;
int plantsensor = 7;
int reservoir = 8;
int actled = 13; //Status Led
void setup() ////One time run at each execution.
{
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
pinMode(flushpin, OUTPUT);
pinMode(lightpin, OUTPUT);
pinMode(flowerpump, OUTPUT);
pinMode(plantpump, OUTPUT);
pinMode(actled, OUTPUT);
pinMode(flowersensor, INPUT_PULLUP);
pinMode(plantsensor, INPUT_PULLUP);
pinMode(reservoir, INPUT_PULLUP);
Wire.begin();
Serial.begin(9600);
////Set date and time on the clock.
////You only need to run this the first time you setup your RTC.
////Set the correct value below and un comment it to run it.
/*
second = 00;
minute = 10;
hour = 15;
dayOfWeek = 1;
dayOfMonth = 19;
month = 6;
year = 16;
setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
*/
}
void loop()
{
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
if (hour >= 23 && hour < 9) {
digitalWrite(lightpin, HIGH);
}
else {
digitalWrite(lightpin, LOW);
}
if((digitalRead(reservoir) == HIGH)||(digitalRead(flowersensor) == HIGH))
{digitalWrite(flowerpump, HIGH);}
else
{digitalWrite(flowerpump, LOW);}
if((digitalRead(reservoir) == HIGH)||(digitalRead(plantsensor) == HIGH))
{digitalWrite(plantpump, HIGH);}
else
{digitalWrite(plantpump, LOW);}
if (hour=12)
{digitalWrite(flushpin, HIGH);}
else
{digitalWrite(flushpin, LOW);}
}