# How to apply Kirchoff laws to form differential equation for RC circuit with a variable applied 2nd voltage?

I'm trying to create a model for how a capacitor charges and discharges in an RC circuit in response to an applied "control voltage" V2. For this, I want to form the differential equation for time-dependent capacitor voltage for the below circuit: simulate this circuit – Schematic created using CircuitLab (my interest stems from being able to simulate this circuit, e.g. used practically here: https://pimylifeup.com/raspberry-pi-light-sensor/)

I recall learning Kirchoff's voltage/current laws to analyze such circuits, but am having difficulty applying it to this circuit because of the added V2 voltage (which in practice is used for switching whether the capacitor is charging or discharging).

For example, if we consider the left-hand side 'loop', wouldn't Kirchoff's voltage law give us:

V2 = voltage across capacitor


thus eliminating all time dependence?

I feel I'm missing something simple?

• If V2 is an ideal voltage source the rest of a circuit does not matter for the capacitor point of view only V2 counts. – G36 Oct 27 '19 at 15:49
• That's not a practical circuit though. Switching on V2 will create an inifinite amount of current through the capacitor. You'd need to either model the residual resistance of the capacitor or the internal impedance of the voltage source V2 – Hilmar Oct 27 '19 at 17:59

For example, if we consider the left-hand side 'loop', wouldn't Kirchoff's voltage law give us:

V2 = voltage across capacitor


thus eliminating all time dependence?

Correct, assuming the V2 source has no time variation.

If you connect an ideal voltage source across a capacitor, then nothing else in the circuit affects how it charges or discharges.

• Ok, thanks but what if I'm interested in the charging/discharging behaviour and not the steady state, where V2 is periodically switched from a value between V1 and 0V. There must be some charge time surely? That's how the circuit I linked to in the OP works I think? – SLhark Oct 27 '19 at 16:15
• Then your model is incomplete. You should include a source impedance in your model of V2 if you don't want it to be able to charge the capacitor instantaneously. – The Photon Oct 27 '19 at 16:24
• Also notice in the RPi circuit you linked to, they didn't set the pin to be 0 V or 5 V. They set it to be output as 0 V, or as input. In input mode, it will be high impedance, not a low impedance 5 V source. – The Photon Oct 27 '19 at 16:26
• Ah ok, thanks for clarifying. So in "input mode", I could effectively consider a model with V2 removed (since I assume high impedance is effectively open circuit?)? And in "output mode", since there is some finite discharge time in real life, it seems wrong to say the voltage across the capacitor is suddenly 0V, so I guess I need to replace V2 with a resistor (modelling RPi output impedance) to ground (ie 0V)? Does that seem logical? And if so, how can we know what resistor value to use for the RPi output impedance? Thanks! – SLhark Oct 27 '19 at 16:38
• Yes, that's reasonable. To know the right resistor value for the RPi output you'd have to know exactly what device is connected to that pin on the RPi, and get its datasheet. Something like 1 - 5 ohms is probably reasonable, and shouldn't change the result in any meaningful way. – The Photon Oct 27 '19 at 16:44