##### Child pages
• Capacitance Based Humidity Sensor
Go to start of banner

# Features

• Using a 555 timer to reflect changes in capacitance
• Sampling a microcontroller input to determine frequency

# Introduction

Many sensors use capacitance as an output, and a simple means of measuring it is useful.  This application note covers a method of converting the capacitive output of a humidity sensor to a frequency.  A microcontroller monitors this frequency and controls an output based upon a programmed threshold.

# Application

The sensor has a capacitance based on the relative humidity of its surrounding environment.  This capacitance changes non-linearly with humidity.  Each sensor has specifications defining a transfer function that describes the relationship between its capacitance and humidity.

The capacitance can be measured by several methods, each with its own merits and disadvantages.  The simplest method is to measure capacitance directly, but this requires a very accurate timing source when dealing with small capacitances.   Another method uses a relaxation oscillator, which is relatively expensive.  This application note focuses on a third method, which uses a separate timer with a counter.  This involves more components; however, it is ultimately less expensive, since it does not require precision timing components.

A 555 timer is central to this approach.  The 555 timer uses the sensor’s capacitance to create a square waveform.  A basis frequency is selected to correspond with the sensor’s capacitance at a given relative humidity.  This frequency is arbitrary, so long as it is comfortably within the frequency specifications of the 555 timer and humidity sensor.  The square wave’s period is calculated in equation (1).

(1)

C is the sensor’s nominal capacitance (at a specified humidity level).  Using equations (2) and (3), calculate R1 and R2 to achieve a duty cycle close to 50%.

(2)

(3)

For example, the Humirel HS1101 humidity sensor has a capacitance of 180pF at 55% RH.  Choosing a basis frequency of 6.5kHz yields a period of 154us, a tlow of 75.4us, and an R2 of 604kΩ.  Solving for R1 gives a 25kΩ resistance.

Figure 1 shows how to setup the 555 timer.  The resistor placed on pin 5 compensates for temperature changes (consult the manufacturer’s datasheet for suggested values).  A 1kΩ resistor is placed on the output for short circuit protection.

Figure 1.  555 Timer Circuit

A microcontroller monitors the 555 timer output frequency to determine the relative humidity.  One of the microcontroller’s timers is cleared and set up to count the low to high transitions on an input pin.  After a one second interval, the timer’s count equals the input square wave’s frequency, which corresponds to a specific relative humidity.  The humidity can be calculated using the sensor’s transfer function (or a lookup table), or it can simply be compared to a known threshold value.

# Example

The following example controls humidification in a large humidor.  The unit monitors the relative humidity and powers a fan to humidify the surrounding environment.  The fan is placed near a water source to provide humidification.  A preset threshold in the code sets the relative humidity level that engages the fan.  Between measurements, the unit resumes sleep mode.

This circuit uses the PIC12F683 with an internal 4MHz clock, a Texas Instruments TLC555, and a Humirel HS1101 humidity sensor.  The HS1101 is a capacitive type sensor that can operate from 0% to 100% relative humidity.  The source code (written in C) is provided in an accompanying zipped file.  The circuit is shown in Figure 2, and a complete parts list is provided in the Appendix.

Figure 2.  Humidor Example Circuit

As described above, the Humirel HS1101 humidity sensor has a capacitance of 180pF at 55% RH.  A basis frequency of 6.5kHz yields an R2 of 604kΩ and an R1 of 25kΩ.  Using standard values, R1 and R2 are 604kΩ and 25.5kΩ, respectively.

The PIC12F measures the 555 timer output frequency.  Timer0 is configured in input capture mode with a prescaler of 32, lowering the frequency resolution (by 32X in this case).   This prevents the count of low to high transitions from overflowing Timer0’s 8-bit register over the sample interval.  Lower resolution creates an accuracy error in the humidity calculation, but the computed humidity is within ±2.5% of the actual humidity and acceptable for this application.  An example of the error and hysteresis is shown in Figure 3.

Figure 3.  Visual Depiction of Test Samples

The frequency is compared to a known threshold and outputs are set accordingly.  (This example does not use the sensor’s transfer function to solve for exact humidity as precision is not imperative.)

The device then transitions into sleep mode.  The same input signal increments the internal sleep timer, Timer1.  When Timer1 overflows, the microcontroller wakes up, clears Timer0, and repeats the frequency measurement.  The sleep interval is dependent on the humidity level (e.g. higher humidity results in shorter sleep intervals).

The microcontroller controls an N-channel MOSFET to switch the fan on and off.  Since the control circuit and fan share a common power source, the fan’s inrush current can cause the voltage rail to sag, resulting in a microcontroller reset.  To alleviate this condition, a large capacitor placed near the fan provides charge during the fan’s startup.  Alternatively, soft starting techniques can achieve the same end.

# Conclusion

This application note describes one method of interfacing with capacitance based humidity sensors.  A 555 timer converts the capacitance to a frequency.  The microcontroller determines the frequency by counting the incoming pulses over a specified period.  It compares the result to a predefined threshold frequency and controls the appropriate output(s).