Source: https://mokxi.com/parts/ds1302
Updated: 2026-11-18

Part

# Real-time clock, DS1302

The kit clock with a coin cell: BCD time and 31 bytes of RAM behind CLK, DAT and RST.

See every part

- 5 pins
- 2 settings
- In 1 project
- In 1 lesson

Drawn live by the editor's own code, at the size you see it.

At a glance

## The Real-time clock, DS1302 in brief

What it is, and every setting the properties panel gives it.

The DS1302 is a real-time clock module with a coin cell and a watch crystal. It talks over a three-wire interface of its own: a clock pin, a data line and an enable. It keeps seconds, minutes, hours, date, month, day of the week and year in BCD, plus 31 bytes of RAM. Mokxi models the transfer rules from the datasheet: RST high starts a transfer, a command byte arrives least significant bit first on rising CLK edges, and data comes out on falling edges. Burst mode walks all eight clock registers or all 31 RAM bytes, write protect blocks other writes, and the hours register supports the 12-hour form with a PM bit. Each of the three pins has about 40 kohm pull-downs inside the chip. It does not model the trickle charger, the backup cell, or the undefined state of a new chip. The model starts at the start time with write protect off. Aliases: DS1302, RTC module, three-wire clock.

Family

Clocks and links

Pins

5

start

2026-01-01 12:00:00

halted

false

Pins

## 5 pins

Named as the editor names them, so a wire lands where you expect it.

Pin

What it does

VCC

Supply, 2 V to 5.5 V.

GND

Ground.

CLK

The serial clock (SCLK).

DAT

The data line (I/O), both ways.

RST

The enable (CE): high for a transfer.

How to use it

## How to use the Real-time clock, DS1302 with an Arduino

The example project is "Alarm clock". A DS1302 keeps the time and a TM1637 shows it. At 7:00 a piezo beeps until the button stops it. It runs beside these words, and it opens in the editor as it is drawn here.

The wiring: CLK goes to Arduino Uno pin 5, DAT to pin 4, RST to pin 2, VCC to 5V and GND to GND.

With the default settings, the serial monitor shows "Mokxi Arduino Uno: alarm clock", then "6:59:50", "6:59:51" and "6:59:52". The clock module was set to 6:59:50, so the alarm goes off ten seconds after Run.

Change the setting halted to true and run again. The monitor now shows "Mokxi Arduino Uno: alarm clock", then "clock was stopped: starting it", then "6:59:50", "6:59:51" and "6:59:52". The sketch noticed the halted clock and started it before reading the time.

Part pin

Goes to

CLK

Arduino Uno R3 pin 5

DAT

Arduino Uno R3 pin 4

RST

Arduino Uno R3 pin 2

VCC

Arduino Uno R3 pin 5V

GND

Arduino Uno R3 pin GND

Hold the button

This is the simulator itself, running here. Click anything to open it in the editor.

Open this project in the editor Read the full tutorial

sketch.ino · Arduino Uno R3 · the first 45 lines

Common errors

## Common Real-time clock, DS1302 errors and fixes

What goes wrong

The fix

Wiring it like an I2C clock.

The DS1302 is not on the I2C pins. Any three digital pins will do.

Mixing up the order in ThreeWire.

It is the data pin, then the clock, then the enable: ThreeWire myWire(4, 5, 2).

Writes do not stick because write protect is on.

Clear bit 7 of the control register first, as in Rtc.SetIsWriteProtected(false).

The clock stays stuck and the sketch prints it was stopped.

Start it in code with Rtc.SetIsRunning(true), or leave halted at false in the settings.

Questions

## Questions and answers

### how do i connect a ds1302 to arduino

Use any three digital pins. In the example, CLK goes to pin 5, DAT to pin 4 and RST to pin 2, plus 5V and GND.

### does ds1302 use i2c

No. The DS1302 uses its own three-wire interface with a clock, a data line and an enable. Any three pins will do.

### what library for ds1302 arduino

Rtc by Makuna. Include ThreeWire.h and RtcDS1302.h, then write ThreeWire myWire(DAT, CLK, RST); and RtcDS1302<ThreeWire> Rtc(myWire);

### why is my ds1302 clock not running

The clock-halt bit may be set. Start it in code with Rtc.SetIsRunning(true), or set halted to false in the editor.

How it is modeled

## What is true about the Real-time clock, DS1302, here

In its help article’s own words: what the simulation gets right, and where it stops.

### Modeled

From the DS1302 datasheet:

The transfer. RST high starts it and low ends it. A command byte comes first,
least significant bit first, each bit taken on a rising edge of CLK; bit 7 must be
1, bit 6 picks RAM, bits 5 to 1 the address and bit 0 a read.

Reads. The data comes out on the falling edges, starting with the falling edge
that ends the command, so a sketch lets go of DAT before then.

Burst mode. Address 31 walks all eight clock registers, or all 31 RAM bytes, in one
transfer; a clock burst write is taken only once all eight are in.

Write protect. Bit 7 of the control register, set, blocks every other write.

The hours. Bit 7 of the hours register is the 12-hour form (bit 6 on the DS1307),
with bit 5 for PM.

Pull-downs. About 40 kohm on each of the three pins inside the chip.

### Not modeled

The trickle charger (its register is stored and read back), the backup cell, and the
undefined state of a brand-new chip: the model starts at start, with write protect
off.

From Real-time clock, DS1302, in full.

Projects

## See the Real-time clock, DS1302 in a project

One built-in project uses it. It opens in the editor, already wired.

Lessons

## Where it turns up in a lesson

One lesson places it in its own circuit.

### Learn articles

1 lesson

- Arduino DS1302 RTC: an Alarm Clock With Code

Boards

## The boards it is shown on

This board has a built-in project with the Real-time clock, DS1302 in it.

- Arduino Uno R3

Keep going

## Keep going

- Real-time clock, DS3231
- Real-time clock, DS1307

More parts

## The rest of the bench

Every one of these is drawn and simulated the same way.

Full-size breadboard

A real 0.1 inch grid with the rails and the center channel, 63 columns wide.

Jumper wires

Drag from any pin or hole to any other. Corners snap, and you can drag them.

Power

A supply rail at the voltage you choose.

Ground

The other end of every circuit.

LED

Lights when current flows. Five colors, and the brightness is what your eye would see.

Filament lamp

A tungsten bulb in a holder: an inrush when it is switched on cold, tens of milliseconds to warm up, and dim on half its voltage.

Resistor

Any value you like, with the color bands drawn to match.

ESP32-C3-DevKitM-1

A RISC-V board that runs your firmware at 160 MHz on the real memory map.

Pushbutton

A 12 mm tactile switch. Hold it while the simulation runs.

Raspberry Pi Pico

The RP2040 board on our own Cortex-M0+ core. Pick a program and press Run.

Raspberry Pi Pico W

Raspberry Pi Pico W (RP2040). The same board and the same pinout as a Pico, with the CYW43439 on it. The WiFi is simulated (no radio; real internet through the Cloud panel’s switch), and the on-board LED, which hangs off that chip rather than off GP25, is driven through the same path. Everything else is the Pico.

Raspberry Pi 4 Model B

Raspberry Pi 4 Model B: the 40-pin header, driven by main.py with RPi.GPIO or gpiozero.

See every part

## Wire up the Real-time clock, DS1302

Open the editor and push it into the breadboard. It is free, and it runs on your own machine.

Start building free Open the editor
