How to interface and measure a capacitive sensor? - General Discussion - Netduino Forums
   
Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

How to interface and measure a capacitive sensor?


Best Answer NameOfTheDragon , 09 November 2015 - 09:52 PM

Thanks for your comments Mario.

As I mentioned in my previous post, I did manage to get it working fairly convincingly on my Netduino Plus 2. By increasing the size of the resistor to about 10M, the oscillator frequency is brought down to around 1 KHz which is a rate that Netduino can happily service interrupts at. The interrupt routine just has to compute the difference between two time stamps so there isn't much work for it to do.

I used a number of techniques in the software to produce a stable output. For example, I used a 'moving average' to get a stable reading. I was able to display the results on an OLED display in terms of a percentage 'wetness'. For my application, the actual reading is not so important as getting an indication of whether it is wet or dry - ultimately it is going to be used to safeguard an astronomical observatory. By using thresholds in the software, it is a simple matter to get a "go/no-go" indication. The sample code I wrote drives 3 LEDs and gives a 'traffic light' indication.

You can see the code I used, such as it is, at https://bitbucket.or...lliraindetector

I looked at your web page and I couldn't see any evidence of a rain detector. I see you are selling the Davis weather station but I already have one of those. It has a rain gauge of course but it is far too slow to react for what I need.

Out of interest, the Davis weather station forms part of the larger project I am working on for a complete weather monitoring and logging system. https://bitbucket.or...f.weatherserver

That said, I blew up my Netduino a few days ago. I have been growing disillusioned with the product after encountering serious bugs that SecretLabs have been slow to address and limitations/bugs in the .NET Micro Framework. The price of the product has crept up to the point where it is no longer viable for me, so rather than replace the Netduino I have purchased a Raspberry Pi 2 instead. The Pi costs less than a basic Netduino 3, runs Windows 10 IoT Core with the Universal Windows Platform (a portable version of the full-blown .net framework), has a quad core CPU, bags of memory and a built-in HDMI output for running user interface. There is a lot to be said for it. I am slowly migrating my code across to the Universal Windows Platform.

One thing that the Raspberry Pi doesn't have is analogue inputs. I found a module based on the PCF8591 chip that uses I2C and I have just written and tested a driver for that, so I have got back my analogue inputs. The code for that isn't public yet but it will be soon! I'll be migrating all of my device drivers, including my motor control library over the next few days/weeks. Go to the full post


  • Please log in to reply
13 replies to this topic

#1 NameOfTheDragon

NameOfTheDragon

    Advanced Member

  • Members
  • PipPipPip
  • 112 posts
  • LocationCanterbury, Kent, UK

Posted 15 October 2015 - 08:51 PM

I would like to interface to a sensor which has a capacitive moisture sensor. The capacitance varies from 100pF (completely dry) to >= 360 pF (completely wet).

 

I'm a software engineer and analogue electronics doesn't come easy to me, so I hope someone is willing to help. What would be a suitable way to interface this device to a Netduino and measure it's value?



#2 TechnoGuy

TechnoGuy

    Advanced Member

  • Members
  • PipPipPip
  • 51 posts
  • LocationCanada

Posted 28 October 2015 - 03:07 AM

Could you please post details about your sensor please?  Things like Manufacturer & Part # would help.  If you could post a photo of your sensor that would help also.

 

Chances are that you have 3 pins on your device, though and they are:

 

  • 3.3 V (or maybe 5 V):  Supply Voltage
  • GND:  Ground
  • SIGNAL:  A variable voltage ranging from 0.0 V to the supply voltage level

 

If you could just confirm the details of what you have, I think it should be possible to advise you properly.


- Ian

 

My Current Dev Boards:

  • 3 x Netduino Plus 2
  • 1 x Netduino 3 WiFi

#3 NameOfTheDragon

NameOfTheDragon

    Advanced Member

  • Members
  • PipPipPip
  • 112 posts
  • LocationCanterbury, Kent, UK

Posted 28 October 2015 - 04:34 AM

