# CapacitiveSensor fundamentals

Dear forum,

this is basically a question for Paul Badger or Paul Stoffregen, or both! But anyone knowing an answer will be welcome!

First, congratulations for the library, a lot of people have successfully used that!

I am testing a self-made moisture sensor for wood chips mounted on a bucket. I am doing that within the frame of a MSc thesis. This means that I want to establish statistical relationships between the values from CapacitiveSensor (corrected reading, absolute reading or even elapsed time) and the real values of moisture, in combination with the measured bulk density and temperature. So, since my work has to be more or less scientific, I would like to explain in my results, when I finally obtain something, from where are the arduino values coming.

So, my question is, how does this library produce the values capacitiveSensor() and capacitiveSensorRaw()? My ideal would be to reach a value of capacitance (farads), but if impossible, I should be able to explain which is the meaning of a reading of 7000 or 29000.

When I tried to obtain my own values of capacitance by measuring the elapsed time between the "HIGH" in the send pin and the 63% of 5V in the received pin, for using the 1 = R*C equation, I completely failed to obtain anything. Then, I decided to use CapacitiveSensor library, which has shown to be sensitive to the material I am using.

In the meanwhile, I have noticed the enormous differences when getting readings when arduino is connected to a Laptop or connected to a 9V battery. When reading with the Laptop, the wire going to the bucket (where the + (10 cm x 10 cm) foil is stuck at the bottom) is sensitive when I grab it. So I thought that the use of shielded wires would solve this issue (yes?). But when working with a 9V battery, my aim, the wire is by contrary almost insensitive, and in addition I have lost a lot of sensitivity also in the sensor, even with a large foil connected to ground (-) and fixed on a wall of the bucket. Touching the battery also affects the readings, but I can solve it by isolating it.

Completely understanding how CapacitiveSensor works would help to better design the final experiment (I will devote a lot of time to that).

Ignacio

A capacitor has two plates. With the sensor, one of these is ground. When you use the laptop it has a large area of grounded metal (internal boards etc). With a 9v battery, you only have the Arduino ground which is much smaller.

Try making a connection to earth or having a large sheet of metal nearby.

Please supply a drawing of how you have physically connected the sensor parts.

Weedpharma

As you have found out using an Arduino to measure capacitance is not a very precise business. It is subject to so many variables over which you have no control. Therefore I would not use an Arduino for any scientific measurements simply because they are not very repeatable.

There are better ways of measuring capacitance than the technique used by these libraries. If I were doing that project I would look at the many capacitive sensing chips that are around. Read the data sheets as they explain in detail what effects they are measuring.

Grumpy_Mike:
As you have found out using an Arduino to measure capacitance is not a very precise business. It is subject to so many variables over which you have no control. Therefore I would not use an Arduino for any scientific measurements simply because they are not very repeatable.

IMO you're confusing measuring a capacity, and measuring some other thingy by capacity.

When you connect known capacitors to the circuit, you can find out about precisiion, repeatability etc. of the capacity measurement.

Most (intended) applications suffer from defined capacities, that could be precisely measured. A finger approaching a metal foil has anything but a known capacity. Only (un-)certain circumstances can happen to influence the capacity reading, with no guarantee of reproducability or relationship to the actual situation, movement or whatsoever.

Similarly one can use an LDR for an proximity sensor, which may work in a very specific environment, but not in outdoor applications.

IMO you're confusing measuring a capacity, and measuring some other thingy by capacity.

Do you mean:-
IMO you're confusing measuring a capacitor, and measuring some other thingy by capacitance.

Please get your words correct if you are going to accuse me of getting something wrong. The OP is looking to measure moisture by taking a capacitor measurements.

A finger approaching a metal foil has anything but a known capacity.

No it has a very definite capacitance, all you need to do is to measure it. Given the nature of what you are trying to measure means that the capacitance is not very repeatable from one measurement to the next.

I think it is you who has got hold of the wrong end of the stick here.

Hi there!
I really do appreciate your answers. As soon as I have time, I will get through your questions and also look for some of the solutions you have proposed.
Thanks again!
Igancio

A finger is not a capacitor, doesn't have a specific capacity.

A finger can be considered part of an capacitor, when the foil acts as its second contact, and the air between both acts as dielectricum. Then you have an capacitor, with one contact (the foil) connected to the Arduino, but with a detached second contact. As we all know, measuring a capacity requires both contacts of the capacitor connected to the measuring circuit, so where is that second contact?

