DS1302 – connection scheme for Arduino

Many projects or tasks require precise, temporary execution. For example, in the system of automatic watering there can be several modes: morning watering, day and evening.
ds1302-real-time-clock-module-8520733096

Many projects or tasks require precise, temporary execution. For example, in the system of automatic watering there can be several modes: morning watering, day and evening. So, for the stable operation of the entire system and the entire working cycle, it is necessary that the system built on the Arduino be able to accurately determine the current time.

This function was not provided on the board, so the RTC module of the real-time clock will help solve this problem. He will help to make a plan for Arduino with regards to what and at what time should be included in the work or to perform other actions.

Orientation in time is very useful not only in automatic watering but also in other systems: turning on the light or heating on a schedule, turning on the electric kettle on a timer, etc.

Consider the operation of real-time clock modules on the example of DS1302. Other modules can also be attributed to this family, for example, DS1307, DS3231, while the connection scheme and the writing of the code are identical for all.

To implement the project from this article, we need the following components:

  • Arduino Uno R3
  • DS1302 – Real Time Clock (RTC)
  • Wires

SENSOR OVERVIEW

The DS1302 is a microcircuit of the same name on a small board with the necessary strapping, allowing you to connect a 3-5 V battery, among other things, thanks to which the module can be powered either through Arduino or independently.

What is this device capable of?

This chip allows you to count the time to within seconds. It has low power consumption, so a small lithium battery can last for more than a month.

CONNECTION SCHEME
The module is connected to the board using 5 pins:

 

  • Conclusion VCC and Gnd are responsible for power respectively (supply of five volts to DS1302 and grounding);
  • The CLK contact is connected to a digital pin on the board, for example, pin 6;
  • The DAT contact is connected to a digital pin on the board, for example, pin 7;
  • The RESX contact is connected to a digital pin on the board, for example, pin 8.

CONNECTING TO ARDUINO IDE

First, we recommend installing a special library for modules of the DS family.
You can download it at the link.

Library connection is carried out standardly for all libraries, using the include directive:

  #include

This library contains many useful commands and functions and simplifies writing code. Let’s deal with several of them using the example of a pair of codes for installing and determining the current time:

#include  
iarduino_RTC time(RTC_DS1302,8,6,7);
void setup() {
delay(300); 
Serial.begin(9600); 
time.begin(); 
time.settime(10,10,10,4,10,17,3); 
}
void loop(){
if(millis()%1000==0) { 
Serial.println(time.gettime(“d-m-Y, H:i:s, D”)); 
delay(1); 
}
}

Now we have set the time value to the module, and we can further use this value in the following programs.

As you can see, the main functions when working with the module will be:

  • Function begin(); – serves to initialize the work of our watches;
  • Function settime(sec, min, hour, day, month, year, day of the week); – serves to set the time;
  • Gettime() function; – serves to read the time.

To read the current value from the RTC module, use the following code:

#include  
iarduino_RTC time(RTC_DS1302,8,6,7); 
void setup() {
delay(300); 
Serial.begin(9600); 
time.begin();
}
void loop(){
if(millis()%1000==0){ 
Serial.println(time.gettime(“d-m-Y, H:i:s, D”)); 
delay(1);  }
}

Share on facebook
Facebook
Share on google
Google+
Share on twitter
Twitter
Share on linkedin
LinkedIn
Share on pinterest
Pinterest