Hey everybody,
I am struggling with a programming problem. I think for an arduino expert, it's nothing, but I am still a beginner.
I have an Arduino UNO, with a TinyRTC (DS1307 based/RTClib.h) connected to it.
I want to calculate sunrise time (to display it on an LCD. I use the sunrise.h library, which works fine.)
Instead of entering month and day manually every day (which works fine), I would like the Arduino to pull this information from the RTC, so that it is always up-to-date and I do not have to manually change the date.
So, in the code, I tried to just replace month and day (6,11) with ((now.month(), DEC),(now.day(), DEC)). However, it does not work. I always get 7:24 as sunrise time, which is not correct.
I should add that the (now.month(), DEC) and (now.day(), DEC) commands work fine elsewhere in the same code, when it comes to reading the time from the RTC.
I have been trying for a couple of hours now and am desperate at this point. Any help would be much appreciated!
This is my code. It may look much, but it is only the part at the end that does not work.
#include <Wire.h>
#include <LiquidCrystal.h>
#include <Adafruit_BMP085.h>
#include <RTClib.h>
#include <Sunrise.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
Adafruit_BMP085 bmp;
RTC_DS1307 RTC;
Sunrise mySunrise(49.44,11.86,+2);
void setup() {
Wire.begin();
lcd.begin(16, 2);
bmp.begin();
RTC.begin();
//RTC.adjust(DateTime(__DATE__, __TIME__));
mySunrise.Actual(); //Actual, Civil, Nautical, Astronomical
delay(10);
}
void loop()
{
lcd.print("Temperatur:");
lcd.setCursor(0, 1);
lcd.print(bmp.readTemperature());
lcd.print(" ");
lcd.print((char)223);
lcd.print("C");
delay(2000);
lcd.clear();
lcd.print("Helligkeit:");
lcd.setCursor(0, 1);
lcd.print(analogRead(A0));
lcd.print("/1023");
delay(2000);
lcd.clear();
lcd.print("Luftdruck:");
lcd.setCursor(0, 1);
lcd.print(((bmp.readPressure() + 4060)/100.0),1); //4050 ist Korrekturfaktor
lcd.print(" hPa");
delay(2000);
lcd.clear();
DateTime now = RTC.now();
lcd.print("Datum:");
lcd.setCursor(0, 1);
lcd.print(now.day(), DEC);
lcd.print('.');
lcd.print(now.month(), DEC);
lcd.print('.');
lcd.print(now.year(), DEC);
delay(2000);
lcd.clear();
lcd.print("Uhrzeit:");
lcd.setCursor(0, 1);
lcd.print(now.hour(), DEC);
lcd.print(':');
lcd.print(now.minute(), DEC);
lcd.print(':');
lcd.print(now.second(), DEC);
lcd.print(" Uhr");
delay(2000);
lcd.clear();
byte h,m;
int t;
t=mySunrise.Rise((now.month(), DEC),(now.day(), DEC));// (month,day) - january=1
h=mySunrise.Hour();
m=mySunrise.Minute();
lcd.print("Sunrise:");
lcd.setCursor(0, 1);
lcd.print(h, DEC);
lcd.print(":");
lcd.print(m, DEC);
delay(2000);
lcd.clear();
}
Many thanks again for any suggestions!