Pages: 1 2 [3] 4 5   Go Down
Author Topic: home automation with arduino and android  (Read 52757 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK! i will try! Thanksss
Logged

Bedfordshire
Offline Offline
Newbie
*
Karma: 1
Posts: 9
.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Nice! Been looking into home automation for ages this seems perfect! Sorry if im just being blind but is there the script for the arduino up? I have the app on my phone already and will order the parts and arduino UNO tomorrow.
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 149
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

you can find an example of arduino sketch at the first page of this post, let me know
Logged

Bedfordshire
Offline Offline
Newbie
*
Karma: 1
Posts: 9
.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi got my uno today, all connected up have it conected to the network. I put the scetch you posted on the first page and i get the error on the line

 readString.append(c);

'class string' has no member named 'append'

any ideas?

Thanks

Adam
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 149
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Which version of the IDE are you using? Take a look on this
http://www.arduino.cc/en/Tutorial/TextString
Logged

Newcastle, England
Offline Offline
Sr. Member
****
Karma: 3
Posts: 489
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Looms really good!
What code did you use for the computer interface?
I'd love to build something like this, but I would have
no idea how to intergrate it into the computer.
Logged

My website: http://www.harryrabbit.co.uk/electronics/home.html Up and running now! (Feel free to look round!) smiley-grin

0
Offline Offline
Full Member
***
Karma: 0
Posts: 149
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

the interface has been developed for android device, so it has been build in JAVA, full code is available on github
Logged

Bedfordshire
Offline Offline
Newbie
*
Karma: 1
Posts: 9
.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks got rid of the error but now means the wont sync with my android  :-/

I guess ill have to start writing from scratch then...

Thanks Adam
« Last Edit: December 06, 2010, 03:43:21 pm by adamjgreen » Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 149
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

before to use the android app test the http call through a web browser...you should see the json message on it
Logged

Bedfordshire
Offline Offline
Newbie
*
Karma: 1
Posts: 9
.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks mate.

Im finding it really hard to see whats what in the script so i might have to have a go at starting from scratch....
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 149
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

of course, some basic programming skills are needed to better understand it, let me know!
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 149
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi there, with this sample you should be able to turn on/off a light, i'm posting this beacuse an user of this forum asked me how to make it and i thought it was nice sharing this with all the people.
Code:
#include <SPI.h>
#include <Ethernet.h>

#define action_none -1
#define action_out_all 0
#define action_on_light 1
#define action_off_light 2

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xBE }; //physical mac address
byte ip[] = { 192, 168, 1, 16 };                  // ip address
byte gateway[] = { 192, 168, 1, 1 };                  // internet access via router
byte subnet[] = { 255, 255, 255, 0 };                   //subnet mask
Server server(80);                                      //server port
String readString = String(30); //string for fetching data from address

// arduino out
int pinOutPlight = 4;


// incoming GET command  
String r_pinOnLight = "GET /?out=4&status=1";
String r_pinOffLight = "GET /?out=4&status=0";
String r_out_all = "GET /?out=all";

// current action
int current_action;

