Go Down

Topic: ATMega328p sleep mode with RTC3231 power consumption (Read 899 times) previous topic - next topic


  Please see the attached image for my RTC DS3231 Module.


Those pictures of the board look like vendor supplied photos. Is your module EXACTLY this module?
There are many vendors selling boards like that look similar but are not the same.
Many of the RTC modules like that have a h/w issue on them but to know if your RTC requires modification, and where/how to do the modification it is critical that we seeing the EXACT module you have. Close is simply not good enough when dealing with things at this level.
This is why I'm asking for EXACT information about your h/w and software.

You are still not providing the information being asked for and as you can see several people are starting to get very frustrated and starting to lose interest in helping you.

The key thing about RTC modules like that is that it has a charging circuit for a LiPo battery.
Many of the vendors ship the RTC with a CR2032 instead of the LiPo LIR2032 battery because it is cheaper.
The bad thing about charging circuit on that type of module is that it is a bad circuit and causes problems as it is too simple to really work properly.

There is a simple way to disable the charging circuit but we need to know which module you have to be sure that the module has the issue and then how to modify it.

I too am tiring of asking for information about your h/w and s/w.
Please provide what is being asked for.
* an EXACT schematic of what you have wired up.
   What you have shown us so far doesn't make sense and cannot be what you have wired up.
   A photo of your current h/w might be helpful
* photos of YOUR RTC module.
* the exact code you are running.
* the serial output to be able to see if the RTC control register BBSQW bit is set

please provide all of this.
I'll respond again, when I can see all of this information.

--- bill


Sure bperrybap,
       I am thank full to you, that you are helping me, the RTC Module picture what i have sent is the exact same of my module that is zs-042 and with the battery of LIR2032 thats why i have sent that vendor image itself so that you can able to see clearly. and regarding the schematic i said that i am not a electronic student bro, the schematic which i have posted  is created with fritzing, that means when i create the breadboard diagram same like which i  have in physical that schematic is automatically created by fritzing, if its were wrong i dont know how to correct it, so only i have also attached the breadboard connected image also, with that you can get idea. or i will send all the below details bro for you

1) will send the live breadboard connection image
2) will send the code running in the atmega328
3) will send the libraries used and with the url reference
4) will send the photo of the RTC
5) will send the serial output of RTC to check BBSQW


Hi Bperrybap,
    Sorry for the late reply, please check the below details for my problem, i have given all the details what i have and also attached the live demo video link please check and help me on this.

