Introduction: Arduino Based Automated Lighting Control

About: the simpler, the better!!

This is my second instructable. i want to share some of the basic things i made using the arduino i am so busy lately. then i got the chance to have this spare time... inspired by my former student and a fellow co league to share this arduino based wireless automation.
this automation was done using an arduino together with an enc28j60 Ethernet Shield (because this is the only shield available here in my country as i think of) and a android app i made for this particular project.

Here is the video of the project:

http://www.youtube.com/watch?v=ZdTwsNPthOI&feature=g-upl

Step 1: Step #1. Thing That You Need

Here are the list of what you need in this project:
1. Arduino Uno (Here in the Philippines its Gizduino)
2. Ethernet enc28j60 shield
3. Wireless Router
4. LAN cable (connection for the ethernet shield and the router)
5. 2 pcs. LED 
6. Resistors
7. Wires
8. Breadboard

Step 2: Step #2: the Arduino Hardware Setup

First, connect the ethernet shield to your arduino.
Next, connect the LAN cable to your router and to your ethernet shield
Thrid, connect the LED and resistors according to this sequence:

PIN 6 --> LED1 -->Resistor --> GND
PIN 7 --> LED2 -->Resistor --> GND

Lastly, connect your USB cable to your arduino so we could start the programming

Step 3: Step #3: Arduino Sketch

This is the sample sketch i edited based on this website
http://trollmaker.com/article11/arduino-1-0-with-enc28j60-ethernet-shield-v1-1

i made some modification of my own but there are some position of the buttons for the LED 2 i did not edit since i will be using my own android program for this project. the idea is to get have the parameters (such as the "?led1=on") to work on the lighting condition.

// A simple web server that turn an LED on or off"

#include "etherShield.h"
#include "ETHER_28J60.h"

int outputPin1 = 6;
int outputPin2 = 7;

static uint8_t mac[6] = {0x54, 0x55, 0x58, 0x10, 0x00, 0x24};   // this just needs to be unique for your network,

static uint8_t ip[4] = {192, 168, 1, 15}; // IP address for the webserver

static uint16_t port = 80; // Use port 80 - the standard for HTTP

ETHER_28J60 e;

void setup()
{
  e.setup(mac, ip, port);
  pinMode(outputPin1, OUTPUT);
  pinMode(outputPin2, OUTPUT);
}

void loop()
{
  char* params;
  if (params = e.serviceRequest())
  {
    e.print("<h1><a href='/?led=off'>Arduino Web Remote</a></h1>");
    if (strcmp(params, "?led1=on") == 0)
    {
      digitalWrite(outputPin1, HIGH);
      e.print("<a href='?led1=off'><button style='border: 1px solid #ff0000; border-left: 10px solid #ff0000' type='button'>LED IS ON</button></a>");
    }
    else if (strcmp(params, "?led1=off") == 0)
    {
      digitalWrite(outputPin1, LOW);
      e.print("<a href='?led1=on'><button style='border: 1px solid #000; border-left: 10px solid #000' type='button'>LED IS OFF</button></a>");
    }

    else if (strcmp(params, "?led2=on") == 0)
    {
      digitalWrite(outputPin2, HIGH);
      e.print("<a href='?led2=off'><button style='border: 1px solid #ff0000; border-left: 10px solid #ff0000' type='button'>LED IS ON</button></a>");
    }
    else if (strcmp(params, "?led2=off") == 0)
    {
      digitalWrite(outputPin2, LOW);
      e.print("<a href='?led2=on'><button style='border: 1px solid #000; border-left: 10px solid #000' type='button'>LED IS OFF</button></a>");
    }
    e.respond();
  }

Step 4: Step #4: Android Program

I use the basic4android application for this project. then i used the http libraries to call the webserver parameters

http://www.basic4ppc.com/android/help/http.html

the idea is, for every button in the application it will push the webserver the parameters needed to turn off and turn on the lights

here is the program for the android app:

'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim URLoff As String
URLoff = "http://192.168.1.15/?led1=off"
Dim URLon As String
URLon = "http://192.168.1.15/?led1=on"
Dim URLoff2 As String
URLoff2 = "http://192.168.1.15/?led2=off"
Dim URLon2 As String
URLon2 = "http://192.168.1.15/?led2=on"
Dim HttpClient1 As HttpClient
End Sub

Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.

End Sub

Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("layout1")
HttpClient1.Initialize("HttpClient1")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
Sub ButtonOn_Click
Dim request As HttpRequest
request.InitializeGet(URLon)
HttpClient1.Execute(request,1)
ToastMessageShow("LED Light On",False)
End Sub
Sub ButtonOff_Click
Dim request As HttpRequest
request.InitializeGet(URLoff)
HttpClient1.Execute(request,1)
ToastMessageShow("LED Light Off",False)
End Sub

Sub Button2On_Click
Dim request As HttpRequest
request.InitializeGet(URLon2)
HttpClient1.Execute(request,1)
ToastMessageShow("LED Light On",False)
End Sub
Sub Button2Off_Click
Dim request As HttpRequest
request.InitializeGet(URLoff2)
HttpClient1.Execute(request,1)
ToastMessageShow("LED Light Off",False)
End Sub

Sub HttpClient1_ResponseSuccess (Response As HttpResponse, TaskId As Int)
    Dim resultString As String
    resultString = Response.GetString("UTF8")
    'Work with the result
End Sub

Sub HttpClient1_ResponseError (Response As HttpResponse, Reason As String, StatusCode As Int, TaskId As Int)
    Log("Error connecting: " & Reason & " " & StatusCode)
    If Response <> Null Then
        Log(Response.GetString("UTF8"))
        Response.Release
    End If
End Sub

Step 5: Step #5 Upload All the Files and Test

Once uploaded, you can get start making your automation

Step 6: Recommendations:

if you want to make you of this at home i suggest learn mo about Solid state relays, to have the signal of 5V from the arduino control a much higher voltage which is suitable for home use (110 - 220V).
better programming, try to use some free programming software such as eclipse or netbeans for the android development.

Hack It! Contest

Participated in the
Hack It! Contest