Skip to content

How to simply use DS1302 RTC module with Arduino board and LCD screen

 

 



Hello there,

In this tutorial we gonna use DS1302 Real Time Clock module with Arduino board. This module can be set up via an Arduino code and then you can use it as you want, for example to show time/date a  screen or to log some sensor values by time or setting sleep and wake modes, similar modules are used in computers, phones, TVs…. it always has a battery cell that can last long enough so even if the device is not powered the time keeps updating.

Here are some projects I did with this module:

Or some similar modules:

 



For this we gonna need:

  • RTC DS1302 module.
  • Arduino board, here I’m using Uno.
  • LCD i2c screen, optionnal if you want to visualize date/time on your screen. If you don’t know how to use one check here.
  • Some jump wires.
  • And 1k Resistor if you have the same problem as I had (check the video).

 

Libraries

Here are the libraries you’ll need for this, download them here:

Wirings and Codes

Here I gathered all codes I used, you can download them here: RTC codes I’ve used “.ino”, or check below and copy them.

 


Wiring 1: Setup the module from the IDE and show the time on the Serial monitor

DS1302 wired with Arduino UNO

Code 1 : Setting the time and date of the module and showing it on the serial monitor

This code will permit you to set the DS1302 and then display date and time on the serial monitor.

Please read carefully the code below, the line

Permits you to set the module on the given values (numbers typed there), you have to set it up to your current date/time and then comment it

