Does ladyada recommend the 2N2907? I did not see a label on the schematic.
Since the transistor is being used as a switch a better choice would be a 2N3906
which has much lower Vbe(sat) and Vce(sat) specifications.
From what I can see at a glance, it does seem to use a simple RC charge time calculation. It looks like the pin probably is set low to discharge, then set to input and waits for the 3.3MΩ resistor to charge it up and calculates from that. As the pin does not appear to be an analog input it appears they are using the CMOS input high level to determine the "end point".
I may be wrong about some of the above since I don't use AVr micros, but I can't see another obvious way of it doing things. Generally, there is the RC constant way used in many hobby/low end meters, the LC tank method also used for a few hobby projects (the most well know is probably the Elsie meter), or the applied signal and complex number calculation way, which most commercial LCR meters use.
Commercial LCR Meters use a very clean sine wave at typical (usually selectable) frequencies of 1kHz, 10kHz, 100kHz, etc. They apply the signal across the component with a shunt resistance and measure the ratio between voltage/current and the phase between them. From there you can calculate what you need to know (Impedance, ESR, Q, etc) The better ones also include a 4-wire sensing setup, with a guard terminal also.
I have a Mastech MS5308 here, which is a very nice example of such a meter at a good price - it will go as low as 0.01pF at ~2% accuracy.
Anyway, for your purposes, since this is a custom application I'd take advantage of the fact that:
- You already roughly know the measurement range, and that the capacitance will be pretty small
- Since it's for fuel level sensing, I would imagine absolute accuracy does not matter (which is good since accurate measurement of pF is difficult to do well), it's just the relative change you are interested in.
So I would design something that only has a measurement range of e.g. 1 - 100pF (or whatever your range is between empty/full) and is easily calibrated (e.g. null out the readings at empty)
There are many projects out there that you could look at and pinch ideas from. The RC time constant is probably the easiest way, but difficult with low capacitance. I think I would probably go for something like the Elsie way of doing it for this.
Alternatively, there are micros with capacitve touch sense peripherals which might be usable in this scenario. I don't know about AVRs, but for example the PIC16F1828 has a 12-channel capacitive touch peripheral.
Here is what looks like an AVR based version of the PIC based Elsie meter, with schematic and source code, so may be worth a look.
Best Answer
You can get an approximate measure of the capacitance with just 2 microcontroller pins, 1 resistor and 1 known capacitor. The circuit looks something like this:
C2 is the unknown capacitance you're trying to measure. C1 is a reference capacitor of known value, and about 50-1000 times the value of C2. R1 isn't too critical, 1k Ohm or so.
The idea is to charge C2 with a known voltage (5 or 3.3 V, whatever V+ is), and then transfer its charge (q = C*V) into C1. Each time we transfer the charge from C2 to C1, C1's voltage increases by a tiny amount proportional to C2. The number of times we have to transfer charge to make C1's voltage exceed some threshold (for us, the logical "1" threshold of pin A) is then inversely proportional to the value of C2.
The trick is to take advantage of the high-impedance state of the microcontroller pins. If we kept the bottom side of C1 grounded while charging C2, then we would also end up fully charging C1. Instead, we let the bottom side of C1 float by configuring pin B as high-impedance. Now, whatever the top side of C1 does, the bottom side does too, always keeping the same voltage across C1.
The measurement algorithm goes like this (in pseudo-C):
You can see a demonstration of the circuit at https://www.circuitlab.com/circuit/uq2zs6/cap-sensing/