loading

MyHome - home automation with Arduino and XBee

Picture of myHome - home automation with Arduino and XBee
Overview.png
Overview ver1.jpg
**** UPDATED ******
Ver 2.0
- added Nexa power outlet control
- added one wire temperature sensors
- added control of stuff via Google Calendar Events
***********************
Hi all,

This is the story about my project "myHome". I wanted to build a system for monitoring temperatues, electricity and oil usage and maybe in the future control an AC unit or why not the locks, drapes and my Moccamaster...

Parts in myHome:
Wireless sensors units:
- XBee sensor units for temperatures.
- Arduino + XBee unit for electricity monitoring from the blinking LED on the houses main circuit board
- Arduino + XBee unit for monitoring oil burner from a LED which lights up when burner running
Server running Windows 7:
- XBee reciever connected with a FTDI USD cable
- Python script to recieve XBee signals and insert sensor values into mySQL database
- mySQL database on server
- Python script to get current and forecasted outside temperature from nearby airport and write this to database
- Apache webserver for showing charts, and in the future web based functionality to do stuff in the home
 
Remove these adsRemove these ads by Signing Up

Step 1: Temperature Sensors

Picture of Temperature Sensors
IMG_5742.JPG
IMG_5744.JPG
These are XBee series 1 radios sittin on top of Adafruit Adapters. I chose their adapter as I wanted to solder it together myself and their guides are really good.

For the temperature sensor I chose the cheap TMP36 sensors. Their voltage differs in relation to temperature. This voltage is connected to the analog ports on the XBee.

The XBee radios are configured to sleep the maximum time (about 5 min) and then grap just 1 set of analog voltages and send it to a coordinator XBee using API mode. The config file is attached. You can open it in a text editor to see the settings.

At first I used 4 AA batteries to power the radios but as they couldn´t last more than about a week at the time I switched to old Nokia chargers.

I used 3.5mm plugs for sensors and the power.

This unit is in the bedroom which is the room that is most relevant for this monitoring. The room is either heated with a heating element which burns oil (baaaaad) or with a fireplace (goood).

Any suggestions on how to cover the fireplace sensor and cord so it doesnt look that ugly??? It´s not an option to move the sensor as I want to monitor that exact spot (it the hottest).

Step 2: Electricity usage sensor unit

Picture of Electricity usage sensor unit
IMG_8466.JPG
On most household electricity meters there is a LED that pulses  every time a certain amount of Watts have been used. On mine one pulse means 0.8Wh used. This was printed next to the pulsing LED.

Of course you could remove the LEDand direclty grab the pulse from there but as I have a great respect for that box I didn´t dare to dismantle it. Instead I decided on placing a light sensor on top of the LED and get the pulses this way.

Without properly studing light sensors I first ordered some "photo cells" but quickly realized they cant pick up a quick pulse. Instead I got some Photo Reflective Sensors that have a light and IR sensor. With this sensor there was no problem to catch the pulses. Of course I had to cover the area around no to let any additional light in.

How to count the pulses? First I wanted to do this just with the XBee but as I couldn´t figure out a way to easily do it I put a Arduino to provide some logic. The sensor is attached to an analog port and the Arduino does a count++ every time it senses a pulse. A counter on the Arduino counts to 60 seconds and then sends the count over XBee to a coordinator. The Arduino is actually a clone by Seeeduino.

Arduino sketch and XBee config attached.

Step 3: Oil burner runtime sensor unit

Picture of Oil burner runtime sensor unit
IMG_5725.JPG
IMG_5727.JPG
This is pretty much the same thing as the electricity monitor except for a few differences. The burner has a LED that lights up while the burner is running. So now we are not counting LED pulses but seconds over period of time when LED is lit. I choose 5 minutes.

On the Arduino I have a LED that is normally green and when the burner is running it switches to red.

Arduino code and XBee config attached.

At this time I dont know how much oil the burner burns per second. This depends on the nozzle inside. There should be a print on the nozzle indicating gallons per minute (I think) but I havent gotten around to check mine yet. Another way to get this info is of course to instead take the oil from a bottle or such and compare how much is spent over the time used. I´ll probably do this before next winter...

Step 4: XBee Reciever unit (coordinator)

This is the unit connected to the computer. Assembled using Adafruits guide. Some pics above from the assembly. Nothing special...

As I love Legos (who doesn´t) I built a simple case for it.

See the next steps for info on the stuff going on in the server.

Step 5: Wireless XBee LCD to show key values and indicate status with background color

This will be a small unit with all kinds of uses in the future. So far it shows key values of whats going on in the house.
Up left: El. use over last 1 minute in Wh / average el. usage this hour and this weekday from whole history of values.
Low left: oil burner runtime in minutes last 5 min period / same as above
Up right: time
Low right: current temp. If the heating element is over 1 degree warmer than the fireplace outer wall both are shown. Means it´s time to burn some wood!

The background color changes according to how much electricity is used.
Green for less than 80% of the average.
Blue for 80-120% of average. In the picture which looks green the screen is actually blue put for some reason it shows greenish in the pic.
Red for over 120% of the average. Turn off the vaccum cleaner!!!

The LCD is from Adafruit. Its has a USB + Serial backpack so its really simple to use...

XBee config attached
LCD.pro619 bytes

Step 6: Python script for reciever

Picture of Python script for reciever
The script does the following:
- gathers values from temp, electricity and oil unit and writes it to the mySQL database
- sends data to the LCD

The code started simple but over the time as new functions were added it became quite difficult to read. It should be refactored but as it works well I havent gotten around to it yet...

gatherValues.py is used for testing.
SER_gatherValues.py is used to install the script as a Windows service (command: python SER_gatherValues.py install)

Improvmets ToDo:
- Clean the code!
- Sending to the LCD is now done every time we recieve something from another XBee. Reconfig the LCD XBee to sleep and on wakeup poll for new values.

Step 7: Python script to get outside temperatures from airport

Picture of Python script to get outside temperatures from airport
This script gets temperature values from a nearby airport using the wunderground service.

Simple stuff. Wunderground has good examples on their site...

Step 8: MyHome website with charts

Picture of myHome website with charts
Temp_today.JPG
Temp_7d.JPG
Oil_7d.JPG
El_7d.JPG
This part covers the website that presents some of the gathered data in graphical form.
I use the flot package to draw the graphs and php to query data from the mySQL database.

I am very aware that the code does not follow any best practice guidelines... Should absolutely clean it and optimize. The page takes a while to load...

Here you can see some screenshots of what kind of things can be seen on the myHome website. Dont ask me to provide the URL to the actual page because the server is in no way capable of answering multiple requests... :-)

There is one getXXXTemps.js.php or similar per line but they are basically all the same. Only the SQL query differs.
kedwa306 months ago

A suggestion on how to make the fireplace sensor and cord more appealing to the eye: incorporate it into an 2d copper wire tree.

http://thespringsong.blogspot.com/2009/11/copper-t...

Use some copper enameled wire instead of the black insulated cable for the part that is visibly on the surface that you see. Also, you can place surface mount LEDs on twisted pair branches for fruit that lights up. The sensor will then become just another fruit in your wall art.

You can make a vine if you don't want a tree. Use copper leaf to make leaves.

kedwa30 kedwa306 months ago

I forgot to say, use CA glue (super glue) to tack it on. You can use copper leaf on your sensor as well.

sandeepnag11 months ago

Hi ,

Is there a java class instead of python script to read data from receiving xbee connected to COM port of PC while transmitting xbee (at the arduino)is sending data

Qtronik1 year ago
I plan to do the same but with PHP for the backend and jQuery for User interface... and... I'll put MySQL directly on my online webserver. I plan to render graf with google data/graf API service!
florianagr1 year ago

Very nice!! I need to do a voc monitoring network for a project, but i don´t know where to connect my voc-sensor(tgs 2620). I have a arduino UNO, xbee shield , 2 xbee, and one xbee adapter.

Where can i connect my voc-sensor?

I also calibrated my sensor (in the arduino sketch without xbee connection), but i don´t realy know how to write a new sketch for xbee connection.

Can you explain me how i can write the sketch for arduino and where i can connect my sensor?

Thanks

jweymarn (author)  florianagr1 year ago

Hi!

Connection: I assume the sensor gives out an analog value which is relative to the value it is sensing. That would mean you just connect it to one of the analog ports on the Arduino (A0, A1...). However as the sensor seems to need warmup and heating the schematic is not as simple as a analog temp sensor... Anyway, in the sketch you want to read the analog value from that pin.

I also assume you want to use the Xbees to send the sensor value to a PC. For that check e.g. my Electricity monitor sketch. To receive the value with python on a PC check my gatherValues.py. It is horrible and old code but the current version is much longer so that will just confuse... You want to especially look at gatherValues() and message_received(data)

HI,

thanks for your answer.
I will use a TGS 2620, Arduino, xbee shield and xbee pro series 2b for the transmitting side. Xbee and Xbee usb explorer for receiving side.
But i don´t know how to configure it for this purpose?
Do you have some ideas?

Thanks a lot for this tutorial
imbhartesh1 year ago

Tutorial for Python Script please

Nice one, would love to do this. The kit is very scarce and expensive in South Africa, but need to give this a go
iHomeFun2 years ago
Thanks for the mention of the wunderground service. I had never heard of them, but their API looks perfect for the home automation project I am working on.
OCPik4chu2 years ago
First Ill say good 'structible, I'm always happy to see more Xbee projects, I am trying to get into the Arduino/wireless game and these are great for learning.

To hide the cord:

First, run it in a way that the cord makes only right angle turns and runs straight. Get a staple gun that has small but slightly long staples and use it to staple the cord in place. Make sure to pull the cord somewhat tight to keep it looking straight and you wont need very many staples (like 1 every foot at most). So turn the sensor sideways so the cord goes to the right and tape it back down for now. Run the cord from the sensor straight to the right to the gap at the wall, then run it straight down the gap to the top of the baseboard. Run it along the baseboard to wherever it needs to go.

After this, come back with some white paint and paint over the cord and staples along the baseboards to make them blend in more. The part on the fireplace just pick a neutral brown so its less obvious or if you have some good painting skills you can try to paint the cord to match. As for the sensor itself you can paint some of it (obviously not the sensor part) to match. Im not sure if you are using that to measure the air or the surface but if its the air you can just use a little double-sided tape on the sensor to keep it there. If you are measuring the surface it will be a bit more difficult, perhaps putting a small amount of hot glue or silicon (something that wont damage stuff) along the outside edge to hold it in place.

Hope that helps :)