The DS3231 is best known as a highly accurate real-time clock, but it also includes useful alarm and interrupt functions. These features allow the RTC to signal a microcontroller when a specific time is reached, making it useful for low-power systems, scheduled events and wake-up functions.
This article explains how DS3231 alarms work and how they can be used in embedded projects.
Why Use RTC Alarms?
Instead of keeping a microcontroller awake all the time to check the clock, an RTC alarm can trigger an interrupt only when needed.
- Reduces power consumption
- Allows precise scheduled wake-up
- Useful for battery-powered systems
- Works even while the main microcontroller sleeps
This makes RTC alarms especially useful in low-power designs.
DS3231 Alarm Overview
The DS3231 includes two independent alarms:
- Alarm 1
- Alarm 2
Both alarms can generate an interrupt output when their configured condition matches the current time.
Alarm 1
Alarm 1 is the more flexible of the two alarms.
- Can match seconds, minutes, hours and date/day
- Can trigger once per second, once per minute, hourly, daily or on a specific date/day
Because it includes seconds, Alarm 1 is useful when fine timing is required.
Alarm 2
Alarm 2 is similar, but does not include seconds.
- Can match minutes, hours and date/day
- Can trigger once per minute, hourly, daily or on a specific date/day
Alarm 2 is useful for less frequent events such as periodic wake-ups or daily schedules.
Interrupt Output Pin
The DS3231 provides an interrupt/square-wave output pin, commonly labeled INT/SQW.
- Can output square wave signals
- Can act as alarm interrupt output
- Typically open-drain output
When using the alarm function, this pin can be connected to a microcontroller interrupt input.
How the Alarm Interrupt Works
When an alarm condition matches the current time, the DS3231 sets an internal alarm flag and pulls the interrupt output active.
- Alarm condition occurs
- Alarm flag is set
- INT/SQW pin changes state
- Microcontroller wakes or responds
The microcontroller must clear the alarm flag after handling the event.
Important: Clear the Alarm Flag
One of the most common mistakes is forgetting to clear the alarm flag after an interrupt.
- If the flag is not cleared, the interrupt may remain active
- The next alarm may not behave as expected
Good RTC libraries usually provide a function to clear the alarm.
Typical Alarm Use Cases
Wake Up a Sleeping Microcontroller
- MCU enters deep sleep
- DS3231 continues running
- Alarm triggers interrupt
- MCU wakes and performs task
Scheduled Data Logging
- Wake every minute, hour or day
- Read sensors
- Store data
- Return to sleep
Clock and Timer Functions
- Daily alarm clock
- Timed switching
- Scheduled display updates
Alarm Modes
| Function | Alarm 1 | Alarm 2 |
|---|---|---|
| Once per second | Yes | No |
| Once per minute | Yes | Yes |
| Hourly alarm | Yes | Yes |
| Daily alarm | Yes | Yes |
| Specific date/day | Yes | Yes |
| Second-level precision | Yes | No |
Using Alarms with Arduino Libraries
Many DS3231 libraries support alarm configuration, but the exact function names differ between libraries.
- Set alarm time or match condition
- Enable alarm interrupt
- Attach microcontroller interrupt
- Clear alarm flag after trigger
Always check the documentation of the library you are using.
INT/SQW Pull-Up Resistor
The interrupt output is usually open-drain, which means it requires a pull-up resistor.
- Some modules already include a pull-up
- Typical external value: 4.7 kΩ to 10 kΩ
- Pull up to the microcontroller logic voltage
This is important when using the DS3231 with 3.3V controllers such as ESP32, RP2040 or XIAO boards.
Square Wave vs Alarm Output
The INT/SQW pin can be used either as a square wave output or as an alarm interrupt output.
- Square wave mode: outputs fixed frequency
- Alarm mode: signals alarm events
For wake-up and scheduled events, alarm interrupt mode is usually preferred.
Common Mistakes
- Forgetting to clear the alarm flag
- Using the wrong alarm mode
- Not providing a pull-up resistor
- Confusing square wave output with alarm interrupt output
- Not handling time zones or DST in scheduled events
Best Practices
- Use Alarm 1 when seconds matter
- Use Alarm 2 for minute-level scheduling
- Clear alarm flags immediately after handling
- Use RTC alarms to wake sleeping microcontrollers
- Test alarm behavior carefully before using it in unattended systems
Conclusion
The DS3231 alarm and interrupt functions make the chip much more than a simple timekeeping device. They allow efficient scheduled operation, low-power wake-up and reliable event timing.
For battery-powered clocks, data loggers and automation projects, RTC alarms are one of the most useful features of the DS3231.
