Problem with rtc code

Hello i have a problem with rtc 1307 module, it appears date 00:00 1/1/2000 , how can i make him work ?
Here is the code:
#include <dht11.h>
#include <LiquidCrystal.h>
#include <Wire.h>
#include <RTClib.h>
RTC_DS1307 rtc;
#include <SD.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

const int buttonPin = A0; //pinul la care este conectat butonul
int buttonState = 0;
dht11 DHT11;
#define DHT11PIN A0

const int chipSelect = 8;

byte termometru[8] = //pictograma pentru temperatura
{
B00100,
B01010,
B01010,
B01010,
B01110,
B11111,
B11111,
B01110
};

byte picatura[8] = //pictograma pentru umiditate
{
B00100,
B00100,
B01010,
B01010,
B10001,
B10001,
B10001,
B01110,
};

void setup() {
pinMode(buttonPin, INPUT);
lcd.begin(16, 2);
lcd.clear();
lcd.createChar(1,termometru);
lcd.createChar(2,picatura);
lcd.setCursor(0,0);
lcd.print("Initializare");
lcd.setCursor(3,1);
lcd.print("card SD...");
delay(1000);
lcd.clear();
pinMode(10, OUTPUT);
digitalWrite(10,HIGH);

if (!SD.begin(chipSelect)) {

lcd.setCursor(4, 0);
lcd.print("Cardul");
lcd.setCursor(0, 1);
lcd.print("nu este prezent");
delay(3000);
return;
}

lcd.print("Card initializat.");
delay(2000);
lcd.clear();

Wire.begin();
rtc.begin();
if (! rtc.isrunning()) {
lcd.clear();
lcd.print("Eroare RTC");
}
delay(2000);
}
void loop() {

int chk = DHT11.read(DHT11PIN);

DateTime now = rtc.now();

lcd.clear();
lcd.setCursor(2, 0);
lcd.write(1);
lcd.print(" ");
lcd.print((float)DHT11.temperature, 0);
lcd.print((char)223); // semnul pentru grade
lcd.print("C");
lcd.setCursor(9,0);
lcd.write(2);
lcd.print(" ");
lcd.print((float)DHT11.humidity, 0);
lcd.print("%");

lcd.setCursor(7, 1);
lcd.print(now.day(), DEC);
lcd.print('/');
lcd.print(now.month(), DEC);
lcd.print('/');
lcd.print(now.year(), DEC);
lcd.setCursor(0, 1);
if (now.hour() < 10) lcd.print("0"); // add zero
lcd.print(now.hour(), DEC); // Print ora
lcd.print(":");
if (now.minute() < 10) lcd.print("0"); // add zero
lcd.print(now.minute(), DEC); // Print minute
// lcd.print(":");
// if (now.second() < 10) lcd.print("0"); // add zero
// lcd.print(now.second(), DEC); // Print secunde

int s=now.second();
if(s==1){ //se memoreaza datele odata pe minut
LogToSD(); //memorarea se face cu ajutorul acestei functii
}
delay(1000);
}

void LogToSD(){
DateTime now = rtc.now();
File dataFile = SD.open("datalog.txt", FILE_WRITE);
if (dataFile) {
dataFile.print(now.day(), DEC);
dataFile.print('/');
dataFile.print(now.month(), DEC);
dataFile.print('/');
dataFile.print(now.year(), DEC);
dataFile.print(",");
dataFile.print(now.hour(), DEC);
dataFile.print(':');
dataFile.print(now.minute(), DEC);
dataFile.print(':');
dataFile.print(now.second(), DEC);
dataFile.print(",");
dataFile.print((float)DHT11.temperature, 0);
dataFile.print(",");
dataFile.print((float)DHT11.humidity, 0);
dataFile.println();
dataFile.close();
}

// if the file isn't open, pop up an error:
else {
//Serial.println("error opening datalog.txt");
lcd.clear();
lcd.setCursor(2,0);
lcd.print("Eroare fisier");
delay(2000);
}
}

(deleted)

I don't see anywhere in your code where you have initially set the clock. An RTC doesn't know what time it is when you turn it on, unless you've got the battery backup hooked up. But it always has to have the time set initially.

gabiunitbv:
Hello i have a problem with rtc 1307 module, it appears date 00:00 1/1/2000 , how can i make him work ?

Everything seems to work fine and the time/date you see is caused by a double-power-loss:

  1. no normal power (VCC) for the RTC module
  2. no backup-power (VBat) provided by the backup battery.

Possibly you removed the backup battery of the module and after putting it back you missed setting date and time in the RTC?

and how can i set it ?

(deleted)

gabiunitbv:
and how can i set it ?

You are including a RTC library

#include <RTClib.h>

Look up the .h file for prototypes and comments of all functions in that library!

And don't forget the library example sketches!

This function is often used: rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); . It gets the time of when was the sketch compiled. I'd also advise to set time separately from your main sketch if you don't want the time resetting every time you reset your Arduino.

Hi i have a problem with my rtc code, i use an lcd, an rtc ds 1307 rtc, an temperature and humidity senzor and arduino uno board but, on the screen it appears the temperature humidity and only the date when i load the code on the board, for example , 20:02 15/5/2016 and stays like this. How cand i make the clock work ? Could somebody write for me what i have to write in the code?
Here is the code:

