So conceptually this is like a thermistor - the resistance varies with the variable to measure - you would use a resistor divider with
the sensor in series with a fixed resistor.
However this device must recieve pure AC (no DC component or it'll be destroyed electrochemically). This complicates things.
Since the device is relatively high resistance we can power it from two digital pins driven in anti-phase (one is HIGH when the other is LOW).
We switch the pins over every 0.5ms and this is then a 1kHz square wave (pure AC). between the pins we wire the sensor and a 100k
resistor in series (so that the divider is roughly midrange at 50% humidity at 20C - most common case?).
Since the circuit is high impedance (> 10k) we then need to read the voltage at the midpoint of the divider twice (to allow time for
code would be something like:
#define DRIVE1 ?? // the antiphase drive pins
#define DRIVE2 ??
#define SENSE A0 // analog input
#define PERIOD_US 1000 // for 1kHz, or use 10000 for 100Hz
#define HALF_PERIOD_US (PERIOD_US/2)
unsigned long prev_time;
void setup ()
pinMode (DRIVE1, OUTPUT) ;
pinMode (DRIVE2, OUTPUT) ;
prev_time = micros () ;
byte phase = 0 ;
float voltage ;
void loop ()
.. do any other stuff here if only takes a few 100us ...
while (micros () - prev_time < HALF_PERIOD_US) ; wait for next 0.5ms time segment
prev_time += 500 ; // set up for the next loop
digitalWrite (DRIVE1, phase == 0) ; // antiphase drive
digitalWrite (DRIVE2, phase != 0) ;
int val = analogRead (SENSE) ;
val = analogRead (SENSE) ; // second read allows much longer for high impedance reading to settle
if (phase == 0)
val = 1023 - val ; // reverse sense on alternate half cycles
voltage = 5.0 * val / 1024 ;
phase = 1 - phase ;
You can run the loop slower or faster, the datasheet says 100Hz upto 5kHz will work.