Reputation: 1628
I have a HIH-5031 humidity sensor and a MCP9700 connected to my raspberry pi.
Part of my code in python:
getSensorVsupply = adc.read_voltage(1)
getSensorTemp = (((adc.read_voltage(2)*1000)-459)/10)
getSensorVout = adc.read_voltage(3)
calcRH = ((getSensorVout/getSensorVsupply)-0.16)/0.0062
calcTrueRH = calcRH/(1.0546-0.00216*getSensorTemp)
SensorVsupply, is the voltage supplied to the sensors 3.31V
SensorTemp, is the output value of temperature sensor MCP9700 and presented in Celsius, let's say 25 The value of 459 is calculated offset during immersion in water of 35 degrees celsius. Yes I know it should be in 25C when reference measure, but the problem here where that the kind of reference meter I had, could'nt go below 30C with good tolerance.
SensorVout, is the HIH-5031 humidity sensor. It's radiometric and if I understand that correct, that means that if I supply it with 3.3V and output is 1.65 that would mean 50% humidity. Right now showing 1.11V
calcRH, my calculation to %RH, in this case 1.11/3.31-0.16/0.0062 => 28.28% And last one is true %RH, compensated by temperature. 28.28/1.0546-0.00216*25 => 28,26%
I have these sensors in a box in the garage. When I spray the box with water and seal it, after 20 min it have'nt gone up to more than RH 34%. Is my code for the sensor to calculate RH and TRH correct?
Might be useful to know that between gnd and senor output, I installed 90kohm instead of minimum requirements of 65.
Product HIH-5330: http://sensing.honeywell.com/honeywell-sensing-hih5030-5031-series-product-sheet-009050-2-en.pdf?name=HIH-5031-001
Product MCP9700: http://ww1.microchip.com/downloads/en/DeviceDoc/20001942F.pdf
Upvotes: 1
Views: 3154
Reputation: 1628
So, I found this site: https://www.ghielectronics.com/community/codeshare/entry/136
It confirms that my algorithm is ok. From the datasheet of the HIH-5030 one can read:
//#Honeywell HIH-5030 Formula Sensor Voltage Output (1st order curve fit)
//#Vout = Vsupply(0.00636(Sensor RH%)+ 0.1515), (Typical at 25 'C)
Now to the Math (how to actually get %RH) :
//y = z(mx + b) = mxz + bz = y =>
//y/z = mx + b = -b + (y/z) = mx =>
//-b/m + y/(zm) = x = -b/m + (1/zm)y
//y = Sensor Vout
//z = Vsupply = 3.3 V <--- A/D ref. voltage
//m = 0.00636
//x = Sensor RH% (0-100%)
//b = 0.1515
//x = -23.82075472 + 47.64627406y - Recompute formula above for different supply voltages.
//http://www.algebrahelp.com/calculators/equation/
Then for temperature compensation:
//xt = Sensor RH% (0-100%) temperature compensated
//xt = (x*1.0546)-(0.00216*getSensorTemp)
Hope this helps someone more than me! Cheers!! :)
Upvotes: 2