Translate

Tuesday, 6 May 2014

Arduino dehumidifier controller project.

OK, so last year I moved into my lovely new house. Well, it wasn't lovely at the time, pink walls, and green carpets, and no Earth! However it was well insulated. Very well insulated. Cavity wall insulation, many mm of loft insulation. Great. Well that's what I thought. It turns out that the new building regs that require many mm of loft insulation are all very well in new build houses that are designed to take it. They have well ventilated loft spaces or "warm lofts" where the loft is insulated with Kingspan (other insulation manufacturers are available) just below the tiles. This isn't the case with my old house. My house was built when I was born, but the insulation had been "upgraded". Many mm of that hairy glass fibre stuff above the ceiling. This had caused a major issue with condensation in the loft. Insulation was so good, the loft space would stay considerably cooler in the winter months and condensation would literally rain down from the membrane under the tiles. This "rain" then soaked into the hairy glass fibre stuff, holding the water and waiting for the next bit of heat to evaporate it and start the cycle again. Not good. Not good at all. To temporarily fix the issue, I nipped down to our local Argos, and purchased the cheapest dehumidifier I could find. Change out of £100. Problem solved... but what about my energy bill running the damn thing? I would probably have been better to remove the excess loft insulation! Now, I've done a fair amount of research into this whole condensation thing. The answer might be ventilation. Chop some holes in the (probably asbestos) soffit, pull back the excess insulation form the edges to expose said holes, and it might solve the problems. My roofing bloke Gary said it might. I might also drop dead of some asbestos related cancer in 30 years time. Nah... this calls for an engineering solution....

... enter the world of climate control!

So, the thought process goes a little like this. I need to bring the dehumidifier on when it gets sweaty up there.... OK. I think back to my days of video recorder repair. They had a little ceramic dew sensor on the video head drum, that would shut the machine down if there was condensation on the head drum, thus preserving your beloved pirate copy of ET from getting minced....

So, I search out such a sensor...



How does it do? Well, it needs AC to operate for a start, about 1KHz, and the RMS voltage quite tightly regulated, and it's impedance measured to give you a "sweaty" or "not sweaty" reading.
After a few evenings mucking about with op-amps, it works. Not very well. At all. No. Whilst it may be fine for preventing the tape from getting wrapped up in your aging VCR, it's no good for switching on my dehumidifier.
Right, enter the DHT 11....
A super little chap, which can be had on eBay for peanuts. Fewer peanuts than his analogue colleague above, which surprises me, as he's got one of those inside him.

So, we give him a nice 5 volts, a ground and he dutifully outputs temperature and humidity on a single wire serial interface. Superb.
And someone's written an Arduino library for the little chap too. Super.
So, armed with an Arduino Uno, an uninterrupted Sunday morning... the super dehumidifier conrtoller is born.

So, you'll need an Arduino of some description. I developed it on an Uno, them built it up on a Pro Nano copy (£1.75 from China... £1.75!!!!) as I like the size. Field in a nice Hitachi HD44780 display clone with a nice blue backlight, and you have it.

You'll need the DHT11 library from here.

and cut and paste this delightful code into the Arduino thingy:



// 
// FILE:  dehumid.pde
// Written by Andy Doswell 4th May 2014
// PURPOSE: DHT11 sensor with LCD Display and output for controlling dehumidifier.
// Dehumidifier is controlled by a relay attached to pin 7, defined in rlyPin.
// DHT11 sensor is connected to 8, as defined in #define
// LCD is a Hitachi HD44780 or compatible, attached thus:
// LCD RS pin to digital pin 12
// LCD Enable pin to digital pin 11
// LCD D4 pin to digital pin 5
// LCD D5 pin to digital pin 4
// LCD D6 pin to digital pin 3
// LCD D7 pin to digital pin 2
// RW to GND
// V0 Held high (this may or may not work with your LCD, usual practice is to connect this to a 10K pot between +5 and GND)
// delta max = 0.6544 wrt dewPoint()
// 6.9 x faster than dewPoint()
// reference: http://en.wikipedia.org/wiki/Dew_point
double dewPointFast(double celsius, double humidity)
{
 double a = 17.271;
 double b = 237.7;
 double temp = (a * celsius) / (b + celsius) + log(humidity*0.01);
 double Td = (b * temp) / (a - temp);
 return Td;
}


