Hi all, how are you doing? I hope everything is doing good for you all. I'm pretty new here and at the programming world, though i have some prior knowledge. I'm creating a programm that will be responsible for activating and deactivating solenoid valves at the field, basically; an irrigation system. What happens here is that after a while my serial port stops refreshing continuously the time read from a RTC 1302 device and the information flow stops. The result: nothing more works. If i remove all the lines responsible for each valvle, it works again and if i re-write them, it works for a while and then it stops updating again. I've been searching through the web but haven't found anything about such problem. All the wiring is working good as the software works for a while. All i need to do is read the time and activate or deactivate the valves at a specific time.
#include <virtuabotixRTC.h>
virtuabotixRTC myRTC (12, 13, 7);
int V1HON = 16;
int V1MON = 22;
int V1HOFF = 16;
int V1MOFF = 23;
int relay1 = 2;
void Relay1 ();
void setup() {
Serial.begin (9600);
pinMode (relay1, OUTPUT);
//myRTC.setDS1302Time (40, 59, 23, 7, 28, 8, 2021);
// put your setup code here, to run once:
}
void loop() {
myRTC.updateTime ();
Serial.print("Data Atual / Hora Local: ");
Serial.print(myRTC.dayofmonth); //You can switch between day and month if you're using American system
Serial.print("/");
Serial.print(myRTC.month);
Serial.print("/");
Serial.print(myRTC.year);
Serial.print(" ");
if(myRTC.hours < 10) Serial.print("0");
Serial.print(myRTC.hours);
Serial.print(":");
if(myRTC.minutes < 10) Serial.print("0");
Serial.print(myRTC.minutes);
Serial.print(":");
if(myRTC.seconds < 10) Serial.print("0");
Serial.println(myRTC.seconds);
delay (1000);
do{
digitalWrite (relay1, HIGH);
}
while (((V1HON) != (myRTC.hours)) && (V1MON) != ((myRTC.minutes)));
if(((V1HON) == (myRTC.hours)) && (V1MON) == ((myRTC.minutes))){
Relay1();
}
}
void Relay1(){
digitalWrite (relay1, LOW);
}
The code is very simple and it works but i don't know what happens that the serial port stops updating the time values.
Best Regards,
EngDSS.