See the below code, its working perfectly and no problem at all, but when arduino and servo is on power down mode only RTC is running and it consumes 1.2mA current, but DS3231 datasheet says that it will consume only in the range of uA, i have also removed power led and its resistor, charging diode and its resistor(before removing diode and resistor it has been consumed more tha 1.8mA so i need a solution for this to reduce the 1.2mA current drain by my RTC. because the system wakes only on every 2hrs and do its operation for about 10sec.

Library Used Files Links(Download) :-

DS3231 - https://drive.google.com/file/d/0B-I2VNmwkPf2bHBYMXF4R0hER0U/view?usp=sharing
Lowpower - https://drive.google.com/file/d/0B-I2VNmwkPf2SUpxWFZRZFJ5TXM/view?usp=sharing
Streaming - https://drive.google.com/file/d/0B-I2VNmwkPf2OG9ubHIzRzgtUGc/view?usp=sharing
Time - https://drive.google.com/file/d/0B-I2VNmwkPf2THc5b184VzAydDQ/view?usp=sharing
VarSpeedServo - https://drive.google.com/file/d/0B-I2VNmwkPf2eHRNM3IyY3RaaFU/view?usp=sharing

Library Used References Links :-

DS3231 - http://github.com/JChristensen/DS3232RTC
Lowpower - https://github.com/lowpowerlab/lowpower
Streaming - http://arduiniana.org/libraries/streaming/
Time - http://playground.arduino.cc/Code/Time
VarSpeedServo - https://github.com/netlabtoolkit/VarSpeedServo

Images Of Project :-


Image Of BBSQW Result :-


Live Video Of Project :-


Code: [Select]

#include <DS3232RTC.h>        //http://github.com/JChristensen/DS3232RTC
#include <Streaming.h>        //http://arduiniana.org/libraries/streaming/
#include <Time.h>             //http://playground.arduino.cc/Code/Time
#include <Wire.h>             //http://arduino.cc/en/Reference/Wire
#include <LowPower.h>         //https://github.com/lowpowerlab/lowpower
#include <VarSpeedServo.h>    //https://github.com/netlabtoolkit/VarSpeedServo

#define SQW_PIN 2

VarSpeedServo myservo;
volatile boolean alarmIsrWasCalled = false;
int led_pin = 13;
//int rtc_power_pin = 7;
int servo_power_pin = 6;

void setup(void)

    pinMode(led_pin, OUTPUT);
    digitalWrite(led_pin, LOW);
    pinMode(servo_power_pin, OUTPUT);
    Serial << "RTC Sync";
    if (timeStatus() != timeSet)
      Serial << " FAIL!";
    Serial << endl;

    attachInterrupt(INT0, alarmIsr, FALLING);

    //Set an alarm at every 20th second of every minute.
    RTC.setAlarm(ALM1_MATCH_SECONDS, 20, 00, 0, 1);
    RTC.alarmInterrupt(ALARM_1, true);

    //Set an alarm every minute.
    RTC.setAlarm(ALM2_MATCH_MINUTES, 00, 59, 0, 1);
    RTC.alarmInterrupt(ALARM_2, true);

    Serial.print("RTC_CONTROL: ");
    Serial.print(RTC.readRTC(RTC_CONTROL), HEX);

void alarmIsr()
    alarmIsrWasCalled = true;

void loop(void)
    Serial << endl;
    if (alarmIsrWasCalled){
        if (RTC.alarm(ALARM_1)) {
             digitalWrite(led_pin, HIGH);
             digitalWrite(servo_power_pin, HIGH);
             myservo.write(0, 30, true);
             myservo.write(180, 30, true);
             digitalWrite(led_pin, LOW);
             digitalWrite(servo_power_pin, LOW);
        if (RTC.alarm(ALARM_2)) {
           //need to write some logic
        alarmIsrWasCalled = false;
        LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);

void printDateTime(time_t t)
    Serial << ((day(t)<10) ? "0" : "") << _DEC(day(t)) << ' ';
    Serial << monthShortStr(month(t)) << " " << _DEC(year(t)) << ' ';
    Serial << ((hour(t)<10) ? "0" : "") << _DEC(hour(t)) << ':';
    Serial << ((minute(t)<10) ? "0" : "") << _DEC(minute(t)) << ':';
    Serial << ((second(t)<10) ? "0" : "") << _DEC(second(t));


A schematic of your circuit would be nice to have (you didn't provide one) but since you provided photos, it can pretty much be derived.

Little details really matter.
Not that it matters now, but you had told us that the RTC module contained a LIR2032 but the photos show a module with a CR2032.

Are you really powering your circuit with 4 AA batteries in series like the fritzing diagram is showing?
6v is too much voltage.
Beyond that, the biggest thing I notice is that it seems that what you have hooked up right now is not matching what you previously told us you had connected.

This s/w and h/w is not attempting to turn off the power to the RTC to put it into lower power mode.
And from the photos, there is no wire connecting D7 to the RTC.

In looking at the actual schematic for that RTC module there are some design issues that prevent you from using it "as is" for your application.
The LED (for power), and the charging circuit (which was a bad/broken design) have already been removed but there are some VCC and pullup issues that still need to be resolved.

Here is a link to page with lots information on the subject:
There is lots information there including a schematic of your RTC module and links to other places with additional information.
It is pretty dense so take your time reading.

The key thing to note is about the pullups.
What complicates things is that they are needed but in your application you are using dual voltages for the RTC module (module VCC and backup battery)
The RTC module has pullups on it for i2c and for SQW. These pullups are connected to the RTC module VCC which creates a problem when you use an arduino pin to power the module since when you turn off the power to the RTC module VCC by grounding the signal (which is required to push the RTC into low power mode), the RTC module pullups will now be pull downs since they are now connected to ground.

The page above talks about this and how you will need to make some additional changes to the RTC module in order to be able to power it down and use the SQW signal.
They are not difficult but are required because the module was not designed to be used in lower power mode.

In your case, you can use the AVR internal pullup so no external pullup will be needed on the SQW pin.
Also, the AVR has pullups on the SDA and SCL pins. While they are WAY out of spec, they often do work and it may be worth a try to see if it works without external pullups on the i2c bus signals.
While it most likely will work ok without external resistors on the I2c bus signals using only the internal AVR pullups, keep in mind that it is out of spec so there maybe issues depending on the main battery level, the length of the wires used, and the temperature, so for maximum reliability, you may want to use a pair of 10k resistors.

You also need to address the transistor that you are using to power your servo.
As I mentioned in response #42, you cannot use a 2222 transistor the way you are trying to use it.
The way you are using it can damage the AVR or the transistor.
A NPN transistor works by turning on a switch between collector and emitter when current flows between the base and the emitter.
The important thing to keep in mind is that NPN transistors are current driven. It takes current into the base to turn on the "switch" and the more current you need to switch between collector and emitter, the more current you have to push into the base but you do have to limit the current. The way you have it wired up now, you are not limiting the current so it is overloading the AVR pin.
You need a resistor between the AVR pin and the base transistor pin a 1k resistor would probably be fine.
Keep in mind that the needed current that flows into the base of the transistor is wasted.

Alternatively you could switch to a FET transistor like 2N7000
These work on voltage rather than current.
When you apply a voltage to the gate pin, it turns on the switch between the drain pin and the source pin.

You hook it up like this:
(Device VCC signal connects to VCC)
 (Device GND signal)------------+
 (Arduino Pin)-------------G-|-< (2N7000 FET)

This works the way you were assuming the 2222 worked but it doesn't use/waste any current so it is more power efficient than the 2222.
Not sure where you get parts from but I've been happy with this place for low volume low cost parts like this:

Also, when you add back in the code to turn the power to the RTC module on/off you will need to turn it back on when you wake back up.
The older code that you had was not doing this. While the RTC will work with i2c when running off battery its battery backup power, that isn't what you wanted since I assumed you wanted it to use the main power when being accessed.

Hope that helps.
You are slowly being dragged into the world of having to understand the low level hardware.  :)

--- bill


I have not read all the responses above but it looks like all my observations on the circuit have already been covered apart from one:

The servo negative line is switched, switching it off means the electronics inside the servo will then all be at the +ve battery voltage, but I suspect the servo signal pulse pin is still at 0V because the servo detach only stops pulsing the pin, I suspect it leaves it an output at logic 0. This would mean there is a parasitic current path through the servo +ve power line into the pulse drive pin of the ATmega328.  The current flowing will be dependent on the servo internal electronics design (with lucK it may be AC coupled...), but in any case this is very bad design practice...

In your case the simplest solution is to turn the servo pulse pin into an input immediately after switching off the servo power, then that signal pin can float up to the rail with the internal servo electronics. When the servo is attached again the pin will be switched to an output. A 1K series resistor in this line would be a good idea to protect against any high parasitic currents damaging the ATmega328.


Today at 12:44 am Last Edit: Today at 02:34 am by rowboteer
Edit - deleted some points as I notice pullups and the SQW line being open drain (can pull down only) has already been covered by Bill...

If you use the Sparkfun module as featured in the Fritzing diagram in post #27 then you would not have the higher than wanted powered down current as that module makes use of the internal pullup of the ATmega, hence the RTC can be fully switched to battery power and still generate interrupts. So you will need to do a bit more hacking of the module you have (as Bill has pointed out).

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131