AED 9.95
Description
The DS1302 is a real-time clock (RTC) module that is commonly used in electronic projects to keep track of time. It features a battery backup to maintain timekeeping even when power is lost, and communicates with a microcontroller using a simple serial interface. The module includes a clock/calendar function with year, month, day, hour, minute, and second information, as well as programmable square-wave output and trickle-charge capability for battery backup. The DS1302 is a popular choice for timekeeping applications due to its low cost, ease of use, and availability in small form factors.
Package Includes:
- 1 x DS1302 real-time clock (RTC) module (multi colors sent randomly)
- Note: Battery is not included
Features:
- Accurate Timekeeping: The module provides accurate timekeeping with a clock/calendar function that tracks year, month, day, hour, minute, and second.
- Battery Backup: The module includes a battery backup that allows it to maintain timekeeping even when the main power supply is lost.
- Simple Interface: The module communicates with a microcontroller using a simple 3-wire serial interface.
- Programmable Square-Wave Output: The module features a programmable square-wave output that can be used to trigger periodic events or drive a clock display.
- Trickle-Charge Capability: The module supports low-power consumption by providing a trickle-charge capability for the backup battery.
- Leap Year Compensation: The module supports programmable leap year compensation to ensure accurate timekeeping.
- Multiple Package Options: The DS1302 RTC module comes in a variety of package types, including DIP and SOIC, and is commonly available in small form factors.
- Wide Compatibility: The module is compatible with a wide range of microcontrollers and development platforms, and has a large community of developers and resources available.
Description:
The DS1302 Real Time Clock (RTC) module is a popular and affordable device used in various embedded systems and electronic projects to keep track of time. It is a low-power, full binary-coded decimal (BCD) clock/calendar with a battery backup that can operate autonomously, even when the main power supply is lost. The module uses a simple 3-wire serial interface to communicate with a microcontroller and can be easily integrated into a wide range of projects. The DS1302 RTC module can keep track of the current year, month, date, hour, minute, and second with programmable leap year compensation. It also features a programmable square-wave output signal that can be used to trigger periodic events or drive a clock display. The output frequency of the square wave can be adjusted, and the module supports low-power consumption by providing a trickle-charge capability for the backup battery. The DS1302 module comes in a variety of package types, including DIP and SOIC, and is commonly available in small form factors, making it easy to incorporate into small or space-constrained projects. The module is well-supported by various development platforms and has a wide range of libraries and tutorials available to assist in its integration with different microcontrollers.
Principle of Work:
The DS1302 RTC module works on the principle of keeping track of time using an oscillator, a counter, and a memory storage system. The module uses an external 32.768kHz crystal oscillator to generate a precise time base. The oscillator output is fed into a divider circuit that divides the frequency down to a 1 Hz signal, which is then used as the clock input for the counter. The counter is a binary counter that counts the number of clock pulses and keeps track of the current time. The counter output is in binary-coded decimal (BCD) format, which means that each digit is represented by four binary bits. The counter is capable of counting up to 60 seconds, 60 minutes, 24 hours, and up to 31 days in a month. The time and date information is stored in a non-volatile memory, which is backed up by a small battery on the RTC module. When the main power supply is lost, the RTC module switches to the battery backup and continues to keep track of time. To interface with the RTC module, a microcontroller sends a series of commands to read or write to the various registers in the DS1302 module. The module responds to the commands by providing the requested information or updating the necessary registers with new values.
Pinout:
- VCC: This is the power supply pin and is typically connected to a 5V power source. The DS1302 module can operate over a wide range of supply voltages, from 2.0V to 5.5V.
- GND: This is the ground pin and is connected to the ground of the power supply.
- CLK: This is the clock pin, which is used to synchronize data transfer between the RTC module and the microcontroller. The CLK pin operates at a frequency of 32.768 kHz, which is the frequency of the crystal oscillator used by the module.
- DAT: This is the data pin, which is used to transfer data between the RTC module and the microcontroller. Data is transferred in a serial format using a three-wire interface, with the DAT pin acting as both the input and output pin.
- RST: This is the reset pin, which is used to reset the RTC module and put it in a known state. The RST pin is active low, which means that it must be pulled to the ground to reset the module.
Applications:
- Digital Clock: The DS1302 module can be used to build a digital clock that displays the current time and date. It can be easily interfaced with a microcontroller or display module to show the time on a digital display.
- Data Logging: The module's built-in clock can be used to timestamp data logs, such as temperature or humidity readings, for analysis and visualization later on.
- Security Systems: The module can be used in security systems to maintain accurate timekeeping for access control or alarm systems.
- Industrial Automation: The module can be used in industrial automation applications where precise timing is required for controlling machines, production lines, or other processes.
- IoT Devices: The module can be used in Internet of Things (IoT) devices to keep track of time and synchronize data across different devices.
Circuit:
Connect the clock pin of the DS1302 RTC module to Arduino pin 6, the data pin to pin 7, and the reset pin to pin 8. Then, upload the code to your Arduino board and open the Serial Monitor at 9600 baud. You should see the current time printed every second on the serial monitor.
Library:
To use the DS1302 library in your Arduino IDE, you'll need to install it first. Here's how you can do that:
- Download the DS1302 library from the author's GitHub page: https://github.com/msparks/arduino-ds1302
- In the Arduino IDE, go to
Sketch
>Include Library
>Add .ZIP Library...
- Navigate to the location where you downloaded the library and select the
DS1302-master.zip
file. - Click
Open
and the library will be installed.
Code:
example Arduino code that uses the DS1302 RTC module to print the current time every second on the serial monitor:
Note that this code assumes that the RTC module is already set to the correct time. If the module is not set to the correct time, you will need to set it manually using the rtc.setTime()
function before running this code.
#include "DS1302.h" // Initialize the DS1302 RTC module with the clock, data, and reset pins connected to pins 6, 7, and 8, respectively DS1302 rtc(6, 7, 8); void setup() { Serial.begin(9600); rtc.halt(false); // Set the RTC to running mode rtc.writeProtect(false); // Disable write protection } void loop() { // Get the current time from the RTC Time t = rtc.getTime(); // Print the current time on the serial monitor Serial.print("Time: "); Serial.print(t.hour); printDigits(t.minute); printDigits(t.second); Serial.println(); // Wait for one second before printing the time again delay(1000); } // Helper function to print leading zeros for single-digit minutes and seconds void printDigits(int digits) { if (digits < 10) { Serial.print(":0"); } else { Serial.print(":"); } Serial.print(digits); }
The first line includes the DS1302 library in the sketch. The setup()
function initializes the serial monitor at a baud rate of 9600 and sets the RTC to running mode and disables write protection. The loop()
function gets the current time from the RTC using the rtc.getTime()
function, then prints the current time on the serial monitor using the Serial.print()
function. It also calls the printDigits()
function twice to print the minutes and seconds with leading zeros. Finally, the function adds a newline character to the output using Serial.println()
, then waits for one second using the delay()
function.
The printDigits()
the function is a helper function that checks if the argument is less than 10, and if so, prints a leading zero before the number. This is used to ensure that the minutes and seconds are always displayed with two digits.
Technical Details:
- Supply voltage: 3.3V - 5V DC
- Operating current: <1.5mA
- Standby current: <200nA
- Clock accuracy: ±2ppm (at 25°C)
- Time format: 24-hour or 12-hour with AM/PM indicator
- Timekeeping range: 1 January 2000 to 31 December 2099
- Time resolution: 1 second
- Backup power: CR2032 button cell (not included)
- Data retention: >10 years
- Communication interface: SPI or 3-wire interface (CE, IO, SCLK)
- Operating temperature: -40°C to +85°C
- Dimensions: typically around 42.7mm x 22.4mm x 11.5mm
Resources:
Comparisons:
The DS1302 and DS1307 are both real-time clock (RTC) modules, but they differ in their features and specifications. Here are some of the key differences between the DS1302 and DS1307:
- Communication interface: The DS1302 uses a 3-wire or SPI interface, while the DS1307 uses an I2C interface. This means that the DS1302 may require more pins to connect to a microcontroller, but it can be easier to use in certain situations where I2C is not available.
- Supply voltage: The DS1302 can operate at a lower supply voltage (3.3V) than the DS1307 (5V), which can make it a better choice for low-power or battery-powered applications.
- Timekeeping range: The DS1302 can keep time from 1 January 2000 to 31 December 2099, while the DS1307 can keep time from 1 January 2000 to 31 December 2100. This may not be a significant difference for most applications.
- Clock accuracy: The DS1307 has a higher clock accuracy than the DS1302, with a typical accuracy of ±2ppm at 25°C, compared to ±5ppm for the DS1302. This means that the DS1307 can keep time more accurately over longer periods of time and in a wider range of temperatures.