Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <virtuabotixRTC.h>
- #include <LiquidCrystal_I2C.h>
- #include <Wire.h>
- virtuabotixRTC myRTC(6, 7, 8);
- const byte sensorPin = A0, relay = 4;
- byte lastSecond, humidity;
- bool relayState = 0, lastRelayState = 0;
- LiquidCrystal_I2C lcd(0X27, 16, 2);
- //Update display every second
- byte updateLCD(int val){
- byte h = map(val,520,200,0,100);
- lcd.setCursor(0, 0);
- lcd.print("Temps:");
- lcd.setCursor(7,0);
- char buf[10];
- sprintf(buf,"%02u:%02:%02", myRTC.hours, myRTC.minutes, myRTC.seconds);
- lcd.print(buf);
- lcd.setCursor(0,1);
- lcd.print("Humidity:");
- lcd.setCursor(10,1);
- lcd.print(humidity,DEC);
- Serial.print(myRTC.hours);
- Serial.print(myRTC.minutes);
- Serial.println(myRTC.seconds);
- lastSecond = myRTC.seconds;
- return h;
- }
- void setup(void){
- Serial.begin(9600);
- pinMode(relay, OUTPUT);
- digitalWrite(relay, relayState);
- myRTC.setDS1302Time(00, 06, 14, 4, 22, 02, 2024);
- lastSecond = myRTC.seconds;
- lcd.init();
- lcd.backlight();
- lcd.setCursor(0, 0);
- lcd.print("Saha");
- delay(200);
- lcd.clear();
- }
- void loop(void) {
- myRTC.updateTime();
- //Every Second update LCD
- if(myRTC.seconds != lastSecond){
- int sensorValue = analogRead(sensorPin);
- humidity = updateLCD(sensorValue);
- }
- if ((myRTC.month == 12 ||myRTC.month == 1||myRTC.month == 2) &&
- (myRTC.dayofweek == 4)&&
- (myRTC.hours >= 12 && myRTC.hours <= 14)){
- if(humidity <= 80){
- relayState = 1;
- }else{
- relayState = 0;
- }
- }
- if ((myRTC.month >= 3 && myRTC.month <= 5)&&
- (myRTC.dayofweek == 1 || myRTC.dayofweek == 4)&&
- (myRTC.hours == 16) && (myRTC.minutes == 0)) {
- if(humidity <= 90){
- relayState = 1;
- }else{
- relayState = 0;
- }
- }
- if ((myRTC.month >= 6 && myRTC.month <= 8)&&
- (myRTC.dayofweek == 1|| myRTC.dayofweek == 3|| myRTC.dayofweek == 6)&&
- (myRTC.hours == 16) && (myRTC.minutes == 0)){
- if(humidity <= 90){
- relayState = 1;
- }else{
- relayState = 0;
- }
- }
- if ((myRTC.month >= 9 && myRTC.month <= 11)&&
- (myRTC.dayofweek == 1 || myRTC.dayofweek == 4)&&
- (myRTC.hours == 16) && (myRTC.minutes == 0)){
- if(humidity <= 90){
- relayState = 1;
- }else{
- relayState = 0;
- }
- }
- if(relayState != lastRelayState){
- digitalWrite(relay, relayState);
- }
- lastRelayState = relayState;
- }
Advertisement
Add Comment
Please, Sign In to add comment