// TEMPERATURE AND HUMIDITY DATA LOGGER WITH CLOCK AND DATE
// USING ARDUINO UNO, 16X2 I2C LCD, DHT11 SENSOR
//
//Codul original a fost creat de Husham Samir de pe instructables.com //
// http://www.instructables.com/id/Temperature-Data-Logger-1/ //
//
//
// Arduino datalogger with i2c lcd and rtc and DHT11. - YouTube
//
// ++++++++++++++++++++++++++++++++++++++++++++++++
//
// SD card attached to SPI bus as follows:
// ** MOSI - pin 11
// ** MISO - pin 12
// ** CLK - pin 13
// ** CS - pin 8

//RTC Clock and I2C LCD
// SDA -Pin A4
// SCL -Pin A5

// DHT11 Sensor
// Pin 1 - 5V
// Pin 2 - Data -> D2 on Arduino
// Pin 3 - NC
// Pin 4 - GND

// Button
// A2]------------+
// R 10K | Switch
// +5V--[===]-----+----[/]---+
// |
// GND-----------------------+

#include <dht11.h>
#include <LiquidCrystal.h>
#include <Wire.h>
#include <RTClib.h>
RTC_DS1307 rtc;
#include <SD.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

const int buttonPin = A0; //pinul la care este conectat butonul
int buttonState = 0;
dht11 DHT11;
#define DHT11PIN A0

const int chipSelect = 8;

byte termometru[8] = //pictograma pentru temperatura
{
B00100,
B01010,
B01010,
B01010,
B01110,
B11111,
B11111,
B01110
};

byte picatura[8] = //pictograma pentru umiditate
{
B00100,
B00100,
B01010,
B01010,
B10001,
B10001,
B10001,
B01110,
};

void setup() {
pinMode(buttonPin, INPUT);
lcd.begin(16, 2);
lcd.clear();
lcd.createChar(1,termometru);
lcd.createChar(2,picatura);
lcd.setCursor(0,0);
lcd.print("Initializare");
lcd.setCursor(3,1);
lcd.print("card SD...");
delay(1000);
lcd.clear();
pinMode(10, OUTPUT);
digitalWrite(10,HIGH);

if (!SD.begin(chipSelect)) {

lcd.setCursor(4, 0);
lcd.print("Cardul");
lcd.setCursor(0, 1);
lcd.print("nu este prezent");
delay(3000);
return;
}

lcd.print("Card initializat.");
delay(2000);
lcd.clear();

Wire.begin();
rtc.begin();
if (! rtc.isrunning()) {
lcd.clear();
lcd.print("Eroare RTC");
}
delay(2000);
}
void loop() {

int chk = DHT11.read(DHT11PIN);

DateTime now = rtc.now();
rtc.adjust(DateTime(F(DATE), F(TIME)));
lcd.clear();
lcd.setCursor(2, 0);
lcd.write(1);
lcd.print(" ");
lcd.print((float)DHT11.temperature, 0);
lcd.print((char)223); // semnul pentru grade
lcd.print("C");
lcd.setCursor(9,0);
lcd.write(2);
lcd.print(" ");
lcd.print((float)DHT11.humidity, 0);
lcd.print("%");

lcd.setCursor(7, 1);
lcd.print(now.day(), DEC);
lcd.print('/');
lcd.print(now.month(), DEC);
lcd.print('/');
lcd.print(now.year(), DEC);
lcd.setCursor(0, 1);
if (now.hour() < 10) lcd.print("0"); // add zero
lcd.print(now.hour(), DEC); // Print ora
lcd.print(":");
if (now.minute() < 10) lcd.print("0"); // add zero
lcd.print(now.minute(), DEC); // Print minute
// lcd.print(":");
// if (now.second() < 10) lcd.print("0"); // add zero
// lcd.print(now.second(), DEC); // Print secunde

int s=now.second();
if(s==1){ //se memoreaza datele odata pe minut
LogToSD(); //memorarea se face cu ajutorul acestei functii
}
delay(1000);
}

void LogToSD(){
DateTime now = rtc.now();
File dataFile = SD.open("datalog.txt", FILE_WRITE);
if (dataFile) {
dataFile.print(now.day(), DEC);
dataFile.print('/');
dataFile.print(now.month(), DEC);
dataFile.print('/');
dataFile.print(now.year(), DEC);
dataFile.print(",");
dataFile.print(now.hour(), DEC);
dataFile.print(':');
dataFile.print(now.minute(), DEC);
dataFile.print(':');
dataFile.print(now.second(), DEC);
dataFile.print(",");
dataFile.print((float)DHT11.temperature, 0);
dataFile.print(",");
dataFile.print((float)DHT11.humidity, 0);
dataFile.println();
dataFile.close();
}

// if the file isn't open, pop up an error:
else {
//Serial.println("error opening datalog.txt");
lcd.clear();
lcd.setCursor(2,0);
lcd.print("Eroare fisier");
delay(2000);
}
}

Wow.

Spycatcher gave you the obvious and correct answer in the very first reply. Why are you ignoring that?

Use the example sketch in the IDE to SET the clock. You do that by loading the sketch to your Arduino and observing the Serial monitor to see the results.

Then, load your sketch above onto your Arduino. Because it is a clock, and is supported by an on-board battery, it will maintain the settings in the first step.

OK?