#include <dht.h>

dht DHT;

#define DHT11_PIN 8

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

// define constants & global variables
const int rlyPin = 7; //defines pin the relay is connected to. relay is active low
int WatchDog = 0; //watchdog default
const int TimerLength = 1800;// number of seconds in an hour / 2 - this sets the minimum time the dehumidifier will remain on for.
int Timer = 0; //timer is off to start
boolean Dew = false; // This is the dew flag. Off as default.

void setup()
{

  lcd.begin(16, 2); // defines the LCD as a 16 x 2
  pinMode (rlyPin, OUTPUT); // sets our relay pin
  digitalWrite (rlyPin, HIGH); // sets the relay off for default condition.

}

void loop()
{
  int chk = DHT.read11(DHT11_PIN); // these 4 lines get data from the sensor
  int dew = dewPointFast(DHT.temperature, DHT.humidity);
  int temp = (DHT.temperature);
  int humidity = (DHT.humidity);
  
  int dewTrip= dew + 5; // Brings the dehumidifier on 5 deg C before the dew point. 

// writes information about the system to the LCD
  lcd.clear ();
  lcd.print("Humidity:");
  lcd.print(humidity);
  lcd.print("%");
  lcd.setCursor(0, 1);
  lcd.print(temp);
  lcd.print((char)0xDF);
  lcd.print("C");
  lcd.setCursor(6, 1);
  lcd.print("Dew:");
  lcd.print(dew);
  lcd.print((char)0xDF);
  lcd.print("C");

// Dew detect loop. If the dewTrip point is reached, start the timer running and set the Dew flag
  if ( temp <= dewTrip ) {
    Dew = true;
    Timer = 1;       
  } 
  else {
    Dew = false;
}

  
  if (Timer >= TimerLength and Dew == false) { // If the timer has expired and there's no dew, switch the dehumidifier off.
    Timer = 0;
    digitalWrite (rlyPin, HIGH);
   
  }

  if (Timer !=0) {                // If the timer is running, switch the dehumidifier on , and write On to the lcd.
    digitalWrite (rlyPin, LOW);
    lcd.setCursor (13,0);
    lcd.print ("On");
    Timer++;
  }
  
 else {
   lcd.setCursor (13,0);
    lcd.print ("off");
 }
  
// Watchdog loop - blinks a curson in the bottom right of the LCD, just to let us know the thing is still running
  if ( WatchDog == 0 ) {
    lcd.setCursor (15, 1);
    lcd.print (" ");
    WatchDog++ ;
  }
  else {
    
    WatchDog-- ;
    lcd.setCursor (15, 1);
    lcd.print ((char)0xFF);
  }
      


  delay(2000); // we can only get data from the sensor once every 2 seconds.
}
//
// END OF FILE
//
So here it is ....

Most of what you see on the perf-board is the power supply. You can see the DHT-11 and the very pretty white on blue LCD with essential information.
The code calculates the dew point, and switches the relay (that's the blue box hiding behind the mains transformer on the perf-board, another Chinese eBay purchase)when the actual temperature gets to within 5 deg C of the dew point. The relay will switch on the mains supply to the dehumidifier, and leave it running for an hour. Smashing. This should prevent condensation, not just clear it up after it forms. Get it boxed up and stashed in the attic.....
... but wait ... that lovely blue and white LCD display... hiding out of sight in the attic... oh what a waste. What's needed here is a wireless external display... just shows how these jobs can snowball....



5 comments:

  1. Nice blog! I have a friend that has been looking for portable dehumidifiers for a project that she has coming up.

    ReplyDelete
    Replies
    1. There's a few updates along the way, the last being http://andydoz.blogspot.co.uk/2014/12/arduino-dehumidifier-controller-failure.html
      Enjoy!

      Delete
  2. I want to offer my family a healthy life and this is why, we use Electric Dehumidifier in our home. For me, a dehumidifier is a "must" because we live near a lake in mountains.

    ReplyDelete
  3. Really very interesting and very valuable information about the Monitor nice work.



    Monitor

    ReplyDelete
    Replies
    1. Thanks Justin. Check out the GPS master clock too. Uses a similar routine, but just shows how flexible transmitting a struct is. http://andydoz.blogspot.co.uk/2016/07/arduino-gps-master-clock-with-433315.html

      Delete