And reupload the code again to the Arduino with removed or commented (//) “setDS1302Time” function, so when you restart your Arduino the program doesn’t execute the function again.

Code 1:

Wiring 2: Add LCD i2c Screen and solving the grounding problem if you encounter it

DS1302 and LCD i²c, the resistor is optional, only if you have the mentioned problem


Code 2: Showing the Date/Time on a LCD i2c screen

This code uses the LCD i²c screen, optional of course, be careful again with “SetDS1302Time” function again (read above).

Yassine View All

Automation and Electrical Engineer, Electronics amateur trying to share my little projects.

31 thoughts on “How to simply use DS1302 RTC module with Arduino board and LCD screen Leave a comment

  1. Arduino:1.8.3 (Windows XP), Tarjeta:”Arduino/Genuino Uno”

    REMOTOvv:19: error: no matching function for call to ‘LiquidCrystal_I2C::LiquidCrystal_I2C(int, int, int, int, int, int, int, int)’

    LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

    ^

    C:\Documents and Settings\Administrador\Escritorio\REMOTOvv\REMOTOvv.ino:19:80: note: candidates are:

    In file included from C:\Documents and Settings\Administrador\Escritorio\REMOTOvv\REMOTOvv.ino:7:0:

    C:\Documents and Settings\Administrador\Mis documentos\Arduino\libraries\LiquidCrystal_I2C/LiquidCrystal_I2C.h:57:3: note: LiquidCrystal_I2C::LiquidCrystal_I2C(uint8_t, uint8_t, uint8_t)

    LiquidCrystal_I2C(uint8_t lcd_Addr,uint8_t lcd_cols,uint8_t lcd_rows);

    ^

    C:\Documents and Settings\Administrador\Mis documentos\Arduino\libraries\LiquidCrystal_I2C/LiquidCrystal_I2C.h:57:3: note: candidate expects 3 arguments, 8 provided

    C:\Documents and Settings\Administrador\Mis documentos\Arduino\libraries\LiquidCrystal_I2C/LiquidCrystal_I2C.h:55:7: note: constexpr LiquidCrystal_I2C::LiquidCrystal_I2C(const LiquidCrystal_I2C&)

    class LiquidCrystal_I2C : public Print {

    ^

    C:\Documents and Settings\Administrador\Mis documentos\Arduino\libraries\LiquidCrystal_I2C/LiquidCrystal_I2C.h:55:7: note: candidate expects 1 argument, 8 provided

    C:\Documents and Settings\Administrador\Mis documentos\Arduino\libraries\LiquidCrystal_I2C/LiquidCrystal_I2C.h:55:7: note: constexpr LiquidCrystal_I2C::LiquidCrystal_I2C(LiquidCrystal_I2C&&)

    C:\Documents and Settings\Administrador\Mis documentos\Arduino\libraries\LiquidCrystal_I2C/LiquidCrystal_I2C.h:55:7: note: candidate expects 1 argument, 8 provided

    C:\Documents and Settings\Administrador\Escritorio\REMOTOvv\REMOTOvv.ino: In function ‘void setup()’:

    REMOTOvv:31: error: ‘class LiquidCrystal_I2C’ has no member named ‘setBacklightPin’

    lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);

    ^

    REMOTOvv:31: error: ‘POSITIVE’ was not declared in this scope

    lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);

    ^

    exit status 1
    no matching function for call to ‘LiquidCrystal_I2C::LiquidCrystal_I2C(int, int, int, int, int, int, int, int)’

    Este reporte podría tener más información con
    “Mostrar salida detallada durante la compilación”
    opción habilitada en Archivo -> Preferencias.

    • Hello, this is a library issue, you have a library with the same name but when you call a function it can’t be found, so you either adapt the code to you existing library or remove it and use the library I provided

  2. Hi. I followed your solution by adding a 1k resistor in series with DAT and Arduino’s input pin, but the problem persistrs. What can I do now? It’s Waveshare’s DS1302 RTC board. It prints crappy time and after 2-3 seconds it stops printing in Serial monitor.

    • Hello, try without the resistor, or a lower value one… make sure that the pins are soldred well, also check the other components, sometimes a badly soldred smd can cause those problems.

      • I tried all of these, I even bought another DS1302 RTC board to check if the previous one had a problem, but it has the same behaviour. I tried on another Arduino, I tried changing the jumper wires but nothing. It prints weird numbers, sometimes characters, and 2-4 seconds later it stops printing on my Serial Monitor. I even had almost the same numbers as you in your video, but the 1k (and other values) resistor didn’t solve the problem.
        My wiring is like this:
        Vcc -> 5v
        GND -> GND
        I/O (MISO) -> Pin 8
        SCLK -> Pin 7
        CE (CS) -> Pin 9

        Initialization (on the code): virtuabotixRTC myRTC(7,8,9);

  3. I just realized that even a simple Serial.println(“test”) doesn’t work either! It turns out that my usb cable is crappy. Problem solved!

    • Yes it’s an i²c, but it’s just an adapter soldered at the pins of a standard LCD, and the function used to declare the LCD needs those pins numbers.

  4. Hello, I am unable to download any archive from Google Drive?? Why is it impssible?? I can not realise the project without those archive. Please help.
    Thx

  5. 23:18:27.509 -> Current Date / Time: 45/25/2165 45:85:85
    23:18:28.499 -> Current Date / Time: 45/25/2165 45:85:85
    23:18:29.497 -> Current Date / Time: 45/25/2165 45:85:85
    23:18:30.505 -> Current Date / Time: 45/25/2165 45:85:85
    23:18:31.507 -> Current Date / Time: 45/25/2165 45:85:85
    23:18:32.493 -> Current Date / Time: 45/25/2165 45:85:85
    23:18:33.489 -> Current Date / Time: 45/25/2165 45:85:85
    23:18:34.519 -> Current Date / Time: 45/25/2165 45:85:85
    23:18:35.511 -> Current Date / Time: 45/25/2165 45:85:85
    23:18:36.511 -> Current Date / Time: 45/25/2165 45:85:85
    23:18:37.505 -> Current Date / Time: 45/25/2165 45:85:85
    23:18:38.534 -> Current Date / Time: 45/25/2165 45:85:85
    23:18:39.525 -> Current Date / Time: 45/25/2165 45:85:85
    23:18:40.535 -> Current Date / Time: 45/25/2165 45:85:85

    I am getting the the time in this format in this form even after i set the time,I am new to programming pls help,I am using ds1302 and aurdino uno .

  6. Arduino: 1.8.12 (Mac OS X), Board: “Arduino Uno”

    test_2:19:80: error: no matching function for call to ‘LiquidCrystal_I2C::LiquidCrystal_I2C(int, int, int, int, int, int, int, int)’
    LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
    ^
    In file included from /Users/raju/Documents/Arduino/test_2/test_2.ino:7:0:
    /Users/raju/Documents/Arduino/libraries/LiquidCrystal_I2C-1.1.2/LiquidCrystal_I2C.h:57:3: note: candidate: LiquidCrystal_I2C::LiquidCrystal_I2C(uint8_t, uint8_t, uint8_t)
    LiquidCrystal_I2C(uint8_t lcd_Addr,uint8_t lcd_cols,uint8_t lcd_rows);

    ^~~~~~~~~~~~~~~~~
    /Users/raju/Documents/Arduino/libraries/LiquidCrystal_I2C-1.1.2/LiquidCrystal_I2C.h:57:3: note: candidate expects 3 arguments, 8 provided
    /Users/raju/Documents/Arduino/libraries/LiquidCrystal_I2C-1.1.2/LiquidCrystal_I2C.h:55:7: note: candidate: constexpr LiquidCrystal_I2C::LiquidCrystal_I2C(const LiquidCrystal_I2C&)
    class LiquidCrystal_I2C : public Print {

    ^~~~~~~~~~~~~~~~~
    /Users/raju/Documents/Arduino/libraries/LiquidCrystal_I2C-1.1.2/LiquidCrystal_I2C.h:55:7: note: candidate expects 1 argument, 8 provided
    /Users/raju/Documents/Arduino/libraries/LiquidCrystal_I2C-1.1.2/LiquidCrystal_I2C.h:55:7: note: candidate: constexpr LiquidCrystal_I2C::LiquidCrystal_I2C(LiquidCrystal_I2C&&)
    /Users/raju/Documents/Arduino/libraries/LiquidCrystal_I2C-1.1.2/LiquidCrystal_I2C.h:55:7: note: candidate expects 1 argument, 8 provided
    /Users/raju/Documents/Arduino/test_2/test_2.ino: In function ‘void setup()’:
    test_2:31:6: error: ‘class LiquidCrystal_I2C’ has no member named ‘setBacklightPin’; did you mean ‘setBacklight’?
    lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
    ^~~~~~~~~~~~~~~
    setBacklight
    test_2:31:36: error: ‘POSITIVE’ was not declared in this scope
    lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
    ^~~~~~~~
    exit status 1
    no matching function for call to ‘LiquidCrystal_I2C::LiquidCrystal_I2C(int, int, int, int, int, int, int, int)’

    This report would have more information with
    “Show verbose output during compilation”
    option enabled in File -> Preferences.
    I am getting this error any suggestion please let me know

  7. Hi, I even after using a 1kOhm I get 45/25/2165 as a date and an invalid time. Is there something else to help ?

  8. C:\Users\RAPID BOOTS\AppData\Local\Temp\Rar$DIa15064.15933\RTC_DS1302_LCDi2c\RTC_DS1302_LCDi2c.ino:19:80: error: no matching function for call to ‘LiquidCrystal_I2C::LiquidCrystal_I2C(int, int, int, int, int, int, int, int)’
    LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
    ^
    In file included from C:\Users\RAPID BOOTS\AppData\Local\Temp\Rar$DIa15064.15933\RTC_DS1302_LCDi2c\RTC_DS1302_LCDi2c.ino:7:0:
    C:\Users\RAPID BOOTS\Documents\Arduino\libraries\LiquidCrystal_I2C/LiquidCrystal_I2C.h:57:3: note: candidate: LiquidCrystal_I2C::LiquidCrystal_I2C(uint8_t, uint8_t, uint8_t)
    LiquidCrystal_I2C(uint8_t lcd_Addr,uint8_t lcd_cols,uint8_t lcd_rows);
    ^~~~~~~~~~~~~~~~~
    C:\Users\RAPID BOOTS\Documents\Arduino\libraries\LiquidCrystal_I2C/LiquidCrystal_I2C.h:57:3: note: candidate expects 3 arguments, 8 provided
    C:\Users\RAPID BOOTS\Documents\Arduino\libraries\LiquidCrystal_I2C/LiquidCrystal_I2C.h:55:7: note: candidate: constexpr LiquidCrystal_I2C::LiquidCrystal_I2C(const LiquidCrystal_I2C&)
    class LiquidCrystal_I2C : public Print {
    ^~~~~~~~~~~~~~~~~
    C:\Users\RAPID BOOTS\Documents\Arduino\libraries\LiquidCrystal_I2C/LiquidCrystal_I2C.h:55:7: note: candidate expects 1 argument, 8 provided
    C:\Users\RAPID BOOTS\Documents\Arduino\libraries\LiquidCrystal_I2C/LiquidCrystal_I2C.h:55:7: note: candidate: constexpr LiquidCrystal_I2C::LiquidCrystal_I2C(LiquidCrystal_I2C&&)
    C:\Users\RAPID BOOTS\Documents\Arduino\libraries\LiquidCrystal_I2C/LiquidCrystal_I2C.h:55:7: note: candidate expects 1 argument, 8 provided
    C:\Users\RAPID BOOTS\AppData\Local\Temp\Rar$DIa15064.15933\RTC_DS1302_LCDi2c\RTC_DS1302_LCDi2c.ino: In function ‘void setup()’:
    C:\Users\RAPID BOOTS\AppData\Local\Temp\Rar$DIa15064.15933\RTC_DS1302_LCDi2c\RTC_DS1302_LCDi2c.ino:29:7: error: ‘class LiquidCrystal_I2C’ has no member named ‘setBacklightPin’; did you mean ‘setBacklight’?
    lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
    ^~~~~~~~~~~~~~~
    setBacklight
    C:\Users\RAPID BOOTS\AppData\Local\Temp\Rar$DIa15064.15933\RTC_DS1302_LCDi2c\RTC_DS1302_LCDi2c.ino:29:37: error: ‘POSITIVE’ was not declared in this scope
    lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
    ^~~~~~~~
    Multiple libraries were found for “LiquidCrystal_I2C.h”
    Used: C:\Users\RAPID BOOTS\Documents\Arduino\libraries\LiquidCrystal_I2C
    Not used: C:\Users\RAPID BOOTS\Documents\Arduino\libraries\Newliquidcrystal_1.3.5
    exit status 1

    Compilation error: no matching function for call to ‘LiquidCrystal_I2C::LiquidCrystal_I2C(int, int, int, int, int, int, int, int)’

Leave a Reply to YassineCancel reply

Discover more from SURTR TECHNOLOGY

Subscribe now to keep reading and get access to the full archive.

Continue reading