Hi all!
I'm trying to make my Real Time Clock working, but it's not using the correct time. For example: it's 17:25 in real time and it's using 17:10. The clock is correctly counting the seconds, but it's not the actual time.
Does anyone have experience with the RTC and knows what's going wrong?
Thanks for your help!
This is the code I used ...
//rtc----------
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
#include <Wire.h>
#include "RTClib.h"
#if defined(ARDUINO_ARCH_SAMD)
// for Zero, output on USB Serial console, remove line below if using programming port to program the Zero!
#define Serial SerialUSB
#endif
RTC_DS1307 rtc;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
//lcd---------
#include <LiquidCrystal.h>
#define ROTARY_ANGLE_SENSOR A0
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
//------------
void setup () {
#ifndef ESP8266
while (!Serial); // for Leonardo/Micro/Zero
#endif
Serial.begin(57600);
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (! rtc.isrunning()) {
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(2017, 10, 3, 17, 40, 0));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
// rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
}
lcd.begin(16, 2);
lcd.print("hello world!");
}
void loop () {
DateTime now = rtc.now();
lcd.setCursor(0, 1);
lcd.print(now.hour(), DEC);
lcd.print(':');
lcd.setCursor(3, 1);
lcd.print(now.minute(), DEC);
delay(500);
}