If your module has DS3231M chip then according to datasheed this modification can only generate 1Hz signal on INT/SQW pin (3) and 32768Hz on 32kHz pin(1). I have several DS3231M's and checked it.

If your module has DS3231SN chip: I had a similar issue recently. Got 10 pcs of DS3231SN from ali. Soldered one IC to my board and discovered this problem. Luckily I had ZIF SO16 to DIP adapter and built a test-board, connected it to oscilloscope and tested all of them. Only 4 pcs of 10 was able to generate different signals (1024Hz, 4096Hz etc.) on SQW pin according to datashet. Also they generated stable 32768 Hz signal on 32KHz pin (pin 1).

Other 6(also marked as DS3231SN) gave only 1 Hz signal on SQW pin, all of them produced signal on 32 kHz pin (one IC generated about 35 kHz), one IC generated floating frequency signal on SQW pin (around 1500 Hz and it cant be changed). I think it's low quality fake IC's.

Answer from Paul on Stack Overflow
🌐
DroneBot Workshop
forum.dronebotworkshop.com › forums › inside the workshop › project corner
DS3231 RTC with EEPROM, Square wave and alarms.
February 11, 2020 - */ RTC.alarm(ALARM_2); RTC.alarmInterrupt(ALARM_1, false); /* Enable or disable an alarm "interrupt" which asserts the INT pin on the RTC. */ RTC.alarmInterrupt(ALARM_2, false); } /* enable/disable 1Hz square wave signal from RTC */ void setSqw(bool enable) { if (enable) RTC.squareWave(SQWAVE_1_HZ); else RTC.squareWave(SQWAVE_NONE); } /* sleep button-push handler set an alarm for ~1 minutes in the future put the micro-controller to sleep wait for clock interrupt when alarm fires */ void sleepButtonPush() { /* only accept first button push and filter out button bounce for a second (or more) */
Discussions

DS3231 Alarm Clock with SQW Interrupt
I spend weeks to configure how to enable the SQW pin on DS3231 RTC module for alarm triggering (noob me). More on reddit.com
🌐 r/arduino
8
2
January 3, 2024
How to set up one second interrupt/ISR for ds3231 RTC - Arduino Stack Exchange
I am able to set up one hz interrupts using millis and other timers, but would like to do it instead using the RTC I have attached (DS3231) I am not sure how I can do that. Can someone point me t... More on arduino.stackexchange.com
🌐 arduino.stackexchange.com
DS3231 RTC module SQW pin: High/low for extended time?
Hi, I wonder if anyone knows if it is possible to have alarm on the DS3231 RTC module that works by setting the SQW pin high and low for extended periods of time? I have used the DS3232RTC library to set interrupt alarms as talked about here Link and that worked just fine. More on forum.arduino.cc
🌐 forum.arduino.cc
15
0
November 22, 2020
Alarm interrupt and square wave.
Hi, I am trying to understand how the alarm interrupts work. So I created a simple example sketch. I am not really sure if the squareWave method plays a role. It appeared that setting it to SQWAVE_... More on github.com
🌐 github.com
26
December 26, 2014
🌐
GitHub
github.com › DuranioMakes › DS3231_RTC_SQW_1Hz_Interrupt
GitHub - DuranioMakes/DS3231_RTC_SQW_1Hz_Interrupt: Easy Real Time Clock Interrupt - How to Use the DS3231 SQW Pi · GitHub
This sketch has been modified to use the SQW output pin of the DS3231 as an external interrupt signal connected to pin 2 of the Arduino. This sketch configures the SQW pin of the DS3231 to output a 1Hz squarewave to trigger the Arduino to read ...
Starred by 2 users
Forked by 3 users
Languages   C++
🌐
Reddit
reddit.com › r › arduino › comments › 18xgage › ds3231_alarm_clock_with_sqw_interrupt
r/arduino - DS3231 Alarm Clock with SQW Interrupt
January 3, 2024 - the clock originally use Arduino ... user can use button to wake from sleep mode or when alarm is set, the SQW pin interrupt will trigger and keep firing until a button is pressed to turn the alarm OFF....
Top answer
1 of 4
4

This answer addresses the original question of why the interrupts didn't work. I happened to have a DS3231 lying around so I made up a test.


Interrupt vs pin number

First, this is wrong in your code:

attachInterrupt(rtcTimerIntPin, rtc_interrupt, RISING);

You need an interrupt number, not a pin number. This is correct:

  attachInterrupt (digitalPinToInterrupt (rtcTimerIntPin), rtc_interrupt, CHANGE);

I also made it a CHANGE interrupt so you get both the rising and falling pulse.


Pull-up resistor

Next, the 1 Hz output needs a pull-up resistor, so you should add that or make it INPUT_PULLUP like this:

  pinMode (rtcTimerIntPin, INPUT_PULLUP);

Testing

I used this library from Adafruit.

Adapting one of their examples, and putting in your interrupt code (with my modifications), it worked!

#include <Wire.h>
#include "RTClib.h"

RTC_DS3231 rtc;

const byte rtcTimerIntPin = 2;

volatile byte flag = false;

void rtc_interrupt ()
{
  flag = true;
}  // end of rtc_interrupt

void setup () {

  Serial.begin(115200);

  while (!Serial); // for Leonardo/Micro/Zero

  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }

  if (rtc.lostPower()) {
    Serial.println("RTC lost power, lets set the time!");
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  }

  // enable the 1 Hz output
  rtc.writeSqwPinMode (DS3231_SquareWave1Hz);

  // set up to handle interrupt from 1 Hz pin
  pinMode (LED_BUILTIN, OUTPUT);
  pinMode (rtcTimerIntPin, INPUT_PULLUP);
  attachInterrupt (digitalPinToInterrupt (rtcTimerIntPin), rtc_interrupt, CHANGE);
}