The sensor is a thick film device made by Telecontrolli in Italy.I have tried really hard to attach the data sheets, in two different browsers, but unfortunately the forum software says no. In IE it will not even allow me to paste any text in the editor. Luckily I keep Chrome handy for situations like this, and that will at least let me paste hyperlinks, so here is a link to the sensor: http://en.telecontro...ain-sensor.html- if you look under the RESOURCES menu on the web site, there's a data sheet and some application notes there.

 

The device itself has six terminals, two are for the rain sensor, two are across a thermistor for measuring ambient temperature and the final two are connected to a heating element. There are no power connections as such because each pair of pins essentially just connects to a non-polarized passive component, so you can connect them up to whatever circuit you like. In the case of the rain sensor, it is a capacitor, so I'm connecting directly to each side of a capacitor. The data sheet will not tell you anything I haven't already stated, though. The rain detector is a variable capacitor that varies from 100pF (dry) to about 360pF (100% wet).

 

I actually had an email exchange with Telecontrolli and they provided me with an updated application note (not the one on their web site). In that they suggested using a 74HC14 inverting Shmitt trigger, arranged so that the rain sensor forms part of an RC network that sets up an oscillation. This can then be measured by the Netduino. I've used an InterruptPort to do this. The circuit as supplied generated oscillations that were in MHz, which was far too fast for the poor little Netduino to keep up with. By using a lot of 10M resistors I managed to get it down to just over 1KHz which is a more reasonable speed for the Netduino. It does work, but I would have rather had a voltage that I could feed into an A to D, that would be much less demanding on the Netduino and make the software a lot simpler.

 

If you are still reading and would like to follow up on this, I have open-sourced the software and a Fritzing file that shows the hardware I'm using: http://stash.teamser...s/heads/develop

 

Someone else has suggested that it might be possible to use an op amp to get a variable voltage output, but I have yet to see a schematic and op-amps, being definitely non-digital, are a bit out of my comfort zone.



#4 TechnoGuy

TechnoGuy

    Advanced Member

  • Members
  • PipPipPip
  • 51 posts
  • LocationCanada

Posted 28 October 2015 - 05:36 AM

This is intended as a quick reply / acknowledgement to offer some first impressions.

 

Basically I think what you have is "base level technology" there rather than "application level technology".  I would think that a company like Adafruit or SparkFun Electronics (but probably not for this particular technology) would be the ones to devote engineering resources to take the base level technology up to application level through the design & implementation of some sort of interface module (which would incorporate the circuit designs presented in the data sheets in one way or another).

 

