HEY everyone
I am working on my project with automatic controlled aquarium(lights and airpump).I read many topics on this forum about this but I can´t find the right code for me.
The whole thing is that the relay will start in the morning and turn them off in the evening.
I want to controlled two relays(first for lights and second for airpump).
I find some code and edit it in this:
#include <Time.h>
#include <TimeAlarms.h>
// Pins
#define RELAY1 2
#define RELAY2 3
void setup() {
// Start Serial & set pin to output
Serial.begin(9600);
//set relays
pinMode(RELAY1, OUTPUT);
pinMode(RELAY2, OUTPUT);
// start clock
setTime(18,00,00,7,1,17); // set time to 18:00 July 1 2017
// create the alarms
Alarm.alarmRepeat(22,00,00, RelayOff); // 22:00:00 every day
Alarm.alarmRepeat(05,30,00, LightsON); // 05:30:00 every day
Alarm.alarmRepeat(22,00,00, LightsOFF); // 22:00:30 every day
Alarm.alarmRepeat(06,00,00, AirPumpON); // 06:00:00 every day
Alarm.alarmRepeat(22,00,00, AirPumpOFF); // 22:00:00 every day
}
void loop() {
digitalClockDisplay();
Alarm.delay(1000);
}
//Relays OFF
void RelayOff(){
Serial.println("All Off");
digitalWrite(RELAY1,HIGH);
digitalWrite(RELAY2,HIGH);
}
void LightsON(){
Serial.println("Lights are ON");
digitalWrite(RELAY1,LOW);
}
void LightsOFF(){
Serial.println("Lights are OFF");
digitalWrite(RELAY1,HIGH);
}
void AirPumpON(){
Serial.println("AirPump is ON");
digitalWrite(RELAY2,LOW);
}
void AirPumpOFF(){
Serial.println("AirPump is OFF");
digitalWrite(RELAY2,HIGH);
}
void digitalClockDisplay()
{
// digital clock display of the time
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.println();
}
void printDigits(int digits)
{
Serial.print(":");
if(digits < 10)
Serial.print('0');
Serial.print(digits);
}
It´s work but i have some problems.
1.When I upload code and open Serial monitor the code started running from the beginning.
For example-the time from arduino are display on the serial monitor
18:00:01
18:00:02
18:00:03
18:00:04
18:00:05
...
I close and open serial monitor and the code started running from the beginning.
18:00:01
18:00:02
18:00:03
(but that is "ok".I will not open Serial monitor.Second problem is bigger)
2.I want to use my rtc(DS3231) with this(because i live on village and the electricial system are often "falls"(for a several minutes)).And the code started running from the beginning when I pull out usb cable(oder electrical system "falls")
I will be very happy when someone can help me ![]()
--Sorry for my bad english--
Thanks ![]()