Translate

Friday 30 May 2014

Wireless Dehumidifier Controller Completion.

The new transmitter and receiver pair duly arrived, fitted and tested. Great range now. I haven't fully tested it's range, but it works beautifully from my attic to my workshop on the ground floor. During testing I became aware of other transmitters sending data on the same channel every now and again (remember my doorbell and weather station?) Perhaps sending data at such a slow datarate every 2 seconds is a bit anti-social, likely to clutter up the band a bit, and is unnecessary, so I've altered the sketch to send the data every 18 seconds.


Finished receiver in a Hammond clear blue case. Posh eh?

Powered from a redundant mobile phone charger (see note below).








Display on the receiver.











A note on aerials. The aerial (or antenna if you must) is simply 173mm of copper wire. Keep it as straight as possible and vertical. 

For the revised transmission rate, only the transmitter sketch changes. The receiver remains the same.

// 
// FILE:  wireless_dehumid.pde
// Written by Andy Doswell 24th May 2014
// PURPOSE: DHT11 sensor with LCD Display and output for controlling dehumidifier.
// Data send via virtualwire and 433MHZ link to remote display
// 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)
// TX connected to pin 10
// 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 <VirtualWire.h>
#include <VirtualWire_Config.h>

#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
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 DewFlag = false; // This is the dew flag. Off as default.
boolean OutputStatus = false; //Output status is off as default
int chk;
int Temp;
int Dew;
int Humidity;
int DewTrip;


// Data structure set up for Transmission

struct TXData
{
  int TX_ID;
  int Temp;
  int Humidity;
  int Dew;
  boolean Output;
};
  

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.
  
  // Virtualwire setup
  vw_set_tx_pin(10); // TX pin set to 10
  vw_set_rx_pin(9); // RX pin set to a spare pin, even though we don't use it. If left as default it interferes with LCD operation.
  vw_setup(300); //sets virtualwire for a tx rate of 300 bits per second
  

}

void loop()
{
  for(int i = 0; i < 10 ; i++) { //transmit only every 9 loops (18 seconds)
    chk = DHT.read11(DHT11_PIN); // these 4 lines get data from the sensor
    Dew = dewPointFast(DHT.temperature, DHT.humidity);
    Temp = (DHT.temperature);
    Humidity = (DHT.humidity);
    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 ) {
      DewFlag = true;
      Timer = 1;       
    } 
    else {
      DewFlag = false;
    }

  
    if (Timer >= TimerLength and DewFlag == 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");
      OutputStatus = true;
      Timer++;
    }
  
    else {
      lcd.setCursor (13,0);
      lcd.print ("off");
      OutputStatus = false;
    }
  
 delay (2000);
  }
  
struct TXData payload; //Loads the Data struct with the payload data
  
payload.TX_ID=10;
payload.Temp = Temp;
payload.Humidity = Humidity;
payload.Dew = Dew;
payload.Output = OutputStatus;
vw_send((uint8_t *)&payload, sizeof(payload)); //Transmits the struct
vw_wait_tx(); //waits for the TX to complete

}  
  
//
// END OF FILE
//


The receiver is powered from a redundant mobile phone charger, rated at 5V at 800mA. I was quite surprised to find it's off load voltage to be just under 7 volts. I expected it to be regulated. I fitted a 7805 voltage regulator inside the case. I was worried if the 7805 had enough headroom, but it seems to function well enough.

Saturday 24 May 2014

Arduino dehumidifier controller project - Wireless update!

Some spare time over the weekend means I can finally crack on with this!

After experimenting with a number of methods of sending and receiving data, I came across the virtualwire library here: http://www.airspayce.com/mikem/arduino/VirtualWire/

Now, there's a few things to note. Whilst surfing the various boards, there's talk of virtualwire only being able to send characters, which makes sending an integer a bit of a bind. There's people doing itoa's and atoi's back again. What happens if you need to send multiple values like we do? Temperature, humidity etc? We'll have to sync the transmitter and receiver for the first time... then what happens if a packet is dropped? It was all a bit much really, and sending integers as character arrays was all a bit wasteful of bandwidth. 

Now virtualwire is great, it takes care of manchester coding your data, and provides a bit of pre-amble so your simple receiver can sort out it's agc before outputing data. It's data is defined as uint_8 .... hang on ... that's a byte isn't it? So why can't I send an integer? It's just data ... 

So, pencil and pad at the ready, and a bit of a read about struct in by big book of C and we can create a custom message, with a unique identifier (just in case someone rings my wireless doorbell or my wireless weather station happens to transmit at the same time and corrupts our message, or indeed preventing our receiver attempting to decode such a message!)

For testing purposes, the two arduinos (arduini?) were linked by a bit of wire instead of the RF link. (Connect your output pin to the input, and link the grounds.)

Data rate during testing was 2000 bits per second.
Once the RF link was added I reduced this to 300 bits per second to make the link a little more robust.

Even reducing the data rate to 300 bits left me with woeful range, so I investigated. Output from the transmitter seemed good on the spectrum analyser, on frequency and plenty of output. 
Output from the receiver was noisy and it appeared the receiver was particularly "deaf". 
I used a frequency source to sweep the receiver, to see if it was tuned in accurately, my thinking being there's a nice big coil on the top to tweak! Sweeping the tuner found it tuned to 315MHz! Great. A 433 TX and a 315 RX. It was amazing it worked at all on the bench! Thankfully the supplier has agreed to send me out a new set, so hopefully It'll be wireless soon enough! 

Here's the transmitter code:-



