Hi, I've been working on a project lately, and it requires me to measure with an arduino uno, how long it takes for a capacitor to discharge on a resistor. The discharge process is very fast and I am not able to measure it with a smartphone or another device. The arduino checks the voltage of the capacitor via a resistor divider with high resistor values, and the divider is connected to pin A0 of the arduino. I control when the capacitor will be discharged with a switch. Is there any way of measuring the time it takes for the capacitor to go from its initial voltage to 0V? My suggestion is to replace the physical switch which controls the discharge process with a MOSFET that's being controlled by the arduino, and let it keep the time since it turned on the mosfet until the capacitor reached 0V. I think of using millis(), or micros() functions. I would appreciate your suggestions or your corrections to mine.
Yes, that is correct.
How will the Arduino know when to begin the timer? You could set a threshold of 99% or 98% of the maximum charge and start the timer when it falls below the threshold.
Similar for stopping the timer. As the capacitor's voltage falls, the rate of discharge will also fall, so it will take a very long time to get to 0V. You might want to set a lower threshold of 1% or 2% of the maximum and stop the timer when the voltage falls below that.
Please look up the resistance into the UNO ADC. That resistance needs to be considered using a high resistance voltage divider as it might affect the divider value. Try to use 10, or better, 100 times lower values in the divider.
@projektoras
The RC time constant is the same no matter what voltage you charge the capacitor to, so why not just use 5V. No need for the divider.
Thanks for replying. I will try what you suggested.
@jim-p
My project requires the capacitor to be charged to a specific voltage so I cant really change it.
That's OK, your proposed solution with the voltage divider and MOSFET will work.
Is measuring this time of discharging really the final purpose of it all?
I guess the real final purpose is something different.
If you give an overview about your project I am pretty sure that a suitable solution can be found.
best regards Stefan
@StefanL38
Yes you are right, my question is a part of the project I am working on but the rest of the project is not helpful to my question. I think my question is answered.
Your results will not be accurate with a resistor divider. Place an opamp wired in unity gain at the measuring point and the divider on the output of the opamp. Connecting the opamp output to the - input forms a unity gain amp (voltage follower). Be sure the opamp has enough voltage to swing the range you need.
The reason for this is that the voltage divider will give you a voltage measurement but it will also discharge the capacitor. The Arduino needs an input of 10K or less on the analog inputs. If you use a duel opamp you can wire the second as a comparator to trigger or light a LED when voltage has been reached.
lol
Nonsense. The divider's resistance can be included in the total discharge pathway.
@gilshultz we are not all ganging up on you. I was just making a joke about your little spelling error.
It is commonly estimated to be 100 Megohms, which means its current draw is negligible, after the input sampling capacitor has charged.
It could be hours or even days, depending on component values.
What is the value of the capacitor, and what are the values of the resistors in the proposed resistive voltage divider? Are you allowed to choose other values?
Sounds like a similar exercise in my pulse and digital circuits class. Did you learn when a capacitor is considered "discharged". That is a fundamental part of your project.
Not a problem I am glad you caught it. I never passed a spelling class the whole time I was in school. I will stay with the 10K arduino uno - What is the lowest resistance pot that is useful with an analog input? - Arduino Stack Exchange.
@PaulRB So could a piece of code like that work? Because I tried but nothing showed on the screen
if(capVoltage < ((voltThreshold*95.0)/100.0)){ // if capacitor voltage falls under 95%
startingTime = millis(); //start measuring time, until
if(capVoltage <= (voltThreshold*7.0)/100.0){//capacitor voltage reaches less
finishedTime = millis(); //than 7% of the original value
dischargeTime = finishedTime - startingTime;
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE); // Draw white text
display.setCursor(0,0);
display.println("Disharge Time(msec): ");
display.println("");
display.setTextSize(2);
display.print(dischargeTime);
display.display();
}
}
To be exact the screen showed 0 in the discharge time.
When do you turn on the MOSFET?
The code need to be in a loop
Is the code fast enough to measure the time constant?
What is the value of he capacitor and resistor?
No, Arduino code must have setup() and loop() functions.