In a previous post I’d looked at 1-wire interface for temperature sensors to get the temperature from a 1-wire device.
For the next part I purchased a combined Temperature, Humidity sensor from Sheepwalk Electronics at http://www.sheepwalkelectronics.co.uk/product_info.php?cPath=23&products_id=55
This device is actually a HIH-4031 analogue humidity sensor with a DS2438 for the conversion to digital for the 1-wire bus. As mentioned there is also a temperature sensor.
The important bit is that you read it like a AD container and not as a humidity container. From the AD container we have two voltages that we need access to, with indexes 0 for the Main Voltage (around 5v) and 1 for the humidity sensor reading. We can get these by simply doing a readDevice,
doADConvert and getADVoltage for each AD container using the double data type for precision.
Then we need a reading from the temperature sensor with the same unique 64 bit 1-wire ID.
At this point we have a some voltages and a temperature.
The next part is to use a formula to determine the humidity from this (Thanks to Paul at Sheepwalk Electronics for help with this)
((((voltageHumid/ voltageMain) – 0.16) / 0.0062) / (1.0546 – (0.00216 * Temp))
This, when rounded to four decimal places, will give us a humidity value we can store in a tidy SQL Server data type of decimal(9, 4)
This is the same data type we used for the temperature so we can use the same table in our SQL Server database and use a typeID as a foreign key. We can also store the temperature reading from the humidity sensor providing a useful double sensor.
My Takeaway: Get playing with technology, Again!