loading

This is an Instructable to make a Twitter controlled Home Automation system for your house in less than 7$ (Rs.450). This tutorial includes setting up Python, Arduino as well as Twitter to build your very own Twitter controlled personal assistant.

The main reason I built this is to turn on the AC and mosquito coils in my room before I get home, so that when i come home, the room is already cooled and free from mosquitoes. But this implementation works for about anything.

Reason for the use of Twitter is because of an already existing twitter Android Wear app. This helps me to tweet by speaking into my watch. That basically means, I control my house talking to my watch!

Usually a home automation system of this sort would cost hundreds of dollars and still be not as good. In this project you will be able to control the appliances in your house right from your watch(if you have an android wear watch like I do).

Be sure to check out the video for an insight.

What goes in?

1) A micro-controller (arduino or arduino clone will do)

2) A laptop (Windows preferably)

3) A relay Shield (optional)

4) Android Wear Watch* (optional)

Step 1: Python Installation

Firstly you will have to download the TwitterHouse.zip file.

NOTE: The zip contains files ONLY FOR WINDOWS and no other operating system. Sorry. Based on your operating system you will have to download the equivalent individual files independently.

Check if you have python already installed on your computer by following the command prompt instruction below. If not continue this step.

Once you have downloaded and extracted the zip file, install python-2.7.9.msi

Open Command Prompt from search and type in "python" and click on enter. You should see that.

Step 2: Twitter Application

This and the next step are important steps where you link twitter to python.

To do so, you'll have to first create a Twitter account(if you don't have one).

Once you're done with that, head over to https://apps.twitter.com/ and hit on "Create New App". Type in a name(any name will do), description(doesn't have to be detailed) and website(any will do) and Create your Twitter application.

Now you go to Application setting and under Access level click on modify app permissions and change that to Read and Write, Update settings. Then click on the Keys and Access tokens tab and note down your Consumer Key and Secret. and scroll down to "Create my access token". Note down your Access token and access token secret as well.

Now you're all set with Twitter's Application Program Interface.

Step 3: Python Twitter Integration

Go back to the folder you had unzipped the downloaded file. And unzip the file tweepy-master.zip

Once you're done with that, open CMD(command prompt) again and navigate to the location of tweepy.

To enter a file, type "cd" and then the file name. and to go to root directory type "cd \".

Once you are in the folder tweepy-master where the file setup.py is located, type in "python setup.py install ". Once its done installing. Close cmd and reopen it. Type

python

once python is opened, type in

import tweepy

If you get ">>>" then you have successfully installed tweepy on your computer. Congratulations.

I suggest you install pyserial-2.7.win32.exe now as well. This you can just install like any other normal executable installation.

Step 4: Arduino Software Setup

In the same downloaded and unzipped folder(TwitterHome), run the installation of arduino. (arduino-1.6.0-windows (1).exe).

Once you're done installing the Arduino IDE, connect your Arduino using the USB serial cable and start the IDE. Select the board you are using and port it is connected on.

NOTE: I am using an Arduino clone and hence my drivers had to be installed separately. If you are also using a clone, download and install the respective drivers too in case it doesn't detect.

Take a note of this port as well.

Now open the file TwitterHome\python-tweet\python-tweet.ino in the IDE. Compile and upload the code to your Arduino.

Now you are done with the coding part of the Arduino.

You may reward yourself with a cookie.

Step 5: Python Coding

This is the part where you may go wrong the most number of times. But don't worry. I did too, because I had to write that code you will use.

Back to the TwitterHome folder, there are 2 files, homeautomationon.py and homeautomationoff.py

This tutorial will show you what to do in one of them and you will have to repeat the same steps for the other file.

So first right click on the file homautomationon.py and click on "edit with IDLE".

Once the editor opens, first thing you'll notice are the comments throughout the code. These comments(## change or ## change optional) are the lines of code you will have to edit based on your preferences and your configuration. The changes are pretty straight forward but in case you have any problems, feel free to comment below.

All the things I asked you to Note down earlier will come in handy now.