void loop () {
  if (flag) {
    digitalWrite(LED_BUILTIN, HIGH);    // flash the led
    delay(100);                         // wait a little bit
    digitalWrite(LED_BUILTIN, LOW);     // turn off led
    flag =  false;                      // clear the flag until timer sets it again
  }
}
2 of 4
1

Use this DS3231 library. It has a method to set the squarewave RTC.squareWave(SQWAVE_1_HZ)

🌐
Arduino Forum
forum.arduino.cc › projects › programming
DS3231 RTC module SQW pin: High/low for extended time? - Programming - Arduino Forum
November 22, 2020 - Hi, I wonder if anyone knows if it is possible to have alarm on the DS3231 RTC module that works by setting the SQW pin high and low for extended periods of time? I have used the DS3232RTC library to set interrupt alarms as talked about here Link and that worked just fine.
Find elsewhere
🌐
Last Minute Engineers
lastminuteengineers.com › ds3231-rtc-arduino-tutorial
In-Depth: Interface DS3231 Precision RTC Module with Arduino
January 20, 2026 - The DS3231 RTC module has 6 pins in total. The pinout is as follows: 32K pin provides a stable 32.768kHz square wave signal. This can be used as a clock reference for other devices if needed. INT/SQW is the Interrupt/Square Wave output pin.
🌐
GitHub
github.com › NorthernWidget › DS3231 › blob › master › Documentation › Utilities.md
DS3231/Documentation/Utilities.md at master · NorthernWidget/DS3231
By default when power is first applied to the DS3231, the INT/SQW pin is configured to operate in Interrupt mode.
Author   NorthernWidget
🌐
GitHub
gist.github.com › deveth0 › 796afa5d35a6c9d79e30008938d42e4e
Arduino Demonstration of an alarm triggered by a DS3231 RTC · GitHub
Thanks Alex. I do use D2 for the interrupt. If I remove the wire from SQW to D2, SQW is low and D2 has 5V. I reconnect. If I toggle D2 then “woke up this morning “ prints on serial monitor. Otherwise nothing else seems to happen. However the LED does blink and keeps blinking.
🌐
GitHub
github.com › JChristensen › DS3232RTC › issues › 5
Alarm interrupt and square wave. · Issue #5 · JChristensen/DS3232RTC
December 26, 2014 - Hi, I am trying to understand how the alarm interrupts work. So I created a simple example sketch. I am not really sure if the squareWave method plays a role. It appeared that setting it to SQWAVE_NONE sometimes caused the alarm not to g...
Author   JChristensen
🌐
Raspberry Pi Forums
forums.raspberrypi.com › board index › hardware and peripherals › device tree
DS3231 interrupt pin? - Raspberry Pi Forums
//EDIT: After hacking the driver ( https://github.com/V10lator/rpi-rt-linu ... c-ds1307.c ) the clock outputs a interrupt signal on the SQW pin. It's just way faster than 1 Hz and I don't know why. ... The dt-bindings for DS3231 that you linked to says that "interrupts" is an optional property.
🌐
Maker Guides
makerguides.com › home › inputs & sensors › alarms with real-time-clock ds3231
Alarms with Real-Time-Clock DS3231
February 9, 2026 - SCL and SDA are the pins for the I2C interface. The 32K and SQW are outputs for the 32kHZ clock signal and a programmable square wave signal. The SQW output can also be configured as an interrupt ...
🌐
techtutorialsx
techtutorialsx.wordpress.com › 2017 › 01 › 22 › esp8266-ds3231-1hz-square-wave-generator
ESP8266: DS3231 1Hz Square wave generator – techtutorialsx
January 25, 2025 - Additionally, we need to connect the square wave pin (SQW) of the DS3231 to the GPIO of the ESP8266 where we want the interrupt to be triggered.
🌐
GitHub
github.com › Erriez › ErriezDS3231 › blob › master › examples › ErriezDS3231SQWInterrupt › ErriezDS3231SQWInterrupt.ino
ErriezDS3231/examples/ErriezDS3231SQWInterrupt/ErriezDS3231SQWInterrupt.ino at master · Erriez/ErriezDS3231
// Create DS3231 RTC object · ErriezDS3231 rtc; · // SQW interrupt flag must be volatile · volatile bool sqwInterrupt = false; · · #if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) ICACHE_RAM_ATTR · #endif · void sqwHandler() { // Set global interrupt flag ·
Author   Erriez
🌐
Arduino Forum
forum.arduino.cc › projects › programming
DS3231: trigger INT/SQW for a certain duration - Programming - Arduino Forum
November 16, 2021 - Hello, I need to program two alarms to trigger the INT/SQW pin LOW and then HIGH for a certain duration. What I need: -keep INT/SQW LOW during at least 30ms (and maximum 2s) and then HIGH -keep INT/SQW LOW more than 2…
🌐
Dev-eth0
dev-eth0.de › 2017 › 09 › 18 › arduino-ds3231-alarm
dev-eth0.de - Use a DS3231 RTC to wakeup an Arduino
September 18, 2017 - There are multiple RTC (real-time ... RTC requires either 3.3V or 5V and uses I2C to communicate with the Arduino. The SQW pin needs to be attached to one of the interrupt pins of your Arduino (e.g....
Top answer
1 of 1
1

Question

How to use a 3V logic signal to switch on/off a P-Channel power MOSFET which in turn switches on/off a 5V power supply for Arduino, Rpi, or ESP32?


Answer

(1) I must first point that you don't use DS3231's Square Wave Signal to switch/trigger the power MOSFET or other devices. You use the interrupt signal.

(2) To switch/trigger a power MOSFET switch, either P-Channel or N-Channel can do the job, as shown in the following schematic.


Discussion, Conclusion, and Recommendation

(1) Using DS3231 to control the power MOSFET which in turn to switch on/off might not be a very solution. My usual trick is to use DS3231 interrupt to direct switch on/off the LM2596 PSU through its power on/off switch pin. See Appendix B for more details.

(2) Using P-Channel or N-Channel power MOSFET, High or Low side switching?

I usually prefer NPN BJT and N-Channel power MOSFET for switch, because (a) more EE guys prefer NPN and N-Channel so you will find more tutorials to follow, and circuits to copy, (b) N guys are more efficient, (c) In case you need to ground complicated circuits, N-Channel and NPN BJT low side switch can ground easier. On the other hand, high side mosfet switches "floats" in the air, so not so easy to make a common ground.

(2) The Sony 18650 tech spec is the best I can google.

(3) The OP's step up regulator is interesting. I bought one long time ago but never tried it, because my projects don't have any space problem. I usually use 18650 x3 or even x4 and step down to 5V. The switching power supply regulator has a very high, or 90% efficiency, so your PSU does not loses that much energy, but lasts 3 or 4 times longer.

(4) I think the OP's design is very good. My suggestions are a bit subjective. The OP need to do engineer trade offs and cost benefit/risk analysis. It is a good learning experience and fun trying different approaches, compare and contrast.


References

(1) IRF9540, SiHF9540 P-Channel Power MOSFET (Vgs(th) = -2V min, -4V max, Rs(on) = 200mΩ @Vgs -10V) datasheet - Vishay

(2) DMP2008UFG P-Channel Power MOSFET (Vgs(th) = -0.4V min, -1.0V max, Rs(on) = 17mΩ @-8.3A) datasheet Diodes

(3) Sony 18650 Lipo Battery Spec

(4) Amazon USB DC-DC Converter 0.9V - 5V Boost to 5V 600MA Step Up Power Supply Module

(5) DS3231M ±5ppm, I2C Real-Time Clock Datasheet - Maxim


Appendices

Appendix A - DS3231 Testing Notes

I am reading my old post to show (1) how to use Rpi OS's DS3231 DT drivers and also (2) basic python program for setting up and also how the program the interrupt for alarming external devices as asked by the OP. I have also used a scope to display the DS3231 1Hz and 32kHz wave forms and found them a bit noisy.

Rpi3B DS3231 pythonProgramming Notes

(1) https://www.raspberrypi.org/forums/viewtopic.php?f=37&t=77158&p=1350076&hilit=DS3231+tlfong01#p1349687

(2) https://www.raspberrypi.org/forums/viewtopic.php?f=37&t=77158&p=1349937&hilit=DS3231+tlfong01#p1350076

(3) https://www.raspberrypi.org/forums/viewtopic.php?f=37&t=77158&p=1349937&hilit=DS3231+tlfong01#p1349687



Appendix B - Using DS3231 interrupt signal to switch on LM2596 PSU for Rpi

Using High/Low side power MOSFETs to switch on off PSU might not be a very good solution. One trick I always use is to use DS3231 interrupt signal to switch on/off the LM2596 PSU, or using the interrupt to switch on LM2941 current switches.


Rpi freezes every now and then, how to fix it with a watchdog?

I modify ordinary DC-DC (12V to 5V) PSUs' so that any Rpi or MCP23x17 GPIO pins can power on/off the LM2956/LM2947 voltage regulator chip of the PSU. (LM2941 can be used for 1A current switches, LM2596 for 5V 3A PSU. The on/off pin is also connected to a push button, for manual power on/off testing.)

Actually each of my 7 Rpi3B+'s is connected to a cheapy DS3231 Real Time Clock Module which has a hardware interrupt pin to reset PSU, Rpi, or other devices.

Now the external DS3231 RTC wakes up everybody in the morning, and switches off lights at midnight, so everybody goes to bed.


End of Answer

🌐
GitHub
github.com › JChristensen › DS3232RTC › issues › 19
Interrupts from DS3231 · Issue #19 · JChristensen/DS3232RTC
January 6, 2016 - Per the documentation, shouldn't the SQW pin go low when an alarm interrupt occurs? Per your API, I've set up repeated alarms like so: RTC.setAlarm(ALM2_EVERY_MINUTE, 0, 0, 0, 0); RTC.alarmInterrupt(ALARM_2, true); This works well by jus...
Author   JChristensen