void setup(){
  //start Ethernet
  Ethernet.begin(mac, ip, gateway, subnet);
  delay(1000);

  pinMode(pinOutPlight, OUTPUT);    
  digitalWrite(pinOutPlight, LOW);
  //enable serial datada print  
  Serial.begin(9600);
  current_action = -1;
}
void loop(){
  current_action = -1;

  // 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 = readString + c;
        }  
        //output chars to serial port
        //Serial.print(c);
        //if HTTP request has ended
        if (c == '\n') {

         Serial.print(readString);
         // ****************************************************
          if(readString.startsWith(r_pinOnLight))
          {
          Serial.print("\n ON UP \n");
          current_action = action_on_light;
          }
          else if(readString.startsWith(r_pinOffLight))
          {
           Serial.print("\n OFF UP \n");
           current_action = action_off_light;              
          }
          else if(readString.startsWith(r_out_all))
          {
            Serial.print("\n ALL\n");
            current_action = action_out_all;
          }
          else
          {
            Serial.print("\n None \n");  
            current_action = action_none;
          }
         // ****************************************************  
          // now output HTML data starting with standart header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
         char buf[12];              
         switch(current_action)
         {
         case action_out_all:
            client.print("{\"ip\" : \"192.168.10.16\", \"devices\" : [{ \"type\" : \"light\", \"name\" : \"your name\", \"out\" : \"");          
            client.print(pinOutPlight);
            client.print("\"}");                        
            client.print("]}");                      
           break;
         case action_on_light:
           digitalWrite(pinOutPlight, HIGH);
           client.print("{\"status\" : \"1\" , \"out\" : \"");
           client.print(pinOutPlight);
           client.print("\"}");                          
           break;          
         case action_off_light:
           digitalWrite(pinOutPlight, LOW);
           client.print("{\"status\" : \"0\" , \"out\" : \"");
           client.print(pinOutPlight);
           client.print("\"}");                
           break;
         default:
           current_action = action_none;        
         }


         // ****************************************************            

          //clearing string for next read
          readString="";
          //stopping client
          client.stop();
        }
      }
    }
  }
}
you have to change your ip in the sketch. It's just a demo, any improvement are welcome.
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 149
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If someone has downloaded my app and played a bit with arduino and this stuff you should vote my project on MAKE

http://makezine.com/tagyourgreen/?id=90

Thanks!
Logged

NYC
Offline Offline
Full Member
***
Karma: 0
Posts: 129
The singularity is near!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This post started out with the premise that other home automation systems are too expensive. Aren't X10 systems pretty cheap ($99 for controller and software)?

One issue with X10 is that they require a computer with X10 controller on 24/7. The computer provides a web interface and can turn devices on/off at scheduled times. For example, you may want to switch an outside light on automatically at 7 PM every day.

Have you given any thought to a server solution, i.e. leaving an android device at home and on 24/7 that can be connected to remotely?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 6
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello!

I try to get this to work with the 28J60 Ethernet Shield.

But i get error in the android APP "An error has accoured, check your internet connection. Is Arduino Alive?"
It all works, i get "my item" and i can controll the arduino output from the app.
The only problem seems to be with the JSON from the arduino to the android app. When i test in my web browser its look like this:
Code:
//arduinoIP/?out=5&status=0
-> {"status" : "0" , "out" : "5"}
//arduinoIP/?out=5&status=1
-> {"status" : "1" , "out" : "5"}

What can be wrong?


 
Code:
if (strcmp(params, "?out=all") == 0)
  
         {
           e.print("{\"ip\" : \"192.168.0.15\", \"devices\" : [{ \"type\" : \"plug\", \"name\" : \"LAMPA\", \"out\" : \"");          
           e.print("5\"}");            
           e.print("]}");      
           e.respond();
          Serial.println("OUTALL!!");
        }

 if (strcmp(params, "?out=5&status=0") == 0)
       {
           digitalWrite(pinOutRelay, LOW);
             Serial.println("OUT LOW!!");
            e.print("{\"status\" : \"0\" , \"out\" : \"");
            e.print("5\"}");  
            e.respond();  
           Serial.println("LOW!!");  
      }

 if (strcmp(params, "?out=5&status=1") == 0)
     {
           digitalWrite(pinOutRelay, HIGH);
           Serial.println("OUT HIGH!!");
           e.print("{\"status\" : \"1\" , \"out\" : \"");
           e.print("5\"}");    
           e.respond();
           Serial.println("HIGH!!");
     }

Edit: I found the error smiley
I had a old DomoticHome APP installed . It work perfect  with the app from market.
« Last Edit: December 27, 2010, 06:21:57 pm by Fluke » Logged

Pages: 1 2 [3] 4 5   Go Up
Jump to: