In another thread a question came up about modding the DS3231 ZS-042 module so it can be used to switch circuit power. So I decided to post separately to make future searches easier. Here's the story:
The INT/SQW pin of the DS3231 RTC can be used to switch circuit power on at the pre-set alarm time. That pin is open drain, and goes low when the alarm triggers. That action can then turn on a P-channel mosfet which controls power to the entire circuit. This may be better for battery life if there are parts of the circuit that cannot effectively be put to low-current sleep. Here is a schematic showing such a power switching circuit:
The DS3231 typically comes in a "ZS-042" module which also includes an EEPROM and a backup coin cell. Three or four modifications may be needed to make the module work well, or at all, in controlling power. Three can be done by cutting traces. The modifications are shown in red in this schematic of the module:
The most important mod is disconnecting the pullup resistor from the INT/SQW pin. That resistor is connected to the module's Vcc pin, but when power is shut off, there will be no voltage there. So the pullup resistor may become a pulldown resistor, and power would be turned back on prematurely. The solution is to disconnect the pullup resistor. The G/S resistor on the external mosfet will take its place, and it will always be pulled up high.
The ZS-042 has a "battery charging" circuit that was useful when it came with a rechargeable lithium cell, the LR2032. The primary CR2032 lasts a long time, so the LR2032 is rarely used anymore in this module. It doesn't make sense to apply charging voltage to a primary cell, so the charging circuit needs to be disabled if a CR2032 will be used.
The module comes with a power indicator LED that just wastes power. So it's better to disable it. I had removed the LED's resistor to do that, but the picture shows where to cut the trace instead.
The INT/SQW pin can tolerate only up to 5.5V, but if a higher voltage source will be used, such as a 12V battery, a two-stage circuit will be needed. That circuit requires connecting the N-channel mosfet gate to the positive terminal of the coin cell. I don't have a picture, but it just involves soldering a wire to the coin holder's positive terminal. This would be a high-voltage circuit:
This circuit works because the INT/SQW pin stays low after the alarm triggers until the alarm flag bit is reset. The Arduino powers up and does its thing, then turns on Vcc to the DS3231 and sets the next alarm time. (You must have power at the module's Vcc pin to communicate because the pullup resistors on SDA and SDL connect to Vcc.) Then the processor sends the command to clear the alarm flag, and the power shuts down. Some DS3231 libraries have the bad habbit of clearing the alarm flag automatically as a part of other processes, such as setting the next alarm time. If so, it may be necessary to modify the library code.
The choice of P-channel mosfet will depend on the battery voltage and the circuit's current requirements. For the N-channel mosfet in the high-voltage circuit, I believe a 2N7000 or BS170 would work ok, but something with a threshold voltage closer to 1V might work better as the coin cell voltage drops over time. I believe there are complimentary pair P-channel and N-channel mosfets in a single package that would be perfect for the high-voltage circuit. Hopefully someone will post some part numbers.
For the low-voltage circuit, the P-channel mosfet could be a DMP1045U or something similar with very low threshold voltage and low on-resistance.
For the high-voltage circuit, the P-channel doesn't need to be logic level, but should have a GS maximum of 20V, and low on-resistance. An IRF9540 would work.
And the BSS138 would work for the small N-channel mosfet.
Since it is a tutorial and not a question. It should be in the Tutorial section.
Click on the flag at the bottom of your original post to contact a moderator. Ask them to move it for you.