Me and a friend are working on building a fully automatic greenhouse with arduino. We use relais for highly powered stuff like fans and the pump. We have 3 relais, 2 servo's and a RTC module. But whenever we boot the arduino up, the RTC seemingly randomly resets. We think it has something to do with the pump because when we don't plug the pump in, it works just fine. The RTC we use is the ds1302. The arduino used is the arduino uno (non-chinese ripoff, the original). The power for the pump is from a usb-splitter, not from the arduino. This is the code. Don't think that's the problem, but it may be:
#include <virtuabotixRTC.h>
#include <Servo.h>
bool lightVar = false;
bool extravar = false;
virtuabotixRTC myRTC(A4, 8, 9);
Servo ServoOut;
Servo ServoIn;
void setup() {
ServoOut.attach(10);
ServoIn.attach(10);
Serial.begin(9600);
// seconds, minutes, hours, day of the week, day of the month, month, year
myRTC.setDS1302Time(0, 0, 0, 7, 23, 5, 2021);
for (int i = 2; i < 6; i++) {
pinMode(i, OUTPUT);
}
}
void loop() {
digitalWrite(3, LOW);
myRTC.updateTime();
Serial.print("Seconds:");
Serial.println(myRTC.seconds);
Serial.print("Minutes:");
Serial.println(myRTC.minutes);
Serial.print("Hours:");
Serial.println(myRTC.hours);
delay(200);
Pump();
// Light();
// Air();
}
//pin 4
void Pump() {
if (myRTC.seconds < 25 && myRTC.minutes == 0) {
digitalWrite(4, !lightVar);
} else {
digitalWrite(4, LOW);
}
}
//pin 3
void Light() {
if (myRTC.hours >= 22 && myRTC.minutes >= 30) {
lightVar = true;
} else if (myRTC.hours >= 23 || myRTC.hours <= 8) {
lightVar = true;
} else {
lightVar = false;
}
digitalWrite(3, lightVar);
}
//pin 5
void Air() {
if (myRTC.minutes < 5) {
ServoOut.write(170);
ServoIn.write(170);
digitalWrite(5, !lightVar);
} else {
ServoOut.write(10);
ServoIn.write(10);
digitalWrite(5, LOW);
}
}
Already thanks in regard,
MokerDikkeKloteKoter