1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
#include <Wire.h>
#include "DS1307.h"
DS1307 clock;//define a object of DS1307 class
const int SOLENOID = 13;
void setup() {
// put your setup code here, to run once:
pinMode(SOLENOID, OUTPUT);
int sensorValue = analogRead(A0);
Serial.begin(9600);
clock.begin();
clock.fillByYMD(2021, 6, 29); //Jan 19,2013
clock.fillByHMS(04, 59, 50); //15:28 30"
clock.fillDayOfWeek(TUE);//Saturday
clock.setTime();//write time to the RTC chip
}
void loop() {
// put your main code here, to run repeatedly:
printTime();
Watering ();
}
/*Function: Display time on the serial monitor*/
void printTime() {
clock.getTime();
Serial.print(clock.hour, DEC);
Serial.print(":");
Serial.print(clock.minute, DEC);
Serial.print(":");
Serial.print(clock.second, DEC);
Serial.print(" ");
Serial.print(clock.dayOfMonth, DEC);
Serial.print("/");
Serial.print(clock.month, DEC);
Serial.print("/");
Serial.print(clock.year + 2000, DEC);
Serial.print(" ");
Serial.print(clock.dayOfMonth);
Serial.print("*");
switch (clock.dayOfWeek) { // Friendly printout the weekday
case MON:
Serial.print("MON");
break;
case TUE:
Serial.print("TUE");
break;
case WED:
Serial.print("WED");
break;
case THU:
Serial.print("THU");
break;
case FRI:
Serial.print("FRI");
break;
case SAT:
Serial.print("SAT");
break;
case SUN:
Serial.print("SUN");
break;
}
Serial.println(" ");
}
void Watering (){
switch(clock.hour){
{case 5:
int sensorValue = analogRead(A0);
if (sensorValue>=560){
digitalWrite(SOLENOID, HIGH);
delay(600000);
digitalWrite(SOLENOID, LOW);
delay(3600000);
}
}
{case 19:
int sensorValue = analogRead(A0);
if (sensorValue>=560){
digitalWrite(SOLENOID, HIGH);
delay(600000);
digitalWrite(SOLENOID, LOW);
delay(3600000);
}
}
}
}
|