// 
// FILE:  wireless_dehumid.pde
// Written by Andy Doswell 24th May 2014
// PURPOSE: DHT11 sensor with LCD Display and output for controlling dehumidifier.
// Data send via virtualwire and 433MHZ link to remote display
// 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)
// TX connected to pin 10
// 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 <VirtualWire.h>
#include <VirtualWire_Config.h>

#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
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 DewFlag = false; // This is the dew flag. Off as default.
boolean OutputStatus = false; //Output status is off as default

// Data structure set up for Transmission

struct TXData
{
  int TX_ID;
  int Temp;
  int Humidity;
  int Dew;
  boolean Output;
};
  

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.
  
  // Virtualwire setup
  vw_set_tx_pin(10); // TX pin set to 10
  vw_set_rx_pin(9); // RX pin set to a spare pin, even though we don't use it. If left as default it interferes with LCD operation.
  vw_setup(300); //sets virtualwire for a tx rate of 300 bits per second
  

}

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");
  
  struct TXData payload; //Loads the Data struct with the payload data
  
  payload.TX_ID=10;
  payload.Temp = Temp;
  payload.Humidity = Humidity;
  payload.Dew = Dew;
  payload.Output = OutputStatus;
  
  vw_send((uint8_t *)&payload, sizeof(payload)); //Transmits the struct
  vw_wait_tx(); //waits for the TX to complete
  
// Dew detect loop. If the dewTrip point is reached, start the timer running and set the Dew flag
  if ( Temp <= DewTrip ) {
    DewFlag = true;
    Timer = 1;       
  } 
  else {
    DewFlag = false;
}

  
  if (Timer >= TimerLength and DewFlag == 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");
    OutputStatus = true;
    Timer++;
  }
  
 else {
   lcd.setCursor (13,0);
    lcd.print ("off");
    OutputStatus = false;
 }
  
 delay (2000);

}
//
// END OF FILE
//





and the receiver code:-




// Receiver Sketch for Dehumidifier controller project
// Written by A.G.Doswell 23 May 2014
// 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)
// Receiver connected to pin 9


#include <VirtualWire.h>
#include <VirtualWire_Config.h>
#include <LiquidCrystal.h>

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

int TX_ID =10;
int Temp;
int Humidity;
int Dew;
boolean Output;



void setup() {
              lcd.begin (16, 2);
              // Virtualwire setup
              vw_set_tx_pin(10); // Even though it's not used, we'll define it so the default doesn't interfere with the LCD library.
              vw_set_rx_pin(9); // RX pin set to pin 9
              vw_setup(300); //sets virtualwire for a tx rate of 300 bits per second, nice and slow! 
              vw_rx_start();     
              }  
void loop()
{
typedef struct rxRemoteData //Defines the received data, this is the same as the TX struct
{
int    TX_ID; 
int    Temp;   
int    Humidity;
int    Dew;
boolean Output;
};

struct rxRemoteData receivedData;
uint8_t rcvdSize = sizeof(receivedData);

if (vw_get_message((uint8_t *)&receivedData, &rcvdSize)) 
{
  if (receivedData.TX_ID == 10)     { //Only if the TX_ID=10 do we process the data.
    lcd.setCursor(13,0);
    lcd.print (" Rx");
    delay (100);
    int TX_ID = receivedData.TX_ID;
    int Temp = receivedData.Temp;
    int Humidity = receivedData.Humidity;
    int Dew = receivedData.Dew;
    boolean Output = receivedData.Output;
    
        
      // writes the received data 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");
  
  if (Output == true) {
      lcd.setCursor (13,0);
      lcd.print (" On");
    
  }
     else {
       lcd.setCursor (13,0);
       lcd.print ("off");

           }
  
      } 

  }
}

// End of file

Let me know if this has been of any use...  but for now I have a nice dry loft!

Saturday 10 May 2014

His Master's Voice 1373

I was going to push on with the dehumidifier wireless controller this weekend, but I've hit an issue. The LCD display I had in stock turns out to be duff, so I'll wait for the others to arrive from China.

In the meantime, a friend bought this in for repair. It's a 1958 HMV Radio. Long and medium wave only, superhet.

Nice maroon cabinet, would suit a West Ham supporter.










PCB in grubby condition. Some evidence of  a burn up by the thermistor.


Took the mains electrolytic capacitor out, and left it on a high voltage, current limited supply overnight to reform. It came up very well. Both 50uF sections measuring 52uF, and both having an ESR of less than an ohm. Not bad for a 56 year old capacitor!  There's a few "Hunts" capacitors that we'll need to change, and an old Plessey electrolytic decoupling the cathode of the output amplifier, so we'll change that as a matter of course.
PCB removed and cleaned up in the sink....

..... Followed by an hour in the oven at 50 deg to dry it out.....
Caps changed, and reassembled.
... and gently on with some power....



The speakers buzzing a little, but we can fix that, and there's a dial lamp out. I've ordered a couple of replacements.




Wednesday 7 May 2014

New 433 MHz Transmitter and receiver pair have arrived courtesy of the lovely people at QQLX.co.uk . Now to revise the hardware & software


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....



Monday 5 May 2014

In the beginning...

Right... Here's the plan. I need somewhere to stash bits and pieces of projects, so it may as well be on a blog and available to the world. It's good to share.

I'm open to comments, advice, criticism etc so feel free to join in.

A bit of background. I'm an electronics engineer, currently involved in the calibration of some ancient analogue electronics somewhere in the UK. In my spare time, I little to play with stuff. Old stuff generally. If it's got valves in, more's the better.