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

Содержание

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:

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

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

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).

Share/Partager

Like this:

Related

Yassine View All

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

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

Amazing! Can I use that in my Arduino project?

Hello sir, Thankyou for the information.
Can you please explain the 7 in the brackets myRTC.setDS1302Time(15, 22, 21, 7, 14, 1, 2018);

It means “Day of the week” (Mon, Tue….) You can associate that number with its day name and display it too

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)’

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 &#8216;void setup()&#8217;:

REMOTOvv:31: error: &#8216;class LiquidCrystal_I2C&#8217; has no member named &#8216;setBacklightPin&#8217;

REMOTOvv:31: error: &#8216;POSITIVE&#8217; was not declared in this scope

exit status 1
no matching function for call to &#8216;LiquidCrystal_I2C::LiquidCrystal_I2C(int, int, int, int, int, int, int, int)&#8217;

Este reporte podría tener más información con
&#8220;Mostrar salida detallada durante la compilación&#8221;
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&#8217;t be found, so you either adapt the code to you existing library or remove it and use the library I provided

Hi. I followed your solution by adding a 1k resistor in series with DAT and Arduino&#8217;s input pin, but the problem persistrs. What can I do now? It&#8217;s Waveshare&#8217;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&#8230; 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&#8217;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);

I really can&#8217;t determine the problem here, do you have other modules? things wired with the Arduino UNO?

I just realized that even a simple Serial.println(&#8220;test&#8221;) doesn&#8217;t work either! It turns out that my usb cable is crappy. Problem solved!

What is the grounding problem?

why did you include the lcd pins if it is using i2c already? im confused

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

Fantastic, Thank you.

what do i need to do if i only want to show the time of the day on a 4 digit 7segment display?

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

How can i use in my scale weighing indicator?

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 .

Arduino: 1.8.12 (Mac OS X), Board: &#8220;Arduino Uno&#8221;

test_2:19:80: error: no matching function for call to &#8216;LiquidCrystal_I2C::LiquidCrystal_I2C(int, int, int, int, int, int, int, int)&#8217;
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 &#8216;void setup()&#8217;:
test_2:31:6: error: &#8216;class LiquidCrystal_I2C&#8217; has no member named &#8216;setBacklightPin&#8217;; did you mean &#8216;setBacklight&#8217;?
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
^

setBacklight
test_2:31:36: error: &#8216;POSITIVE&#8217; was not declared in this scope
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
^

exit status 1
no matching function for call to &#8216;LiquidCrystal_I2C::LiquidCrystal_I2C(int, int, int, int, int, int, int, int)&#8217;

This report would have more information with
&#8220;Show verbose output during compilation&#8221;
option enabled in File — Preferences.
I am getting this error any suggestion please let me know


Источник: surtrtech.com