Go Down

Topic: home automation with arduino and android (Read 59162 times) previous topic - next topic

bl4d3

Hi guys,
I created this project and my target is improve the comfort of my home. Taking a look around I noticed that home automation solution proposed by the big market player are too much expensive for me and, above all, I should create new wires connections between light, plug, etc.. and the control box.
My idea is use what we already have without spend lot of money to buy a owner solution, so I started with arduino, my android mobile phone, some relays and my home.
I have a nice home, 2 bad rooms, kitchen with living room and it was very nice tka e the control of the lights, gate and door with my mobile phone.

Let's start to play.
I used an Arduino 2009 with ethernet shield and the game is very easy, I send some http message to arduino, he moves some relays and give me back a JSON response. Not so hard, but the hard business is interfacing with the electrical wiring of home, with some patience I found what I need and I linked those wires at the relays.

Go deeper.
Let's analyze a bit what my mobile send to arduino, the actors in this scenario are:

AS = Arduino Station (arduino 2009/Mega + ethernet shield with relays linked to arduin digital out)

M = Master (android app)


Sync Mobile - Arduino

You have to configure the ip of your arduino on the app, in this way when you perform a sync the mobile will send to arduino this:

http://arduinoip/?m=hello

and arduini will reply with this json message:

{"ip" : "arduinoip", "devices" : [" +  "{ "type" : "gate", "name" : "cancellino ingresso", "out" : "5"}, {"type" : "door", "name" : "porta ingresso", "out" : "4"}, {"type" : "light", "name" : "luce soggiorno", "out" : "6"}, {"type" : "light", "name" : "luce cucina", "out" : "7"}, {"type" : "temperature", "name" : "camera da letto", "out" : "0"}, {"type" : "temperature", "name" : "camera bimbi", "out" : "9"}, {"type" : "wattmeter", "name" : "consumo energetico casa", "out" : "10"}]}

so we know what sensor/realys are linked to arduino and what they are used for.

Take a closer look at this message:

ip is the arduino ip
out is the arduino pin where the relay/sensor is linked
name a human identifier
type object type

Right now there are the following type available:

plug
light
door
gate
temperature
humidity
wattmeter

The type temperature, humidity, wattmeter can't be controlled because they are sensons, the app has a background job that retrieve this value and store into a database, in the future we could make graph or use this data for statistical consideration.

Now the app is in sync with arduino!

Put something on/off

We just have to call to turn something on:

http://arduinoip/?out=1&status=1

status can be 1(on) or 0(off)
out point at the arduino pin

our arduino will give back this JSON massage if the transaction succeed:

{"out": "4", "status" , "1"}

What can we do with the andriod app:
- sync the app with arduino
- turn something on/off
- create custom action (turn light on and then open the gate)

Items used:

1 Arduino 2009
1 Ethernet shield
1 Relay with driver
1 power pack
1 electrical stuff
1 Pannello di plexiglas
Total in euro: 70

What I control:
- living light
- home gate
- front door
- check living room temperature

What I like to do in the future:
- integrate my irrigation system
- trigger an action at a specified time (need to work on android app)
- link another arduino and handle it with the app
- when the software will work fine give the code at the community

Sorry for my english, I'm not a native speaker.





granyte

that sound great i have a similar project on the long therm but i'll likely use bt instead of ethernet it's great

Sergegsx

for the watt meter...did you use this?
openenergymonitor.org

eres español?

estoy interesado en el envio y recepcion de comandos desde una web al arduino para activar pines.
sobre todo en la parte de php.

estare atento al tema.

Nyo

really really interesting...
Can you post the android code somewhere? I'm starting with andriod programming and I'm curious about this interaction between arduino and the phone!

