Official Hobby Components Online Store | Buy Electronic Kits, Components, Boards, Shields, Modules

DS1302 RTC Module: Keep Time in Battery-Powered Projects

DS1302 RTC Module: Keep Time in Battery-Powered Projects

By Official Hobby Components Online Store | Buy Electronic Kits, Components, Boards, Shields, Modules | Published: 2026-11-02

Category: How-to Guides

Learn how to wire a DS1302 real time clock module to Arduino, add a backup battery, and set the time so your project keeps accurate time even when power is removed.

Quick answer

Wire the DS1302 module to your Arduino using three signal lines plus power and ground, fit a fresh backup battery, then run a short sketch to set the time once. After that, the module keeps time on its own as long as the backup battery stays charged.

Why the DS1302 needs a backup battery and how it behaves

The DS1302 chip keeps its clock and calendar running from a small backup battery when main power is removed. That is what makes it useful for battery-powered or intermittently powered projects. The module you buy typically includes a battery holder, but the battery itself may or may not be included, so check the product listing before you assume you can just plug it in.

The DS1302 uses a simple three-wire serial interface (reset, data, and clock) rather than I2C, so it ties up three digital pins on your microcontroller. That is a trade-off: it is easy to wire and very inexpensive, but it is not as bus-efficient as an I2C RTC. It also stores the year as two digits, so you need to decide how your code will interpret the century.

What the DS1302 does and does not handle for you

The chip tracks hours, minutes, seconds, day of week, date, month, and a two-digit year. Its calendar automatically corrects for months with different numbers of days and for leap years, so you do not have to write that logic yourself. It does not correct for the century rollover, and it does not adjust for daylight saving time or time zone changes — your sketch has to do that if your project needs it.

Accuracy depends on the crystal and the battery voltage. The DS1302 is not a temperature-compensated module, so expect it to drift a little over time. For projects that need tighter long-term accuracy, a DS3231 is the usual alternative, but for many hobby projects the DS1302 is accurate enough and costs far less.

Step-by-step: wire, power, and set the DS1302

  1. Wire the module to your Arduino: Connect VCC to 5V (or 3.3V if your module is specified for it), GND to ground, and the three signal pins (RST, DAT, CLK) to three digital pins. A common mistake is swapping DAT and CLK; double-check the silkscreen labels before powering up. If the module does not respond, re-check that RST is actually toggled by your code — a floating RST line will make the bus appear dead.
  2. Fit and check the backup battery: Insert a fresh coin cell if your module has a holder and the battery is not pre-installed. Measure the battery voltage with a multimeter before relying on it; a weak cell will let the time reset when main power is removed. Some modules ship without a battery — confirm what is in the box before you plan a battery-powered build.
  3. Load a library and set the time once: Use a DS1302-compatible library for your board (for example, a common Arduino RTC library) and run its set-time example with the current date and time. Upload it once, then comment out or remove the set call so the clock is not reset on every boot. Leaving the set call active is the most common reason a project shows the same wrong time after every power cycle.
  4. Verify timekeeping across a power cycle: After setting the time, disconnect main power for a minute, reconnect, and read the time again. It should have advanced by roughly the elapsed time. If it reset to the default, the backup battery or its holder is the first thing to check. A clock that resets on power loss almost always points to the backup battery circuit, not the code.
  5. Handle the two-digit year and daylight saving in your sketch: Decide how your code maps the two-digit year to a full year (for example, treat 00–69 as 2000–2069) and add any daylight-saving or time-zone offset in software. The DS1302 will not do this for you. Write down your century rule in a comment so the next person reading the sketch does not have to guess.

Product facts

  • DS1302 Real Time Clock Module: The DS1302 real time clock module is a compact, battery-backed clock module with a 24-hour clock and a calendar that stores the year in two digits and corrects for month lengths and leap years. That built-in calendar handling means you can focus on your project logic instead of writing date arithmetic, and the compact size fits neatly into small enclosures.
    DS1302 Real Time Clock Module
    DS1302 Real Time Clock Module

Shop Related Products

DS1302 Real Time Clock Module

DS1302 Real Time Clock Module

$0.54 $0.83

Shop Now