In compliance with high industry standards

|| Back to Support & Help Documentation ||

M-Duino RTC

Real-Time Clock  - Tracking the current time

The term real-time clock is used to avoid confusion with ordinary hardware clocks which are only signals that govern digital electronics, and do not count time in human units. RTC should not be confused with real-time computing, which shares the acronym but does not directly relate to time of day.

Although keeping time can be done without an RTC, using one has benefits:

  • Low power consumption (important when running from alternate power)

  • Frees the main system for time-critical tasks

  • Sometimes more accurate than other methods

RTCs often have an alternative power source, so they can continue to measure time while the main power supply is off or not available. This alternative power source is usually a lithium battery, but some new systems use a supercapacitor (they are rechargeable and can be soldered). The alternative power supply can also supply power to a RAM memory within the same RTC, which generally stores the BIOS configuration of the motherboard. 

There is a 3,3V lithium coin cell battery supplying the RTC in every Industrial Shields Ethernet PLC.

M-Duinos RTC Module is based on the DS1307 Chip. 

The DS1307 serial real-time clock (RTC) is a lowpower, full binary-coded decimal (BCD) clock/calendar plus 56 bytes of NV SRAM. Address and data are transferred serially through an I2C, bidirectional bus. The clock/calendar provides seconds, minutes, hours, day, date, month, and year information. The end of the month date is automatically adjusted for months with fewer than 31 days, including corrections for leap year. The clock operates in either the 24-hour or 12-hour format with AM/PM indicator. The DS1307 has a built-in power-sense circuit that detects power failures and automatically switches to the backup supply. Timekeeping operation continues while the part operates from the backup supply.

DS1307 Typical Operating Circuit

DS1307 Block Diagram


Check the M-Duino Family products now!

IMPORTANT: Make sure that your Ethernet PLC is powered (12-24Vdc).

Switch configuration

RTC works with the I2C protocol communication, so it is required to have enabled the I2C protocol.  

4 switches have to be configured in order to enable the RTC features and I2C communication:

Left Zone


RTC SCL & RTC SDA must be set to ON mode to enable the I2C wires to the RTC. If they are in OFF mode, the Arduino won’t communicate with the RTC.

        SWITCH                            ANALOG SHIELD                                   RELAY SHIELD

I2.6/SCL - I2.1/SCLI2.6SCLI2.1SCL
I2.5/SCL - I2.0/SDAI2.5SDAI2.0SDA

I2C must be enabled in order to communicate with the RTC, so if your Ethernet PLC has an Analog Shield you must set I2.6/SCL and I2.5/SCL to OFF mode to enable I2C.  If on the contrary, your Ethernet PLC has a Relay Shield you must set I2.1/SCL and I2.0/SCL to OFF mode to enable I2C. 
Remember: In this mode the inputs (I2.5 & I2.5 for Analog shield or I2.0 & I2.1 for Relay shield) are totally disabled and the I2C is now enabled.


IMPORTANT: Make sure to download the Arduino based PLC boards for Arduino IDE.

Software Configuration:
Once the hardware configuration is done, it's possible to proceed with the software configuration and also its usage. Firstable it's necessary to include the RTC.h library provided in our boards (RTC.h includes I2C.h initialitzation, so it will not be necessary to initialize the I2C.h library):

#include <RTC.h>

To check if the RTC port is working it is easy to use the serial monitor from the Arduino IDE using the right sentence inside the setup()  function:


RTC Library - Functions; //Boolean function. Indicates that RTC is able to transmit data.
RTC.write(); //Boolean function. Indicates that RTC is able to receive data.
RTC.setSecond(uint8_t second); //Sets the seconds on the RTC.
RTC.setMinute(uint8_t minute); //Sets the minute on the RTC.
RTC.setHour(uint8_t hour); // Sets the hour on the RTC.
RTC.setWeekDay(uint8_t weekDay); //Sets the week day on the RTC.
RTC.setMonthDay(uint8_t monthDay); //Sets the month day on the RTC.
RTC.setMonth(uint8_t month); //Sets the month on the RTC.
RTC.setYear(uint8_t year); //Sets the year on the RTC.

RTC.getyear(); // Returns the Year. RTC.getMonth(); // Returns the month. RTC.getMonthDay(); // Returns the day (month format).
RTC.getWeekDay(); // Returns the day (week format) RTC.getHour(); // Returns the hour.
RTC.getMinute(); // Returns the minutes.
RTC.getSecond(); // Returns the seconds.
RTC.getTime(); // Returns the number of milliseconds between midnight of January 1, 1970 and the specified date.

Example Codes

Basic RTC test:

// RTC library example

// by Industrial Shields

#include <RTC.h>


void setup() {




void loop() {

  if (! {

    Serial.println("Read date error: is time set?");


     else {

    Serial.print("Time: ");






    Serial.print(" ");






    Serial.print(" (");






By following these steps carefully, you will be able to achieve the use of the RTC using the Industrial Shields equipments.

1 Star 2 Star 3 Star 4 Star 5 Star