Anyway, at the typical application level - for interfacing with sensors - that would usually be done with an analog type arrangement - i.e. reading a voltage level & scaling it (doing math) to convert it to the intended units or with a digital arrangement (I2C, OneWire or SPI - where there's a bit of intelligence in the module).

 

My thoughts are just this - if you're new to interfacing with sensors and just want to learn about physical computing - you probably picked the wrong type of sensor to start with.  However, it does seem like you've overcome initial hurdles & are on your way to a workable solution.  So that being said - I think it's a sign that you are on top of things.

 

More comments in a day or two (after I've read the application notes).  I was assuming you had a simpler type of device; I may not have much to add...


- Ian

 

My Current Dev Boards:

  • 3 x Netduino Plus 2
  • 1 x Netduino 3 WiFi

#5 TechnoGuy

TechnoGuy

    Advanced Member

  • Members
  • PipPipPip
  • 51 posts
  • LocationCanada

Posted 30 October 2015 - 06:55 PM

Just following up on my initial response.  As I mentioned in that reply I believe you've got hold of technology which is at a base level, something which requires additional hardware support to bring it up to an application level.  I guess this offers lots of options in regards to how exactly to do that - i.e. what capabilities to expose & the choice of application level interface to utilize.

 

I also mentioned in my previous comments that I felt a company like SparkFun Electronics (or like your Sainsmart in the UK) might be the ones to engineer the necessary hardware support / bring things up to an application level.  I just did a quick search for "SparkFun + Weather"; here's one of their offerings, which is at the application level.  This is just for the sake of comparison & it's not meant as an endorsement of their product.

 

SparkFun Weather Meter

 

I do have one of their temperature & humidity sensors though; it's a little expensive for what it does, but it is an example of what I'm talking about.  A company called Measurement Specialties (located in France, I think) produces a chip with temperature & humidity measurement capabilities, along with a published interface (implemented using I2C).  SparkFun has taken the chip and mounted it on a PCB, breaking out all the pins & adding in all the required passive components.  They're bringing it up to application level - where "Joe Hobbyist" (i.e. a regular guy like me) can use it.  In addition, they've gone to the trouble to create a library and example code (aimed at Arduino users) for exercising it.  I developed a corresponding library for NETMF so that I could use it with Netduino.

 

SparkFun HTU21D Sensor Breakout

 

Anyway, I think you've done a lot of the hard work to bring your particular device up to application level and you're just having to make some design decisions on how to expose the functionality.  FWIW - I'm impressed with what you describe.

 

NB #1

I did try to view the Fritzing diagram you created; I get stuck at a Log In prompt for something called Atlassian Stash.  Don't really know what that's all about.

 

NB #2

With regard to data sheets, it's better to just post a link to where it can be found on the manufacturer's website than to try to post the datasheet itself (what you wound up doing).


- Ian

 

My Current Dev Boards:

  • 3 x Netduino Plus 2
  • 1 x Netduino 3 WiFi

#6 NameOfTheDragon

NameOfTheDragon

    Advanced Member

  • Members
  • PipPipPip
  • 112 posts
  • LocationCanterbury, Kent, UK

Posted 02 November 2015 - 02:42 PM

Thanks Ian. I certainly agree that this is a bese level device, but if I wait for someone else to do all the work for me I'll never accomplish anything! Sparkfun's sensor might be excellent but doesn't have a rain detector, which is what I need. I also don't think that Sparkfun's sensor would fayre very well being left out in the rain ;-)

 

Anyway, I'm making progress using the approach suggested by Tellicontrolli, using an inverting Shmitt trigger (74HC14) to make an oscillator. The circuit as suggested went at over 1MHz! Far too fast for the Netduino to keep up with. I just kept adding 1M resistors into the circuit until I got it down to about 1KHz, which translates to an interrupt about every 1 milliseconds, which the Netduino can just about keep up with. It's then a simple matter to get the time interval between interrupts.

 

Sorry about the link not working. I forgot to set my local repository to 'public' - I have done that now and the link should work, but really I should have posted the link to BitBucket. I would post the link but the forum software is very broken and makes it a MAJOR pain in the rear to paste content in, so if you go to bitbucket.org and search for 'Telecontrolli' you will find it.

 

Now, having got it all working within acceptable parameters, unfortunately I have managed to fry my Netduino by putting 9v up the USB connector (don't ask!). Neither the polyfuse nor the ESD protection diodes saved it, and it has ceased to be. Rather than spend money on a new one, they are just too expensive for what they are now and I've bought a Raspberry Pi 2 instead and I am running Windows 10 IoT Core on it. It cost me less than a basic Netduino 3, has HDMI and USB ports so you can actually interact with it. although it works 'headless' too, has a quad core CPU and 1Gb or RAM. Remote debugging works over the network and is much smoother than with the Netduino. I'm saying farewell to .NET Micro Framework, which frankly has had its day, and hello to the Universal Windows Platform. I have already started converting all my code.



#7 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 09 November 2015 - 08:27 AM

I don't think you'll get decent (i.e. accurate) results with a simple oscillator: the capacitance is pretty small and also spans along a short range. Moreover, as you correctly pointed out, the Netduino itself won't be able to capture a so high frequency, although I believe you'd have hard time to read it with an Arduino-like board.

Such a sensor is surely cheap but much reliable: it's just a comb-shaped pair of plates, which offers a different electrostatic behavior upon the quantity of water on it...

Water? how this water is composed? what if the rain is mixed with sand, since often we experience red-rains due the African desert wind?

 

I don't know if that might help you, but we faced the generic "weather" station a while ago, for real cases, not just hobby/home purposes. We've a complete set of sensors for accurate telemetry, even without TCP/IP layer and for pretty long distances (up to some km).

Have a look  here, just for your information...

http://www.cet-elect...ti/sensors.html

 

Cheers


Biggest fault of Netduino? It runs by electricity.

#8 NameOfTheDragon

NameOfTheDragon

    Advanced Member

  • Members
  • PipPipPip
  • 112 posts
  • LocationCanterbury, Kent, UK

Posted 09 November 2015 - 09:52 PM   Best Answer

Thanks for your comments Mario.

As I mentioned in my previous post, I did manage to get it working fairly convincingly on my Netduino Plus 2. By increasing the size of the resistor to about 10M, the oscillator frequency is brought down to around 1 KHz which is a rate that Netduino can happily service interrupts at. The interrupt routine just has to compute the difference between two time stamps so there isn't much work for it to do.

I used a number of techniques in the software to produce a stable output. For example, I used a 'moving average' to get a stable reading. I was able to display the results on an OLED display in terms of a percentage 'wetness'. For my application, the actual reading is not so important as getting an indication of whether it is wet or dry - ultimately it is going to be used to safeguard an astronomical observatory. By using thresholds in the software, it is a simple matter to get a "go/no-go" indication. The sample code I wrote drives 3 LEDs and gives a 'traffic light' indication.

You can see the code I used, such as it is, at https://bitbucket.or...lliraindetector

I looked at your web page and I couldn't see any evidence of a rain detector. I see you are selling the Davis weather station but I already have one of those. It has a rain gauge of course but it is far too slow to react for what I need.

Out of interest, the Davis weather station forms part of the larger project I am working on for a complete weather monitoring and logging system. https://bitbucket.or...f.weatherserver

That said, I blew up my Netduino a few days ago. I have been growing disillusioned with the product after encountering serious bugs that SecretLabs have been slow to address and limitations/bugs in the .NET Micro Framework. The price of the product has crept up to the point where it is no longer viable for me, so rather than replace the Netduino I have purchased a Raspberry Pi 2 instead. The Pi costs less than a basic Netduino 3, runs Windows 10 IoT Core with the Universal Windows Platform (a portable version of the full-blown .net framework), has a quad core CPU, bags of memory and a built-in HDMI output for running user interface. There is a lot to be said for it. I am slowly migrating my code across to the Universal Windows Platform.

One thing that the Raspberry Pi doesn't have is analogue inputs. I found a module based on the PCF8591 chip that uses I2C and I have just written and tested a driver for that, so I have got back my analogue inputs. The code for that isn't public yet but it will be soon! I'll be migrating all of my device drivers, including my motor control library over the next few days/weeks.

#9 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 10 November 2015 - 08:11 AM

Fine!

Just a word about the oscillator...

The frequency of that circuit is something like: f=K/(R*C), where K is a constant.

The relevant thing is that a capacitance-delta is behaving in a hyperbolic way to the frequency. That is, even a small fluctuation of the capacitance (or resistance) will actually produce a huge shift of the expected frequency.

You should avoid coupling high R with small C: leave the oscillator running fast and count how many pulses it feeds in some "capture" input. Any cheap *duino is able to count MHz without any problem.

 

We don't use Davis' products. Our rain detector is basically a water flow meter. However, that's *not* a product of our labs: we just use it.

Cheers


Biggest fault of Netduino? It runs by electricity.

#10 NameOfTheDragon

NameOfTheDragon

    Advanced Member

  • Members
  • PipPipPip
  • 112 posts
  • LocationCanterbury, Kent, UK

Posted 10 November 2015 - 08:40 AM

You may be looking at a different circuit to the one I actually used, but taking T = RC gives a time between interrupts that is directly proportional to the capacitance. Since R is fixed, I can directly compute the capacitance, giving a good approximation of the actual capacitance and thus the % wetness.

You can tell me it won't work all you like, but I have one here that I can point to and say "there it is, working". :) Or, at least I did have until I blew up the Netduino :( There's a video of a fairly early prototype here: https://www.facebook...5093833/?type=2

It's quite sensitive, the tiniest amount of water on the sensor produces a good change in the reading, which is exactly what I wanted for my application.

#11 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 12 November 2015 - 07:56 AM

I never said the circuit is not working: I've said that's very critical. I mean that if you're going to create more-than-just-one circuit, you'll have to re-tune each one, because the inherent error, tolerance and whatever will lead to (even to) dramatic different results.

 

A typical resistor is given at 5%, but you might find at 1% as well. The capacitance of a comb plate is due to many factors: exposed surface area, dielectric, and distance. Thus, upon a temperature range of, let's say, 0 to 40°C, you'll have a very different C, despite the same rain fall.

 

Have a try, and you'll face the problem. However, if you're going to create a single one, okay, you can tune it perfectly, table its trans-characteristics on software and plot a real behavior upon rain and temperature.

 

I really didn't want to fire discussions: just to alert other readers that the problem isn't simple!

Cheers


Biggest fault of Netduino? It runs by electricity.

#12 NameOfTheDragon

NameOfTheDragon

    Advanced Member

  • Members
  • PipPipPip
  • 112 posts
  • LocationCanterbury, Kent, UK

Posted 12 November 2015 - 10:13 AM

Ah, I take your point. Fair enough. I agree, it's not a simple problem.

I did consider the tolerance thing. There are techniques in software that can compensate for component tolerances. In one version I had the thing auto-ranging and it worked reasonable well. Since the thing can never go past completely dry or completely wet, one can keep a record of the maximum and minimum readings and adjust the calculations dynamically. The key there is to choose an appropriate set of defaults.

#13 Billy Propes

Billy Propes

    Advanced Member

  • Members
  • PipPipPip
  • 33 posts
  • LocationVincent, OH, USA

Posted 04 December 2015 - 12:53 PM

Dragon,

http://zerocharacter...sensor.html?m=1

This link may be relevant to your situation. I came across it while doing some research on water level / moisture sensors for my hydroponics system. The link itself is information on a pcb which is being used as a basic planar capacitor to measure soil moisture levels. But, it sounds like you're using something similar.

I think with NETMF being an interpreted language, you're going to have issues with measuring the timing.

If you scroll down to the comments at the bottom of the page, you'll find links to some basic specialized circuits which will allow you to translate the PWM signal into a constant analog voltage that you can measure from a Netduino. It takes a lot of the timing issues out. Hope this helps.

#14 NameOfTheDragon

NameOfTheDragon

    Advanced Member

  • Members
  • PipPipPip
  • 112 posts
  • LocationCanterbury, Kent, UK

Posted 04 December 2015 - 04:56 PM

Billy, thanks for posting. Certainly some interesting stuff to follow up there, hidden down in the comments.

I did have it working fairly reliably on my Netduino Plus 2 using the inverting Schmidt trigger to make an oscillator. On choosing a large enough resistor, the oscillation can be slowed to the point where it can be reliably measured with the Netduino. I also used a moving average to further smooth the results.

One concern that has been expressed is that the technique may be rather sensitive to component tolerances, but in fact there is a lot that can be done in software to mitigate that.

The problem I am left with is that the Raspberry Pi that I am now using has an even worse response time than the Netduino. I can only get a resolution of around 32 milliseconds on the Pi, whereas I could reliably measure with a resolution of around 1 millisecond on the Netduino, even though it is interpreted. There's an alternative GPIO driver for the Raspberry Pi that's supposed to improve performance by 2 orders of magnitude, but I can't get it to work! So, I'm left with the option of somehow measuring the capacitance in hardware. I would ideally use some sort of I2C device to do the measuring, but it is something I have yet to work on as I'm quite tied up in another project.

Anyway, thanks for posting, I will follow up those links.
--Tim




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.