zomer en winterstand

algemene C code
Berichten: 25
Geregistreerd: 04 Dec 2019, 12:29

zomer en winterstand

Berichtdoor Pipo » 25 Okt 2020, 01:23

beste allemaal .

ben al een tijdje aan het proberen , de zomer en winter stand voor elkaar te krijgen
helaas doe ik iets niet goed en/of ik snap hem niet !
de instructies heb ik van https://www.instructables.com/The-Ardui ... me-Europe/

heb de tekst zorgvuldig doorgenomen , maar loop vast
kan iemand mij helpen ?


Code: Alles selecteren
#include <Wire.h>

#include <LiquidCrystal_I2C.h>
#include <DHT.h>
#include <Wire.h>
#include <DS3231.h>
#include <Timezone.h>

DS3231  rtc(SDA, SCL);
Time t;

LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display

//Constants
#define DHTPIN 7     // what pin we're connected to
#define DHTTYPE DHT22   // DHT 22  (AM2302)
DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino
int FanRelay = 38;
int Relay = 36;

const int OnHour = 22; //SET TIME TO ON RELAY (24 HOUR FORMAT)
const int OnMin = 55;
const int OffHour = 22; //SET TIME TO OFF RELAY
const int OffMin = 56;

unsigned long previousMillis = 0;        // will store last time LED was updated
// constants won't change:
unsigned long interval = 2000;           // interval at which to blink (milliseconds)
//Variables
//int chk;
float hum;  //Stores humidity value
float temp; //Stores temperature value


void setup()
{
  rtc.begin();

   // The following lines can be uncommented to set the date and time
    //rtc.setDOW(SATURDAY);     // Set Day-of-Week to SUNDAY
    //rtc.setTime(21,33, 0);     // Set the time to 12:00:00 (24hr format)
    //rtc.setDate(8, 8, 2020);   // Set the date to January 1st, 2014
 
    pinMode(FanRelay, OUTPUT);
    pinMode(Relay, OUTPUT);
    digitalWrite(Relay, LOW);
   
   
    Serial.begin(9600);
    Serial.println("ppdo's Temp and Humidity Sensor Test");
  dht.begin();
    lcd.init(); //initialize the lcd
    lcd.backlight(); //open the backlight
    rtc.begin(); // Initialize the rtc object
    lcd.begin(16,4); // Initializes the interface to the LCD screen, and specifies the dimensions (width and height) of the display }
}

void loop()
{
    //Read data and store it to variables hum and temp
    // Reading temperature or humidity takes about 250 milliseconds!
   unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;
   
    hum = dht.readHumidity();
    temp= dht.readTemperature();
    //Print temp and humidity values to serial monitor
    Serial.print("Humidity: ");
    Serial.print(hum);
    Serial.print(" %, Temp: ");
    Serial.print(temp);
    Serial.println(" Celsius");

   
// set the cursor to (0,0):
    lcd.setCursor(0, 3);
// print from 0 to 9:

    lcd.print("Temp: ");
    lcd.print(temp);
    lcd.print(" C");
 
    lcd.setCursor(0, 2);

    lcd.print("Humidity: ");
    lcd.print(hum);
    lcd.print(" %");
 
 
}
if(( float) temp >50 ){
  digitalWrite(FanRelay, HIGH);
}else{
    digitalWrite (FanRelay, LOW);
 }
 
 {
 t = rtc.getTime();
 lcd.setCursor(0,1);
 lcd.print("Time:  ");
 lcd.print(rtc.getTimeStr());
 
 lcd.setCursor(0,0);
 lcd.print("Date: ");
 lcd.print(rtc.getDateStr());
 
 if(t.hour == OnHour && t.min == OnMin){
    digitalWrite(Relay,HIGH);
    Serial.println("LIGHT ON");
    }
   
    else if(t.hour == OffHour && t.min == OffMin){
      digitalWrite(Relay,LOW);
      Serial.println("LIGHT OFF");

      {
      if (dow == 7 && mo == 10 && d >= 25 && h == 3 && DST==1)

{

setclockto 2 am;

DST=0;//store this in your NVRAM

}
 
    }}}

Advertisement

Berichten: 4064
Geregistreerd: 16 Okt 2013, 14:31
Woonplaats: s hertogenbosch

Re: zomer en winterstand

Berichtdoor shooter » 25 Okt 2020, 11:26

die DST moet je dan wel gebruiken dat vind ik nergens terug, staat ergens denk ik in timezone, en die DST moet dan 1 zijn natuurlijk boven in de loop of zo
dat ligt aan de libraries die je gebruikt.
paul deelen
shooter@home.nl

Berichten: 25
Geregistreerd: 04 Dec 2019, 12:29

Re: zomer en winterstand

Berichtdoor Pipo » 26 Okt 2020, 21:46

Hoi Paul, ik denk dat ik een fout maak , de DST is een flag bestand en deze heb ik nog niet toegevoegd zie ik nu

Berichten: 4064
Geregistreerd: 16 Okt 2013, 14:31
Woonplaats: s hertogenbosch

Re: zomer en winterstand

Berichtdoor shooter » 27 Okt 2020, 11:32

net als setclockto 2 am zal ook niet werken zo.
paul deelen
shooter@home.nl

Berichten: 25
Geregistreerd: 04 Dec 2019, 12:29

Re: zomer en winterstand

Berichtdoor Pipo » 20 Nov 2020, 00:18

ben opnieuw begonnen en had iets gevonden
heb er veel op zitten studeren, maar gaat iets fout ergens zit iets niet goed.

kan het zijn dat lcd.print(rtc.getTimeStr()); vervangen moet worden in DateTime t2 = rtc.now(); ?


Code: Alles selecteren
#include <EEPROM.h>
#include  <RTClib.h>
#include <DS3231.h>
#include <LiquidCrystal.h> // includes the LiquidCrystal Library


//DS3231  rtc(SDA, SCL);
LiquidCrystal lcd(1, 2, 4, 5, 6, 7); // Creates an LC object. Parameters: (rs, enable, d4,

RTC_DS3231 rtc;
int DST;


void setup()
{

DST = EEPROM.get(0, DST);

if(DST != 0 && DST != 1) 
 rtc.begin(); // Initialize the rtc object
 lcd.begin(16,2); //

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();   

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);     

}
lcd.setCursor(0,0);
 lcd.print("Time:  ");
 lcd.print(rtc.getTimeStr());
 
 lcd.setCursor(0,1);
 lcd.print("Date: ");
 lcd.print(rtc.getDateStr());
 
 delay(1000);
}

Terug naar C code

Wie is er online?

Gebruikers in dit forum: Geen geregistreerde gebruikers en 8 gasten