Go Down

Topic: Arduino + Web Control + Relays = Home Automation (Read 37 times) previous topic - next topic

tehjrow

I'm in the beginning stages of doing this exact thing.  Ordered the Ethernet shield already.  If I need more pins than the arduino has i'll use shift registers.

Keep us posted!

vinhtvu2

Me too!! I've collected TOO many toys and ideas for this project already.

But go ahead and give me more ideas and comments!!

I know everyone who has ever owned an Arduino or messed with automation has pondered the possibility... so give all your thoughts! I'll try to put as many of them into effect as possible!

CowJam

I've been thinking about this too (doesn't everyone).

When it comes to ethernet shield interraction I've found it easier to have the arduino poll a web site. I've got a local web server (I have a QNAP NAS box that does web server as well as being NAS), and my arduino polls a website for instructions every time it's idle.  The web server is built to handle multiple threads, whereas my arduino is going to get confused if multiple requests come in at once.  

I've also thought about having an arduino per room or per pair of rooms, so I'm not trying to do too much on one arduino and it'll simplify the wiring.

I got myself a couple of smart card sockets and ten smart cards so I can do door access.  I'm renting at the moment though, but I want to buy mainly so I can do stuff to my house that I can't when renting.

tehjrow

Here's a post to the rfid door unlocker I was doing.  

http://jrowarduino.blogspot.com/

I haven't installed it yet because I want to change it a bit.

vinhtvu2

It has begun. Parts started to arrive today.

I will start programming and prototyping soon.

Follow and comment :-P
http://vinhworkblog.blogspot.com/

bld

Pictures!!!! ;D Want to see the toys too, not only read about them. ;)
captain-slow.dk | non contagious!

Vini

Photos, Videos, everything!
Your project sounds nice!!


SaSaa

LOL @ this pic -> components :P sticker :P

Nice layout right now!
nice bag with reed/magnet switches :D
how large is your hous in terms of windows, doors, rooms, floors and doors to the outside world (I have 5 :S) to bad i rent...


why don't you live close by :P so I could help :P (I'm a electrician to)

vinhtvu2

MAN! I surely could use the help! haha. Or at least just another person to check my work. All my friends are clueless as to what I'm doing...

As for the house, there are TONS of windows... at least 20. There are 5 doors in all that enters the house. So that's about 25 input pins on the Arduino right there. 5 for electric strike plate lock, a couple for PIR, Ultrasonic sensors, a couple for temperature sensor and heater/AC control... by the end, I'm going to be putting most of the pins on this Seeeduino Mega to work! :P

tehjrow

Here's how i'm thinking about doing mine.

Server with php/lighttpd/mysql will host 2 php pages (just two at first to make it simple).
The first php page will be the "front end" that I will connect to from a computer.  It will have buttons and things to turn stuff on/off.  It will connect to a mysql database to get/change the status of something (say light = off).

The second php page will be what the arduino will poll every few seconds.  It will connect to the database and see if the state has been changed.  If, say, light = on now, it will fire the correctly relay.

I already have part of it setup.  I can't figure out how to use the data that has come back from the server on the arduino.  Can you take a peek at my post here?
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1278888171

Also, is this how you are planning to do it?  Or is there a different way?

vinhtvu2

No, I'm more in the business of instant gratification, so with your concept where the Arduino polls the PHP/MySQL every few second will have a slight delay. The delay will be longer since I will be using it through my phone's Web access through wifi... so from the point I click the button on the phone, then wait a few second for the light to turn on, or a door to open would be... un-pleasing.

I mean it would work fine, but I want a better solution. What I was thinking is that when I press a certain button, it will trigger a GET sending straight to the Seeeduino's Ethernet shield. This will turn on whatever relay it's attached to, then the Seeeduino send the appropriate "event" back to the mySQL server with a POST.
So it's suppose to act first, then log. This way, I can also code in the Seeeduino to "check" to see if the appropriate light is on before sending the status. Else it'll have to try again. I will have a bunch of LDR (light detecting diode) wired up to every rooms pretty much, so I can check light status that way. And I can also check to see if a certain door opened up with the use of the Reed switch that will also be use for security purpose.

I think by doing a GET/POST method, the Seeeduino will be acting as the primary server for everything, the only thing the PHP server will be doing is relaying the message from the Seeeduino back and forth.

Let me know if you think this will work. From what I've read of the Ethernet shield, this shouldn't be a problem... but then again I can be wrong. I haven't even gotten the Seeeduino mega to work with the Ethernet shield yet.

tehjrow

I'll work on in that way tonight and see where I can get.

SaSaa

Quote
I can also code in the Seeeduino to "check" to see if the appropriate light is on before sending the status. Else it'll have to try again. I will have a bunch of LDR (light detecting diode) wired up to every rooms pretty much, so I can check light status that way.


since you use a digital pin to controll a relay, transistor or something you can just digitalRead(); the relay pin...
instead of usingpins to check the light of every room :D
this cuts the pins per light in half :P

I always use a function to toggle.

Code: [Select]

// use like toggle(13); to switch pin 13.
// simple but does the job!
int toggle(int pinnumber){
 if(digitalRead(pinnumber) == HIGH){
   // if light is on turn it off
   digitalWrite(pinnumber, LOW);
 } else {
   // if light is off turn it on
   digitalWrite(pinnumber, HIGH);
 }
}


+ a mysql server for the status of the lights?
Why? you can program arduino to do it directly why use a database.

i would use a html file or a php file to create a form like:

Code: [Select]
<center>
<form method="GET" action="http://myarduino-ip">
     <input type="SUBMIT" name=led13 value="toggle led 13">
</form>
<iframe src ="http://website-that-has-the-forms" width="100%" height="100%">
 <p>Your browser does not support iframes.</p> <!-- shows the pages just fine -->
</iframe>
</center>


Code: [Select]
#include <WString.h>
#include <Ethernet.h>
byte mac[] = { 0x00, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 2, 150 }; // MY IP change to your needs
Server server(80);
String readString = String(100);


void setup(){
 Serial.begin(9600);
 Ethernet.begin(mac, ip);
}

void loop(){
 Client client = server.available();
 if (client) {
   while (client.connected()) {
     if (client.available()) {
       char c = client.read();
       if (readString.length() < 100){
         readString.append(c);
       }
       if (c == '\n') {
         if(readString.contains("msg")){
           toggle(13);
         }

         // Now output HTML data starting with standart header
         client.println("HTTP/1.1 200 OK");
         client.println("Content-Type: text/html");
         client.println();
         client.println("led 13 is"); client.println(digitalRead(13));
         readString="";
         client.stop();
       }
     }
   }
 }
}

NOT TESTED!

tehjrow

Quote
since you use a digital pin to controll a relay, transistor or something you can just digitalRead(); the relay pin...
instead of usingpins to check the light of every room
this cuts the pins per light in half


I still want to have light switch control (on the wall), so the arduino can't know if the light is truly on or off without a light sensor.

Go Up