Step 6: Hardware

This is the step where you can tailor the hardware to suit your needs.

This step becomes very simple if you have an arduino Relay shield, if not you can make one like I did and use it. The trigger of the relay shield is to be connected to the pin programmed in the arduino program you uploaded to your microcontroller.

Attach the appliance to your relay shield like you would do if you were to put a switch in its circuit. The arduino doesnt drive the appliance but simply acts as an ON/OFF switch. After you're done wiring up the shield and the arduino connect it back to your computer.

Step 7: Watch Integration

This is the most fun and simplest step. Download Bunting on your phone and it should appear on your watch.

You are all set. :)

Step 8: Magic

Go to the python IDLE editor window that the program you have edited is in, and click on F5. You should see a new window pop up and it will display the contents of any tweet containing the keywords you have specified. When that keyword is detected, python will send a message via serial to your arduino to turn ON/OFF the appliance.

And now you can brag about your personal assistant on twitter. *drumroll* You can try it out by either tweeting on your watch (or any other device). When you tweet with the keyword, your PA will also tweet back to you based on the process undertaken.

Ta-daaaaaa. *bow*

Works brilliantly. And everything has been condensed and simplified that even i could make it. I feel like I'm in the future. Cant thank you enough.
Great to know that you've got it up and working. I will be making a few improvisations and I shall put then to as soon as possible.
<p>Hello, is it possible, that i use only mobile to tweet rather than using wrist watch? thank you!</p>
<p>Hello there! your project is super damn cool and i'm using it as reference to my final year project! I'm a beginner to arduino! Is it necessary to use the wrist-watch? How to make it works by just tweeting from the phone?</p>
Nice going bro! Will try it some day!
<p>what to attach on the realy shield</p>
<p>Assume that the relay is a mechanical switch and connect it like you would for it. Or disconnect the wall switch for it and connect the two wires you removed to the relay. Be careful with the current that your AC draws and the amount your relay can withstand.</p>
<p>I survived all the way till the last step then this props up when i run it!</p><p>Traceback (most recent call last):</p><p> File &quot;C:\Users\Gagan Bhat\Downloads\TwitterHome\homeautomationon.py&quot;, line 22, in &lt;module&gt;</p><p> ser = serial.Serial(usbport, 9600, timeout=1) ##change optional</p><p> File &quot;C:\Python27\lib\site-packages\serial\serialwin32.py&quot;, line 38, in __init__</p><p> SerialBase.__init__(self, *args, **kwargs)</p><p> File &quot;C:\Python27\lib\site-packages\serial\serialutil.py&quot;, line 282, in __init__</p><p> self.open()</p><p> File &quot;C:\Python27\lib\site-packages\serial\serialwin32.py&quot;, line 66, in open</p><p> raise SerialException(&quot;could not open port %r: %r&quot; % (self.portstr, ctypes.WinError()))</p><p>SerialException: could not open port 'COM3': WindowsError(5, 'Access is denied.')</p><p>&gt;&gt;&gt; </p>
<p>Did you connect your arduino right? Go over to the arduino IDE and check the port its connected on. Change COM3 in the source code to the right port. If that doesnt fix it then write a small program and check if serial connection with your arduino works alright in the arduino IDE.</p>
<p>Hi</p><p>Whenever I type Python or Python setup.py install then it says that python is not recognized as an internal or external command </p>
<p>From your next comment I'm guessing you figured a workaround for this...</p>
<p>of the ac</p>
<p>excellent</p>
Thank you :)
This is beautiful :))
<p>Thank you :D</p>
Very cool. Nice g watch BTW.
Haha thank you :)
<p>It was an enjoying read :) <br>Sounds quite interesting , I might try it some day . Is it possible for u to say please on ac and set it at 20 degrees ? Just curious ....</p>
Thanks. I'm still working on that. I will edit and post the improvisations add soon as possible. :)

About This Instructable

7,356views

71favorites

License:

More by adhesh:( Wrist-watch enabled) Home automation via Twitter 
Add instructable to: