Easy read Capacitive Humidity Sensor  direct from microcontroller

The following design works but would be interested in improvements from guys better with analog than my self.

I ran out of ADC pins and didn't want to install a multiplexer or an external ADC for my 3 humidity sensors.  I  was tired of paying $15 to $35 each for humidity sensors  like the vout HM1500 or the digital SensirionSHT75.   In addition I found that many of the vout and freq out units had drifts exceeding 10% after 1 year in our application.    My other issue is that the more sophisticated vout sensors kept getting model changes which required design changes  while the base cap sensors remained the same and reliable.     I needed an adequate solution that was cheaper and could be easily field re-calibrated.   I looked at many of the 555 circuits but they seemed complex with lots of components which could have thermal drift and they still did not allow direct recalibration in the field.         I wanted something that would be easy to integrate into remote mounted circuits dozens to hundreds of feet away while keeping costs low. 

My design is based on reading the capacitance variance directly from the micro controller and have been reasonably satisfied with the results.  The cheap sensors like the HCH-1000-002 and the HS1101 do not come pre-calibrated and I found over a 10% variance from sensor to sensor so calibration must be built into the software.  Due to high rates of drift I needed a easy way to re-calibrate in the field.     

After a very primitive calibration run,  I ran a quick check using a sodium chloride (table salt) calibration solution my readings after averaging ran +- 1.5% of the 75.3% expected which is within the Hysteresis readings of the HCH-1000-002 sensor.   Improved algorithms with more sophisticated averaging would make this more accurate.

The circuit is descried at http://correctenergysolutions.com/electronics/cap-humidity-sensor-circuit with schematic and bascom source and is free to use.   It basically uses a two digital IO lines one as a charge and the other as a sense.    We charge the capacitor circuit through a resistor with a diode for fast drain back.     We feed the sense line from the cap back to the micro controller.   The capacitor is fully drained before the feed line is activated.  We measure the time it requires for sense to convert from a  logic low to logic high in a tight loop with a counter.  Once the transition high on sense occurs the feed line is set to low which re-drains the sensor cap.      As the capacitor value rises or falls with humidity the count value rises and falls proportionately.    We measure the count in a tight loop because we found the variables in interrupt service for the timer caused undesirable variability in the readings.

We found a good count value with reasonable resolution using a 20 Meg feed capacitor on the HCH-1000-002  and a 40 Meg for the HS1101.   

One concern was that the transition from logic low to logic high is defined as a range so I thought it would be sloppy.   I checked this with no cap in circuit and by using a fixed capacitor.    When the variable cap is removed from the circuit it consistently takes 18 cycles to charge the circuit whereas when the capacitor is present it ranges from 1080 to   1300.   When we place a fixed capacitor in circuit it stays the same within a 6 or so cycles and normally stays within 1 cycle from test to test.   I interpret this as a consistent transition voltage from low to high on sense which is basically doing the same thing as a analog comparator.     

An analog comparator would probably be more accurate but I actually saw comparable variability up/down 1.5 to 3%  when reading the vout HM1500 sensors through the ADC and had to run an averaging algorithm anyway.    The difference is a sensor which is 4 times cheaper.    I am most worried about keeping total part count down and this solution only required 1 resistor, 1 diode and the sensor it self.