I am working on charging and discharging a polarized capacitor (100 mF) automatically with a nMOSFET. Charging and discharging are done through constant current via a resistor of 10 kohm, and the voltage must be recorded.
The purpose is to calculate the energy as well as the power density of the cap. But while doing, there is neither discharging nor charging . Nothing happens as I measured with voltage data logger separately.
I am attaching the code and the circuit here. I request advice and suggestions from the community. Thank you.
// Pin assignments
const int capacitorPin = A0; // Analog input pin for measuring capacitor voltage
const int mosfetPin = 2; // Digital output pin for controlling MOSFET
const int chargingTime = 500; // Charging time in milliseconds
const int dischargingTime = 500; // Discharging time in milliseconds
void setup() {
pinMode(mosfetPin, OUTPUT); // Set MOSFET pin as output
Serial.begin(9600); // Initialize serial communication
}
void loop() {
// Charge the capacitor
digitalWrite(mosfetPin, HIGH); // Turn on MOSFET to start charging
delay(chargingTime); // Wait for the capacitor to charge
// Measure and print the voltage
int voltage = analogRead(capacitorPin); // Read voltage from the capacitor
float voltageValue = voltage * (5.0 / 1023.0); // Convert analog reading to voltage (assuming 5V reference)
Serial.print("Charging Voltage: ");
Serial.print(voltageValue, 2); // Print voltage with 2 decimal places
Serial.println(" V");
// Discharge the capacitor
digitalWrite(mosfetPin, LOW); // Turn off MOSFET to start discharging
delay(dischargingTime); // Wait for the capacitor to discharge
// Measure and print the voltage
voltage = analogRead(capacitorPin); // Read voltage from the capacitor
voltageValue = voltage * (5.0 / 1023.0); // Convert analog reading to voltage (assuming 5V reference)
Serial.print("Discharging Voltage: ");
Serial.print(voltageValue, 2); // Print voltage with 2 decimal places
Serial.println(" V");
delay(1000); // Delay between cycles
}
![circuit_MKS|659x500](upload://mQ6a8XAI295jDhveBzzlVNoe8cF.png)
Thank you Mr. Jim-P
Yes I understand
You nailed it and pointed out the error.
Thank you so much.
Its irf530n.
And now I am started to modify the circuit.
Not solved yet!
The IRF530N only has a guaranteed Rds(on) at 10V so it will not work with a 5V Arduino.
We need to find a different MOSFET.
Can you buy parts from Digi-Key or Mouser.
Is your capacitor really 100mF (100millifarads) ?
or did you use the 'm' to denote microfarads, because you couldn't type 'µ' ?
If it really is 100mF, what voltage are you expecting to get after charging it for 500ms through a 10kΩ resistor?
(Hint: it won't be much after 0.0005 time constants.)
Yep, parameters are correct and its 100 mF. Because the charging rate must be slow, may be in a few hours and 10k is just too high and it represents real-time load factors. Since the fabricated cap has Faradaic/pseudo cap characteristics, not EDLC type. So charge rate must be slow to reverse the reaction.
Then why thinking of using an external mosfet.
An Arduino output pin is just a switch with mosfets. Perfectly capable of switching that low current. You can change the current by choosing a different resistor value. 10k is 5volt/10k = 5mA.
More current?
I made once a 400F cap tester by connecting 12 Arduino output pins with 470 ohm resistors (10mA each) to the cap. Charging/discharging with that ~100mA was not a problem.
Leo..