Water Pump and Lamp controlling with DS1302 RTC Modul

Hey Guys,
I am trying to connect my Arduino Uno, through relays with an water pump and a lamp using the DS1302 RTC Clock Modul. To be honest this is my first real project with Arduino, I of course made some of the basic tutorials, but now I am facing many problems. I already managed to connect one of the relays to turn it on and off. Next I wanted to install the DS1302 RTC clock Modul, but here my problems started. The last days I spent with reading through google to figure it out, but it still doesn't work. The Arduino is connected with an LCD 16x2, where I want to see the time and later the pH levels (once i bought the sensor) of the water. I ended up using the Code from this tutorial Arduino Playground - DS1302RTC
and changed it to work with the Uno. It shows now time and date on the LCD, but the time is wrong and sometimes seems to reset itself. The date is correct, though actually I don't need it and if I delete the lines for it it shows this error message:

Arduino: 1.6.12 (Mac OS X), Board: "Arduino/Genuino Uno"

/Users/xxxxxxx/Documents/Arduino/TEst_LCD/Test_lcd_Uhr/Test_lcd_Uhr.ino: In function 'void loop()':
Test_lcd_Uhr:69: error: 'print2digits' was not declared in this scope
/Users/xxxxxxxx/Documents/Arduino/TEst_LCD/Test_lcd_Uhr/Test_lcd_Uhr.ino: At global scope:
Test_lcd_Uhr:78: error: expected unqualified-id before 'if'
if(timeStatus() != timeSet) {
exit status 1
'print2digits' was not declared in this scope

Once I managed to fix this issue I want the two relais to be controlled by the right time.
I hope one of you can help me and sorry if I ask stupid questions or don't understand something.
Thank you so much

Here is the code I am using:

#include <Time.h>
#include <TimeLib.h>
#include <DS1302RTC.h>
#include <LiquidCrystal_I2C.h>

// Init the DS1302

DS1302RTC RTC(2, 3, 4);

#define DS1302_GND_PIN 6
#define DS1302_VCC_PIN 7
// Init the LCD

LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Addr, En, Rw, Rs, d4, d5, d6, d7, backlighpin, polarity

void setup()


// Setup LCD to 16x2 characters

lcd.begin(16, 2);

digitalWrite(DS1302_GND_PIN, LOW);
pinMode(DS1302_GND_PIN, OUTPUT);

digitalWrite(DS1302_VCC_PIN, HIGH);
pinMode(DS1302_VCC_PIN, OUTPUT);

lcd.print("RTC activated");


if (RTC.haltRTC())
lcd.print("Clock stopped!");
lcd.print("Clock working.");

if (RTC.writeEN())
lcd.print("Write allowed.");
lcd.print("Write protected.");

delay ( 2000 );

lcd.print("RTC Sync");
setSyncProvider(RTC.get); // the function to get the time from the RTC
if(timeStatus() == timeSet)
lcd.print(" Ok!");
lcd.print(" FAIL!");

delay ( 2000 );



void loop()
static int sday = 0; // Saved day number for change check

// Display time centered on the upper line
lcd.setCursor(4, 0);

// Update in 00:00:00 hour only
if(sday != day()) {
// Display abbreviated Day-of-Week in the lower left corner
lcd.setCursor(0, 1);

// Display date in the lower right corner
lcd.setCursor(5, 1);
lcd.print(" ");
// Warning!
if(timeStatus() != timeSet) {
lcd.setCursor(0, 1);
lcd.print(F("RTC ERROR: SYNC!"));

// Save day number
sday = day();

// Wait small time before repeating :slight_smile:
delay (100);

void print2digits(int number) {
if (number >= 0 && number < 10) {

Does that code compile?
Does that code work? As in, does that code display the correct time?

What do you need help with?

yes the code compiles, but it gives out the wrong time. In the meantime I took out the battery of the RTC and now the date is also wrong.
It would help me to know, why it doesn't show the right information, so where my mistakes are, maybe I didnt set the time right?
Thanks for the answer!

maybe I didnt set the time right?

Put the battery back in. Set the time right. What happens then?

I tried to set the time with this manual Arduino Playground - DS1302 but at first try the time didn't change and at second try it reseted again to Time = 00:00:00, Date(day of month) = 0, Month = 0, Day(day of week) = 0, Year = 2000

Okay I ended up buying the AZDelivery Real Time Clock DS3231 I2C mine seems to be not working very well. Will keep you updated.

With the new RTC DS3231 it took me five minutes to set it up and get the correct time on the LCD screen, now I am trying to figure out how to control the two relays, based on the RTC time. I guess I should use the TimeAlarms library (?), but I dont really understand how to connect it with my RTC. Can somebody give me a tip how to do it?

My code at the moment:

#include <LiquidCrystal_I2C.h>

#include <Wire.h>

#include <DS3231.h>

#include <
DS3231 rtc(A4, A5);

#define I2C_ADDR 0x3F // Define I2C Address for controller
#define En_pin 4
#define Rw_pin 5
#define Rs_pin 6
#define D4_pin 0
#define D5_pin 1
#define D6_pin 2
#define D7_pin 3

#define LED_OFF 0
#define LED_ON 1
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

void setup()


//rtc.setTime(22, 07, 0);
//rtc.setDate(28, 5, 2017);

lcd.begin(16, 2);

void loop()
lcd.setCursor(4, 0);

//lcd.setCursor(0, 1);

//lcd.setCursor(6, 1);

Serial.print(" ");

Serial.print(" -- ");


delay (1000);

I guess I should use the TimeAlarms library (?),

Why? You need crutches?

You know what time it is. You know what time you want something to happen? Is it that difficult to determine if the two times are the same time?

The library has methods to get all the pieces that make up the time, in other than String/string format.