Measuring capacitance of humidity sensor

If anyone is interested I put together some code and documentation for measuring the capacitance of a Smartec HS07 (SMTHS07) humidity sensor. Obviously, something like a DHT22 is a much more convenient solution but I wanted to see what the result would be from a direct capacitative measurement. Also, the code can be used for measuring capacitance in general. It’s not comprehensive enough for a proper Particle library, methinks, it’s more of a code snippet actually, so I’m keeping it at GitHub:

As the ADC inputs of the STM32 chips are unbuffered, I ran into some problems, and I have therefore used an op-amp to interface the sensor. If anyone has an idea on how to get the variance of the measurements down, I would be very grateful. However, I suspect the fact that I need to measure on a microsecond scale but only get whole microseconds (using micros()), is a strongly contributing factor.

You can use System.ticks() to measure times shorter than a microsecond. There’s also ticksPerMicrosecond() to convert the number of ticks back to microseconds.

Thanks, Ric. Hadn’t seen the ticks functionality before. It wasn’t under Time in the firmware reference; didn’t think to look in System. Will try it out shortly.

It made quite a nice difference and the variance decreased markedly. The figure generated with the Core measuring; the Photon would give even better results.

1 Like