Wednesday, April 10, 2013

Home Automation with Raspberry Pi

In this blog I want to describe how I reduce humidity in my basement without using an energy consuming air dryer. So the control system I implemented is blowing air into the basement, when the air outside of the house is dryer, then inside the basement.

The control system

I have installed two ventilators, five temperature sensors and one humidity sensor in my basement. I installed one humidity sensor outside of my house, as well. The humidity sensors measure the relative humidity, but the sensors translate the values into absolute humidity by doing some math (see here).  Below a picture of the controllers. The right circuit (red) is a controller for the ventillators. It contains two S202 S12 solid state relais to control both ventillators. The controller has a CAN interface to communicate with the left controller. The left controller (green) gathers the temperatures, humidity values from all sensors installed in the basement. It has a CAN interface and 1 wire bus interfaces. Also the circuit has a 24LC1025 eeprom to store the gathered data persistently. I used DS18B20 temperature sensors and connected them directly to the 1 wire bus coming from the controller. Both controllers use at90can128 mikrocontrollers.

The controllers have USB ports. When I wanted to get all measured values onto my laptop, I had to go down to the basement and dump out the eeprom values from USB. In the picture below you can see the humidity values of both humidity sensors from the eeprom dump. The data was gathered from mid 2011 to beginning 2013. In the middle of the curves you can see two lengthy interruptions. I switched off the control system, because I was renovating the basement.

This data gathering was pretty time consuming, so I prefered to have wireless and get the data from the living room or from the office. I needed something that works with wireless on the one hand, and retrieve the sensor data from the controller's eeprom on the other hand. So I came up with the raspberry pi.

Bringing in the raspberry pi

The raspberry has SPI and I2C ports, but no CAN. So I need something which translates SPI (or I2C) to CAN. There are chips available for doing this. Such as the MCP2515 . The chip is widely available, and runs with 3.3V which can be powered from the raspberry pi. Also I needed another chip which is a CAN transceiver. It connects the MCP2515 chip to the CAN bus. I used SN 65HVD230D, which is also widely available and which operates also on 3.3V.

This is the schematic:

I soldered this all together with silver wire and now it looks like this from top, see picture below. On the left upper corner in the picture below you find the raspberry pi. On the buttom right corner you find the components from the schematic above:

On the raspberry runs the wheezy operating system which can be downloaded here. In its forum I described what I have done to install the necessary software to get the raspberry working with SPI, so see CAN for home automation, in case you are interested. The latest wheezy versions have a straightforward way to get the WLAN USB stick running (WIFI config on the wheezy screen). I used the EW-7811UN from EDIMAX.

I created a couple of C functions to retrieve the eeprom data from the basement's controller via CAN. CAN for home automation forum entry describes what I have used to create the functions. The problem with CAN is, that it is rather slow. I cannot dump each time the eeeprom if I want to see the whole curve. This would take more than 5 minutes. So I installed mysql on raspberry and dump all eeprom values into a database. I implemented another script which queries the controller's eeprom once a day for new data and the data is stored into the database. 

The User Interface

As a last step, I needed a user interface. I decided to use a web server and implement a web page to display the data. After little research I found ligtttp and installed it on the raspberry. The decision came mainly because I found somewhere a website which helped me to get this installed easily. lighttpd has perl support, which is convenient for me, because I did not have to learn yet another language like php or python. Also perl has excellent support concerning date calculation needed to setup a time period. So I configured lighttpd to support CGI and wrote the dynamic webpage in perl. I created a login page and a curve display page. The curves I created with gnuplot. It needs to be installed on the raspberry and it works fine, some more information you can find here. Below you can see a snap shot from the webpage:

In the snap shot above you see menu boxes to setup the time period and three more curves. The upper curve above shows the relative humidity values during the time period mid 2011 to beginning 2013. The middle curve shows the temperatures values from the humidity sensors. And the lower curve shows the calculated absolute humidity from both curves. So each time the absolute humdity values of the one curve is above the other, the ventillators are turned on automatically for a short period of time (around 20 min.).


For now, I am pretty happy with my implementations. I can go into my office and take a look into my basement sensor values, and make my thoughts about them. But I was thinking, it would be good to have rain information added to the curves above. Rain information could give me a indications if the humidity values are correlated with the rainy weather. They probably are, but it would be nice if that graphic shows this as well. So it seems that there is more to come.

No comments:

Post a Comment