Will this capacitor damage my output pin?

I'm trying to get my head around how fast this capacitor will charge, and what current it will draw:

Basically the idea is to turn on the DS1307 clock chip, as required to read the time. Then to turn it off again using a digital pin as the "power" pin, like this:

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

const byte POWER = 8;


void setup () { }

void loop () {
  delay (1000);

  // power up clock chip
  pinMode (POWER, OUTPUT);
  digitalWrite (POWER, HIGH);
  // wait for it to be read
  delay (5);
  // talk to it
  // get time
  DateTime now = RTC.now();

  // do something with the time
  // drop power to chip
  pinMode (POWER, INPUT);  
  digitalWrite (POWER, LOW);  // turn off pull-up

  // turn off I2C
  TWCR &= ~(_BV(TWEN) | _BV(TWIE) | _BV(TWEA));
}  // end of loop

I think someone said a while back that the 0.1uF capacitor (which is the decoupling capacitor on the clock board) might drain too much current for the good of the digital pin.

  • Is that true?
  • How do I calculate exactly how much it would drain?
  • Can I "save" my pin in some way, like a small series resistor? If so, what value?
  • Or would a MOSFET as the "power switch" be indicated?

I've been looking at some web sites about the charge rate of capacitors, and they talk about "the series resistor" which is part of the equation. But there is no resistor there. Is there an implied one, like the ESR of the capacitor? Or something else?

Also I seem to be getting "reverse" current back from the capacitor when the digital pin switches off and the capacitor discharges.

  • Is that bad?
  • Should I put a diode there to drain this current?

Thanks for any advice.


What is the purpose of the capacitor? I read your post and you are trying to turn on a chip but I didn't see why you need that capacitor. Maybe for voltage stabilization?

I glanced at the doc and didn't find a DC resistance of each pin. Without a serial resistor, the capacitor will pull a large current, initially equal to 5V/DC resistance of the pin. That is what I guestimate. So to maintain the current below 20mA, you need a resistor between pin 8 and the junction made by the 3 wires. So 5V/20mA=250ohm. When the capacitor is fully charged, its voltage will be 5V and there's no voltage drop on the resistor. If you switch on the chip with pin 8, do you know the maximal current draw of the chip? Should be in spec sheet. If that is greater than 20mA, the max of arduino pin (fig. 30-350 in doc), then you may need a MOSFET as a switch. It seems to me a bit tricky since the chip has a backup battery at 3.3V. You will have to sandwich the chip 5V and GND between the MOSFET and 5V. MOSFET source pin is connected to GND, gate pin to pin 8, drain pin to the chip GND. If you already have the GND of the chip connected to common GND, you have to disconnect it. That's what I think. See if others can comment on my method.

The capacitor actually never finishes charging but here's the fomula:

With prolonged use, I think that might well damage the output pin. Even when driving the gate of a power mosfet with about 50 times less capacitance, a series resistor is recommended. The active current for the DS1307 is specified as 1.5mA maximum, so I think you can add a series resistor of e.g. 220 ohms between the pin and the capacitor/DS1307 and still provide enough voltage to supply the DS1307. Make sure you allow enough time between setting the pin high and reading the clock for the capacitor to charge.

What is the purpose of the capacitor?

I didn't put it there, but I gather it's a decoupling capacitor between Vcc and Gnd.

Indeed it is. I have no basis for saying this, but I really don't know how much sleep I'd lose over it. I have several of those RTCs from AFI and often plug them directly in to an Uno, powering them via

    //power the DS1307 RTC breakout board from the A2 (ground) and A3 (+5VDC) pins
    pinMode(A2, OUTPUT);
    pinMode(A3, OUTPUT);
    digitalWrite(A2, LOW);
    digitalWrite(A3, HIGH);

The above code is always in setup(), so happens relatively infrequently.

So if I were to guess, you're putting the MCU to sleep and you want the RTC to run from the backup battery in the meantime?

220-250 resistor will be needed. No need for Mosfet

Yes it's part of my ongoing research into saving power. The idea is to let the watchdog timer wake you up (at a slower clock speed this could be fairly infrequently) and then from time to time power up the clock chip and find out the actual time. Since the clock chip has a battery backup that should stay correct for years.

Well this is what I don't totally get ...

Looking at the pin D8, when running the above sketch, I see this:

Note that for most of the time the pin is at 3.44V, even though it is in input mode, with pull-ups turned off.

Now strangely enough (after quite a bit of experimenting) if I add these two lines after turning off D8:

  digitalWrite (A4, LOW);
  digitalWrite (A5, LOW);

Then I see this:

But that isn't pins A4 or A5. It seems as if somehow the I2C pull-up current is somehow working its way through the DS1307 chip, and making itself felt at the Vcc pin. Well that's weird.

That look like a discharging curve. In my opinion

Sure, but once the curve has discharged, in the upper screen shot, the flat line is at 3.44V, not 0V, for most of the time.

Just a wild guess, what happens if you disconnect the 3.3V backup battery?

I was thinking along those lines myself, but I don't see how a 3.3V battery would hold Vcc at 3.44 V. Plus, once I pulled the SDA/SCL lines from the clock chip, and the voltage immediately dropped to zero, I thought I had found the culprit.

Nick, thanks for posting this, found it really useful.

My pleasure, and thanks to everyone for clearing up the resistor value. I am worried that I might confidently post complete nonsense if I don't check up on the finer details. :slight_smile:

My summaries of power-saving techniques so far:

I've been playing with clocking Timer2 from a 32.768kHz crystal. Have one 328P on a breadboard, running from 2xAA cells, using 1MHz RC oscillator for system clock, Timer2 generating an interrupt every 8 seconds. The ISR is a software RTC. Works nicely, minimal parts. Draws about a microamp. Can adjust the prescaler for one interrupt per second if having the second hand jump eight notches at a time is too coarse XD

Hmm, can you do that? How did you wire that up, to save me straining my brain any more today?

The I2C pins probably have internal protection diodes, anode to the pin, cathode to Vcc. So I expect you will find that the voltage on the I2C pins is about 0.6v higher than the voltage on that Vcc pin.

Hi Nick, circuit attached below. I call it a "night light" because the sketch includes an algorithm that calculates sunrise and sunset time, and turns the LED on at sunset and off at sunrise.

Say, regarding the capacitor issue, I think it's a very interesting question, and I'd be willing to sacrifice an ATmega328P if you'd like to discuss a test protocol and circuit. I suppose we could cycle the pin hundreds if not thousands of times per second, so shouldn't be a terribly lengthy test.

@Jack Christensen

Nice and simple project. Do you have a code to share ? That will be nice.

@Jack Christensen

Nice and simple project. Do you have a code to share ? That will be nice.

Hi Techone,

Yes, I'll be glad to share code as well, I'm still tweaking it a bit though. I'm working on a blog post which will describe the code as well as the circuit. I'm not sure that it's a terribly "practical" project, but it does demonstrate several interesting features, and so I found it educational if nothing else!

Give me a few days and I'll let you know when I've got the post complete.