Measuring capacitor discharge curve issue

Hi there,

i need to measure few points on discharge curve of capacitor using arduino. This is how it looks my code:

 if(state == 2)
   {
     digitalWrite(rele1, LOW);
     if(u0 == 0)
     {
       u0 = (5.0/1023.0*(double)analogRead(A13))*3.0;
       lcd.setCursor(6,0);
       lcd.print(u0);
     }
     if(akt == 0)
     {
       akt = millis();
     }
  //TIME 1   
     u1 = (5/1023*analogRead(A13))*3;
     lcd.print(u1);
     if(u1 <= 9.0 && t1 == 0) 
     {
       t1 = ((double)millis()-(double)akt)/1000.0;
       
       lcd.setCursor(-4,2);
       lcd.print(t1);
     }
//TIME 2
     u2 = (5/1023*analogRead(A13))*3;
     if(u2 <= 6.0 && t2 == 0) 
     {
       t2 = (millis()-akt)/1000.0;
       lcd.setCursor(1,2);
       lcd.print(t2);
     }
//     TIME 3
     u3 = (5/1023*analogRead(A13))*3;
     if(u3 <= 3.0 && t3 == 0) 
     {
       t3 = (millis()-akt)/1000.0;
       lcd.setCursor(6,2);
       lcd.print(t3);
      
     }

I try to measure voltage, and if voltage falls below for example 9 volts i need to record time.

If i print these 3 times on lcd they are show 0.00 V.

I try to measure voltage, and if voltage falls below for example 9 volts i need to record time.

If the voltage doesn't fall below 5.0V, you'll fry your Arduino.

If i print these 3 times on lcd they are show 0.00 V.

Since the values are time, it's unusual to see time expressed in volts. What part of the world does that?

Post ALL of your code.

Why do you divide by 1000? You will get zero if under 1 second
Post all of your code.

I have voltage divider on analog input.

i divided it 1000, because i need time in seconds not milliseconds

What sort of capacitor are you looking at?
Is it the open-circuit self discharge leakage which you are looking at or through a particular load?
Those makes a huge difference to the best way to do this. A 10000microFarad electrolytic is a lot different to a 10pF ceramic.

Also, do you always discharge from 9V? (if you did that could make things easier).

It is parallel combination of four 2700uF capacitor. They are discharged from 13,5V. I need to measure capacity of that capacitors. They are discharging through a 60 Ohm resistor and i think i measure some points (9, 6 and 3 volts) on discharging curve and calculate capacity like average of capacities calculated in this points.

It is a capacity tester.

I got a nice curve using 10k Ohm resistor and 10uF capacitor with RC = 100ms exactly coming at 1.8 (~=5/e)

float val = 0;

void setup() {
Serial.begin(19200);
pinMode(A0, OUTPUT);
digitalWrite(A0, HIGH);
delay(1000);
pinMode(A0, INPUT);
}

void loop() {
  val=analogRead(A0);
   if(val!=0)
  {
  Serial.print(((float)micros()/1000)-1000);
  Serial.print('\t');
  Serial.println((float)val/1023*5);  
  }
}

Looks like by the time I posted this you gave the scenario of your problem... putting an voltage divider seems to be your best bet. If your max. output voltage is 13.5 (that's where it begins). You can probably make a voltage divider by three 10ks in series to measure the voltage from the third resistor. (If 60 Ohm resistor in the problem statement, you better use a rheostat and take readings from the middle)

Putting inputs more than 5V and more current through Arduino can damage it badly.

the circuit works nice, if i display it on osciloscope it is good. only thing that does not work is the program, voltage is in the correct bounds i have voltage divider parallel to the discharge resistor

If you have voltage divider parallel to the discharge resistor it obviously won't work.

it is 100k and 50k resistors parallel to the 60 Ohms, why it would not work?

I don't like the look of your analogRead(A13) because that would not work on my 168 arduino which has only A0,A1,A2,A3,A4 and A5.

Perhaps try writing a test routine in which setup contains little more than

Serial.begin(115200);
ut1 = micros();
Serial.print( analogRead(A13) );
Serial.print("\t");
Serial.print("0");
Serial.println();

for (m=0; m<500; m++)
{
delayMicroseconds(1000);
Serial.print( analogRead(A13) );
Serial.print("\t");
ut2 = micros();
ut3 = ut2-ut1;
Serial.print(ut3);
Serial.println();
} // less than a second

To get that to work on mine, I'd replace "A13" with "A0" or "0" and use the pin marked a0 on my arduino.
Someone gave me a ticking off the other day for using just a "0", so maybe ask your academic supervisor why that is bad practice.

I using arduino mega 2560, thank you, i will try it :slight_smile: