The DHT22 is a low cost sensor which can provide measurements of relative humidity and temperature.
While carrying out maintenance on the ground floor of our house, it became clear that we had damp & ventilation problems below the suspended wooden floor.
So what better way of monitoring the situation than by using a moisture sensor hooked up to a Raspberry Pi?
|Spikes & bumps are mainly due to the sensor being disturbed by our builders|
I bought this DHT22 back in 2014 and posted some notes here. But up to now, I haven't had reason to use it.
Home Sweet Home
Built in the early 1930s, our house had a couple of problems that had been bothering me for the last 20 years. One of these was the air-bricks. Over the years, previous owners had raised the level of the driveway such that the air-bricks were eventually several inches below the new ground level.
|Ventilation or drainage?|
Lifting the floor boards in the lounge revealed a strong, rather damp smell, and some evidence of localised woodworm infestation. After removing bucket loads of cement dust and general builders debris, we replaced 60% of the timber and treated the remaining boards, joists and sleepers with a woodworm solution.
We also removed a lot of soil, and we flooded certain problem areas of the sub-floor (i.e. where soil was visible or the concrete was thin) with fresh concrete. The final structural task was to remove the existing air-bricks and fit the telescopic variety. These allow the external vent to be a few bricks higher than the internal vent.
|Telescopic air-brick assembly|
Although I didn't measure the moisture level before these mods, I'm curious to monitor both temperature and relative humidity over the coming year or so. However, I have to admit that I don't know what I'm looking for.
All I know about RH (relative humidity) is that the mathematics are quite complicated. Very basically, the RH is based upon the moisture and the air temperature. If the daytime temperature in your garage was 25'C and RH 50%, and then if the temperature dropped overnight to 15'C, the humidity would rise to 100% and everything would be damp in the morning.
I need a low under-floor RH for it to stay nice and dry down there. However, the air coming in through the air-bricks is the only control.
As I write this, the outside RH is about 60% at 14'C. The under-floor RH is about 75% at 15'C. So the RH trend should be downwards. However, I've just had the lounge plastered, so there are bucket loads of water trying to escape the walls and get back into the atmosphere.
To summarise, I don't know what I'm expecting, but will monitor it anyway!
Using wiringPi with the DHT22
Please see this earlier post for wiring details, and how to capture and display results from the DHT22 in a terminal window. This post also gives details of using wiringPi with Gambas, but I want to elaborate a little.
In order to create a single wiringPi library that can be used with Gambas, edit the wiringPi.c file to include the code from maxdetect.c which is located in the devLib folder. You can basically copy everything starting from the section:-
...and paste it into wiringPi.c at the end of the file.
Now build wiringPi again by running ./build from the wiringPi folder.
The Gambas code
Open a new project and add a timer and 2 labels.
In the main class, start by referencing the library and declaring a couple of its methods:-
' Gambas class file
Public Extern wiringPiSetup() As Integer
Public Extern readRHT03(iPin As Integer, ptrTemp As Pointer, ptrRH As Pointer) As Integer
Add public declares:-
Public lngReadings As Long 'a count of readings
Public lngErrorCount As Long 'a count of errors report by wiringPi
Public lngErrorStepChange As Long 'a step change in reading error
Public blnStarted As Boolean
Public intLastTemp As Integer
Public intLastHumid As Integer
Initialise wiringPi as the form opens:-
Public Sub Form_Open()
Add a method to read the sensor on the required pin (I'm using 15):-
Public Sub ReadSensor()
Dim iReply As Integer
Dim intTemp As Integer
Dim intRH As Integer
iReply = readRHT03(15, VarPtr(intTemp), VarPtr(intRH))
If iReply > 0 Then
If blnStarted Then
If intTemp > intLastTemp + 50 Or intTemp < intLastTemp - 50 Then
If intRH > intLastHumid + 50 Or intRH < intLastHumid - 50 Then
blnStarted = True
intLastTemp = intTemp
intLastHumid = intRH
Label1.Text = CStr(intTemp / 10) & "'C"
Label2.Text = CStr(intRH / 10) & "%"
Me.Text = "Readings: " & lngReadings & ", Errors: " & lngErrorCount & ", Step errors: " & lngErrorStepChange
Set the timer Enable=True and Delay to 5000ms. Then add the timer code:-
Public Sub tmrRead_Timer()
That should be enough to test the sensor and give clues to any problems. The "step change" checks are just to evaluate the frequency of any wild readings: you shouldn't really get any of these errors, as the wiringPi code does a lot of error checking.
The other errors occur when the wiringPi C code encounters errors: I see quite a few of these. However I don't see this as a big problem, because my application only needs a good reading every 15minutes.
My Pi server runs this code and produces an HTML page with some PHP code so that I can view the graph remotely, on my laptop (see the graph at the top of this page).
The DHT22 probe
In a few weeks, both rooms supported by this wooden suspended floor will be covered by oak flooring, making further access extremely difficult. However, the "under-stairs" area (which is located between the 2 rooms) will still have a couple of unsecured floor boards.
|Sensor on a stick!|
So I have mounted the DHT22 sensor, the decoupling capacitor and the pull-up resistor into a short length of plastic conduit, the kind that has a snap-down cover. I've used a length of CAT5 cable to connect the sensor back to my Raspberry Pi server.
As the suspended floor rests on brick piers with ventilation gaps, I can slide my sensor under the floor through a gap into the sub-floor area for either of the 2 rooms.
A follow-up post: http://captainbodgit.blogspot.co.uk/2017/03/is-it-damp-under-my-house-part-2.html