zomer wintertijd

Toon hier Uw afgeronde projecten aan anderen.
Berichten: 20
Geregistreerd: 29 Dec 2020, 12:35

zomer wintertijd

Berichtdoor wappie » 29 Dec 2020, 19:38

ik zie dat er nog al wat vragenzijn over de zomer en winterstand dus deze code past deze aan
ool de relais schakeling er bij gezet , een diplay kan er aan worden toegevoegd
veel plezier met de code





Code: Alles selecteren
#include <EEPROM.h>
#include  <RTClib.h>


RTC_DS3231 rtc;
int DST;
int Relay = 4;

// relay gaat aan om 22,48 en uit om 22,49
const int OnHour = 22; //het uur waneer er geschakelt word  (24 uur FORMAT)
const int OnMin = 48;//de minuten
const int OffHour = 22; //uit tijd
const int OffMin = 49;

void setup()
{
Serial.begin(9600);

  pinMode(Relay, OUTPUT);
  digitalWrite(Relay, LOW);
 
DST = EEPROM.get(0, DST);

if(DST != 0 && DST != 1) 

{     

DST = 1; 

EEPROM.put(0, DST);

}

// Uncomment the following 2 lines if you need to set the DST (if you miss the actual day etc). Change the +1 to -1 in the fall.
// DateTime t2 = rtc.now();   
// rtc.adjust(DateTime(t2.year(), t2.month(), t2.day(), t2.hour()+1, t2.minute(), t2.second()));

}


void loop()
{

DateTime now = rtc.now();

  Serial.println("Current Date & Time: ");
    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(" (");
    Serial.print(now.dayOfTheWeek(), DEC);
    Serial.print(") ");
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();

if (now.dayOfTheWeek() == 0 && now.month() == 3 && now.day() >= 8 && now.day() <= 16 && now.hour() == 2 && now.minute() == 0 && now.second() == 0 && DST == 0)     
{       

rtc.adjust(DateTime(now.year(), now.month(), now.day(), now.hour()+1, now.minute(), now.second()));       
DST = 1;       
EEPROM.put(0, DST);     

}     
else if(now.dayOfTheWeek() == 0 && now.month() == 11 && now.day() >= 1 && now.day() <= 8 && now.hour() == 2 && now.minute() == 0 && now.second() == 0 && DST == 1)     
{       

rtc.adjust(DateTime(now.year(), now.month(), now.day(), now.hour()-1, now.minute(), now.second()));       
DST = 0;       
EEPROM.put(0, DST);     

}
 if (now.hour() == OnHour && now.minute() == OnMin)   // When the values are equivalent
{
    digitalWrite(Relay, HIGH);               // Pin 4 is HIGH
    Serial.println("LIGHT ON");             // Print the Message
  }
  else if (now.hour() == OffHour && now.minute() == OffMin) // When the values are equivalent
{
    digitalWrite(Relay, LOW);               // Pin 4 is Low
    Serial.println("LIGHT OFF");          // Print the Message

  }

}
   

Advertisement

Berichten: 287
Geregistreerd: 15 Apr 2021, 20:05

Re: zomer wintertijd

Berichtdoor ctunes » 18 Jun 2021, 21:18


Terug naar Afgeronde projecten

Wie is er online?

Gebruikers in dit forum: Geen geregistreerde gebruikers en 2 gasten