P.s: Ottimo lavoro (bella anche l' UI del programma)

bl4d3

Hi guys, attached a short program that handle 2 relays and 1 temperature sensor, just to give you and idea about the stuff works.

By the way I deployed tha app on the android market, just need to search "DomoticHome".

Code: [Select]

#include <WString.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 10, 15 };                  // ip in lan
byte gateway[] = { 192, 168, 10, 1 };                  // internet access via router
byte subnet[] = { 255, 255, 255, 0 };                   //subnet mask
Server server(80);                                      //server port
byte sampledata=50;            //some sample data - outputs 2 (ascii = 50 DEC)            

String readString = String(30); //string for fetching data from address

int ledLittleGate = 4;  // little gate
int ledMainDoor = 5;  // main door
int ledTemperature = 0; // temperature home
//mcp9700a temperature(ledTemperature);
float tempc = 0; // temperature variables
int samples[8]; // variables to make a better precision

boolean statusLittleGate = false;
boolean statusMainDoor = false;
boolean statusTemperatureHome = false;
boolean whosConnected = false;

void setup(){
//start Ethernet
 Ethernet.begin(mac, ip, gateway, subnet);
//Set pin 4 to output
 pinMode(ledLittleGate, OUTPUT);  
 pinMode(ledMainDoor, OUTPUT);    
//enable serial datada print  
 Serial.begin(9600);
}
void loop(){
// Create a client connection
Client client = server.available();
 if (client) {
   while (client.connected()) {
  if (client.available()) {
   char c = client.read();
   //read char by char HTTP request
   if (readString.length() < 30)
     {
       //store characters to string
       readString.append(c);
     }  
       //output chars to serial port
       Serial.print(c);
       //if HTTP request has ended
       if (c == '\n') {
        // ****************************************************
        // little gate
        if(readString.contains("out=4&status=1"))
        {
            // throw the impulse
            digitalWrite(ledLittleGate, HIGH);    // set the LED on
            delay(300);
            digitalWrite(ledLittleGate, LOW);
            statusLittleGate = true;
         }else{
            statusLittleGate = false;            
         }
        // ****************************************************          
       
        // ****************************************************
        // main door
        if(readString.contains("out=5&status=1"))
        {
            // throw the impulse
            digitalWrite(ledMainDoor, HIGH);
            delay(300);
            digitalWrite(ledMainDoor, LOW);
            statusMainDoor = true;
         }else{
            statusMainDoor = false;            
         }
        // ****************************************************    
       
        // ****************************************************
        // temperature
        if(readString.contains("out=0&status=1"))
        {
            statusTemperatureHome = true;
         }else{
            statusTemperatureHome = false;            
         }
        // ****************************************************          
       
        // ****************************************************    
        // get all the devices connected
        if(readString.contains("out=all")){
           whosConnected = true;
        }else{
          whosConnected = false;
        }
        // ****************************************************            
       
         // now output HTML data starting with standart header
         client.println("HTTP/1.1 200 OK");
         client.println("Content-Type: text/html");
         client.println();
         
         //printing out status
         // little gate
         char buf[12];
         if (statusLittleGate){
             client.print("{\"status\" : \"ok\" , \"out\" : \"");
             client.print(ledLittleGate);
             client.print("\"}");              
         }
         
         // temperature home
         if (statusTemperatureHome){
             /*int i;
             for(i = 0;i<=7;i++){ // gets 8 samples of temperature
             samples[i] = ( 5.0 * analogRead(ledTemperature) * 100.0) / 1024.0;
             tempc = tempc + samples[i];
             delay(200);
             }
             tempc = tempc/8.0;*/
           
             tempc = (( 5.0 * analogRead(ledTemperature) * 100.0) / 1024.0) * 0.356;            
             client.print("{\"status\" : \"ok\" , \"out\" : \"");
             client.print(ledTemperature);
             client.print("\", \"value\" : \"");
             client.print(tempc);
             //client.print(temperature.celsius());
             client.print("\"}");  
         }
             
         // main door
         if (statusMainDoor){
             client.print("{\"status\" : \"ok\" , \"out\" : \"");
             client.print(ledMainDoor);
             client.print("\"}");    
         }              
             
         if (whosConnected){
           client.print("{\"ip\" : \"192.168.10.15\", \"devices\" : [{ \"type\" : \"gate\", \"name\" : \"cancellino ingresso\", \"out\" : \"");          
           client.print(ledLittleGate);
           client.print("\"}");    
           client.print(", {\"type\" : \"door\", \"name\" : \"porta ingresso\", \"out\" : \"");
           client.print(ledMainDoor);
           client.print("\"}");    
           client.print(", {\"type\" : \"temperature\", \"name\" : \"temperatura corridoio\", \"out\" : \"");
           client.print(ledTemperature);
           client.print("\"}");            
           client.print("]}");            
         }
         
         //clearing string for next read
         readString="";
         //stopping client
         client.stop();
           }
         }
       }
     }
}    

bld

Looking good, but nothing on the marked... :-/

What version is it made for?
captain-slow.dk | non contagious!

bl4d3

if i search on the market "domotichome" or "arduino" i catch it, dont you? let me know!

bld

Nothing, tried both domotichome and arduino.

But my phone is running Android 1.5, maybe your app isn't made for it?
captain-slow.dk | non contagious!

xMagnax

Pretty cool, you should add some more features like turning on wall sockets so you can plug other things in (turning them off an on remotely)

bl4d3

@bld you're right I signed the app for android version > 1.5, by the way, if you want you  can try to download it here
http://nerdydog.it/DomoticHome
let me know if it works!

@xMagnax i've already linked a wall socket to arduino through a relay+driver and it works fine!


bld

hehehe, nop... nothing either...

Quote
The page you were looking for doesn't exist.

You may have mistyped the address or the page may have moved.


Hard to get this program.  8-)
captain-slow.dk | non contagious!

bl4d3

#11
Sep 25, 2010, 04:57 pm Last Edit: Sep 25, 2010, 04:58 pm by bl4d3 Reason: 1
http://nerdydog.it/DomoticHome.rar

i forgot the rar extension! grrrr!

bld

What should that be opened with, or how to install it? All the other programs I have installed manually all had a file ending on so the apps installer could find them. But inside the rar there are only a "file" no ext
captain-slow.dk | non contagious!

bl4d3

yeah, into the rar there is an .apk file, it's a variant of jar files and it's used for the distribution of android component. To install you need to copy the apk on your sd card and doewnlaod an apk manager from the market, I suggest "ApkInstaller". For more information
http://www.brighthub.com/mobile/google-android/articles/37151.aspx

bld

No, there are no .apk there.. The file in the rar got no extension, and if I just rename it and put it on the phone, it tells me that the file is broken.

Maybe something happend when you uploaded the file?
captain-slow.dk | non contagious!

Go Up