The current flowing through our (assumed) capacitor can go from the foil through air (dielectricum) to the finger, through the body (resistor), from the feet to ground (earth) through some other dielectricum (shoes, carpet...), and from earth back to the Arduino Gnd on some inobvious way. With so many components, between the finger and the Arduino Gnd, the distance of the finger from the foil is only one of the many parameters that affect the reading of the capacity (charge/discharge) measuring code.

When you touch the Arduino Gnd with another finger, the current flows from the finger through the body (resistor) to the other finger and back to Gnd, forming a much better defined current loop. Now the measured capacity depends mainly on the distance of the finger from the foil (thickness of the dielectricum) and, to some degree, also on the resistance of the body and from the other finger to Gnd. Increasing the pressure on the finger against the Gnd line will reduce the resistance, and consequently also affects the measured value, even if this effect is purely resistive.

Another better defined (and controllable) capacitor can be constructed by means of another foil connected to Gnd. Now the finger can act as a resistive bypass of the dielectricum (air) between both foils, or as two capacitors existing between either foil and the finger, in parallel to the capacity between both foils.

That's why a finger has no specific capacity, the measured value depends on the current flowing from the foil to the finger and back to Gnd on some more or less obvious way.

Dear colleagues,
Thank you for your answers and suggestions. I think that DrDiettrich answer (thanks) is very clear to say that my measures depend on a lot of factors.
I take the opportunity to ask: if I use a shielded wire, can I improve the readings, keeping all other influences constant?
I attach a couple of drawings, answering a petition of weedpharma:

This solution provided sensitivity to wood chips when connected to a laptop. I had no sensitivity when connected to a 9V battery.
Following your suggestions I have done this:

Which recovers some sensitivity.
Thanks Grumpy_mike, I will also look for already developed capacitive sensig chips. Any reference to start with?
Using aluminium foils makes any electrical or sensitivity difference when compared to other metals or thicknesses?
Thanks for your posts and ideas, I really do appreciate your time!
Ignacio

To make a touch switch, I have a small metal plate covered with a paper label and a layer of transparent adhesive plastic film (as available from stationers). With a 5 volt Arduino, I have the plate connected to analogue input pin 'A0' and biased via a 1MΩ resistor to the Arduino's 3.3V pin. Currently I also have 2.2nF capacitor across the resistor but that's not essential.

In the Arduino software, I am using 'File' > 'Examples' > '01.Basics' > 'AnalogReadSerial' to display the voltage readings on the serial monitor (it's rather fast unless you increase the delay in the loop). With my finger well away from the plate, I am seeing the voltage readings varying, not a steady reading corresponding to 3.3V. When I place my finger on the plate the readings vary very much more. Much of this is "hum" as you hear when you touch the input to an audio amplifier. I should add that my Arduino is connected via USB to my PC.

I am therefore sceptical as to whether or not CapacitiveSensor is measuring change of capacitance or just detecting electrical hum.

Anyway, I don't understand why you are trying to measure capacitance. To measure the moisture content of wood chips, isn't it likely to be better to measure their electrical conductivity? I appreciate that the conductivity could depend on the size of the chips, their compression and on the type of wood.

I suggest you place two large areas of foil on opposite sides of your bucket and try measuring the resistance, initially with a multimeter. If the resistance is rather high, you could try placing a number of vertical strips or rings of foil around the inside of your bucket and connect alternate strips to your meter.

When making a circuit to enable conductivity readings to be made by your Arduino you will be able to add a capacitor to virtually eliminate the effect of stray electrical signals such as hum.

For a scientific work on capacitive measuring you deserve a reproducible experimental setup, for obtaining reproducible values. I'd suggest two metallic plates, face to face, which form an capacitor whose capacity can be measured e.g. by the Arduino. Then introduce the test objects (pieces of wood) between the plates, and find out the relationship between the program readings and the known characteristics of the test objects (humidity, mass, shape, fibre orientation, species...).

In ground humidity measuring you'll typically stick electrodes of known shape into the material. Would this be possible with wood as well? Otherwise the dimension of the test object are important, i.e. the volume penetrated by the electrical field. Will it be possible to use test objects of a unique shape (length, width)?

DrDiettrich:
I'd suggest two metallic plates, face to face, which form an capacitor whose capacity can be measured e.g. by the Arduino.

I suggest:

1. the two metallic plates are mounted well inside a large metal box (earthed) to screen them from interference;
2. the measurement is made with a continuous signal of decent frequency, say 50kHz;
3. the plates form one component of a bridge circuit, like a Wheatstone bridge, which if balanced initially may make it easier to detect small changes in capacitance, especially if the output from the bridge is passed through a differential amplifier.

Start with this, it gives stable readings down to 0.1pF with a DMM set on the 200mV scale.

I recently connected it to a new meter that can read down to 0.01mV, and found this circuit pretty stable down to 10fF (femtofarads). I did not do any long term stability testing. Using the Texas Instruments CMOS 555 timer.

Archibald:
Anyway, I don't understand why you are trying to measure capacitance. To measure the moisture content of wood chips, isn't it likely to be better to measure their electrical conductivity? I appreciate that the conductivity could depend on the size of the chips, their compression and on the type of wood.

I suggest you place two large areas of foil on opposite sides of your bucket and try measuring the resistance, initially with a multimeter. If the resistance is rather high, you could try placing a number of vertical strips or rings of foil around the inside of your bucket and connect alternate strips to your meter.

When making a circuit to enable conductivity readings to be made by your Arduino you will be able to add a capacitor to virtually eliminate the effect of stray electrical signals such as hum.

Hi Archibald,
I like your suggestion. However, I initially discarded conductivity and chose capacity because:

• capacitance should be less sensitive to water which is stuck in the surface of wood chips after seasoning
• capacitance seems to have more penetration, by playing with an electric field which crosses my sample of wood chips.
In any case, I may consider trying with conductivity.
Thank you!
Ignacio

DrDiettrich:
For a scientific work on capacitive measuring you deserve a reproducible experimental setup, for obtaining reproducible values. I'd suggest two metallic plates, face to face, which form an capacitor whose capacity can be measured e.g. by the Arduino. Then introduce the test objects (pieces of wood) between the plates, and find out the relationship between the program readings and the known characteristics of the test objects (humidity, mass, shape, fibre orientation, species...).

In ground humidity measuring you'll typically stick electrodes of known shape into the material. Would this be possible with wood as well? Otherwise the dimension of the test object are important, i.e. the volume penetrated by the electrical field. Will it be possible to use test objects of a unique shape (length, width)?

Thanks DrDiettrich,
This was my initial Layout. However, it didn't work as expected, I wasn't able to measure any delay of the change of voltage of one of the plates. I must say that I work with a big bucket (50 litres, ca. 16 gallons), and therefore I initially theoretically estimated a capacitance of about 1 F, which is very high. That's why I thought about the CapacitiveSensor library, which seems to be sensitive, but whose values do not seem to be reliable.
Thanks again!

Archibald:
I suggest:

1. the two metallic plates are mounted well inside a large metal box (earthed) to screen them from interference;
2. the measurement is made with a continuous signal of decent frequency, say 50kHz;
3. the plates form one component of a bridge circuit, like a Wheatstone bridge, which if balanced initially may make it easier to detect small changes in capacitance, especially if the output from the bridge is passed through a differential amplifier.

Hi Archibald,
As you may see in my profile, I am newbie here:-(

1. The metallic plates would be located within a 50-litre Polypropylene bucket (my aim is to integrate bulk density in the estimation of moisture, with arduino; I am using a standardized 50-litre bucket for assessing bulk density). No metal box, but I could protect somehow the plates (ideas?)
2. how can I make the signal with a frequency of 50 kHz? Will it be expensive? Can I do it with arduino and a 9V battery?
3. I don't have right now a clue to understand your concepts of the Wheatstone bridge, but I will investigate it later
BTW: the bucket and the sensor I talked about initially look like this: http://www.tbforest.com/imatges/P5170064.JPG
THANKS!

Now you can see the image

polymorph:
Start with this, it gives stable readings down to 0.1pF with a DMM set on the 200mV scale.

I recently connected it to a new meter that can read down to 0.01mV, and found this circuit pretty stable down to 10fF (femtofarads). I did not do any long term stability testing. Using the Texas Instruments CMOS 555 timer.

http://www.polyphoto.com/tutorials/ElectronicCircuits/Dual555CapMeter150dpi.jpg

Thanks polymorph,
I am wondering if my capacitance will be that low, since I estimated initially that it would be ca. 1 F. I would also need to learn how to manage with the timer you suggest. I guess I could work with this timer with Arduino, yes?
Thanks again!

1F is an incredibly high capacitance, I find that highly unlikely. If you do get that high, patent it.

Yes, you can use this by sending the output to an Analog pin on the Arduino and use analogRead(). If you use the internal 1.1V reference, it'll be more stable and sensitive as this was meant to put out less than 200mV, although it'll work up to 2V output but may not be as linear.

You might also try measuring the length of the pulse right from pin 3 of the rightmost 555.

Ok! I am getting back to the classic capacitor concept and get one of these 555 timers.
I'll post any result!
Thanks!
Ignacio

Cool.