Introduction: Arduino Based Automated Lighting Control

Picture of Arduino Based Automated Lighting Control

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

Picture of 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

Picture of 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

Picture of 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.

Comments

trishav96 (author)2016-08-21

Can someone send a pic of the Arduino Uno board and the Ethernet shield to be used in this?

DomenR (author)2016-07-04

have someone libraries ETHER_28J60.h and etherShield.h?

tnx

ViteshS (author)2016-05-24

thank you so much for your solution. I have been looking for this. thanks again.

Hey Dave (author)2015-05-08

same lang po ba ng code to para sa mini enc28j60 ethernet tapos gagamit po ako ng 8 channel na relay bali i e edit ko nalang po yung code sa IDE tsaka po sa may app ?? pede ko po bang gamitin na ethernet ay mini enc28j60 ethernet ??

rmagtibay (author)Hey Dave2015-05-08

yes and yes

Eloisa CamelM (author)rmagtibay2016-02-16

Sir, hanggang 4 outputs lang po ba ang kaya ng ethernet shield..? Kasi po pag dinadagdagan namin ng isa pang output pin (5pins na lahat) ayaw na po gumana switching namin.

EdwinN6 (author)2015-10-18

kuya tanung lang paanu p ung program pag bluetooth shield ang ginamit

JhayE2 (author)2015-10-11

Hi boss gamit ko po gizduino atmega1281 and ethernet shield enc28j60 nung kinabit ko siya hindi siya nag uupload sinundan ko naman ung process pero error naman po siya. anong version po gamit niyong arduino? i am using arduino 1.6 po reply pls

hemu.katiyar (author)2015-09-25

C:\Users\hemu\Documents\Arduino\libraries\etherShield/ip_arp_udp_tcp.h:32:66: error: 'prog_char' does not name a type

extern uint16_t fill_tcp_data_p(uint8_t *buf,uint16_t pos, const prog_char *progmem_s);

^

C:\Users\hemu\Documents\Arduino\libraries\etherShield/ip_arp_udp_tcp.h:32:77: error: ISO C++ forbids declaration of 'progmem_s' with no type [-fpermissive]

extern uint16_t fill_tcp_data_p(uint8_t *buf,uint16_t pos, const prog_char *progmem_s);

^

In file included from test.ino:1:0:

C:\Users\hemu\Documents\Arduino\libraries\etherShield/etherShield.h:34:65: error: 'prog_char' does not name a type

uint16_t ES_fill_tcp_data_p(uint8_t *buf,uint16_t pos, const prog_char *progmem_s);

^

where is the error?? who it would be solve?

MjF1 (author)2015-02-24

Sir paano po mag rerecieved ng data galing sa arduino papunta sa apps?

muzaffars (author)2014-08-30

excellent! how and where can we add DS18B20 readings to the code and e.print the resu

hkaynar (author)2014-03-29

excellent! how and where can we add DS18B20 readings to the code and e.print the results?

rmagtibay (author)hkaynar2014-03-31

there is for the server read program ill try to post it some other time

retzforshort (author)2014-01-20

Hi sir, ask ko lang po if ma aaccess pa din ba ng mobile app yung pag control ng LED kahit na hindi dun sa router na ginamit naka connect? or simply kahit nasan basta may internet acces, ma ccontrol pa din ba yung LED?

rmagtibay (author)retzforshort2014-01-21

Actually this could only be accessed within the ranged of the router. if you want it to access you controls through he internet, you need IP hosting.

rmagtibay (author)retzforshort2014-01-21

Actually this could only be accessed within the ranged of the router. if you want it to access you controls through he internet, you need IP hosting.

rmagtibay (author)2012-12-18

Actually, programming in the tablet is almost the same as for the phones.. all you have to do is to rearrange and change the resolution when working on tablets... to bad for me i only have a 5 inch device...

ftraxex (author)rmagtibay2013-12-10

Sa Inyo Pala To Sir hahahaha! Thank You Master Talaga!.... ^_^

vgamueda (author)2013-08-14

do you mind sharing where you got the library included in your program? thanks in advance

Build_it_Bob (author)2012-12-17

Very nice project ! Thank you for sharing your knowledge and experience. I hope some day soon to try programming for the Android tablet for home automation.
Build_it_Bob

amigurumi (author)2012-10-25

can i do this without using any router just bluetooth device?? thank you :)

rmagtibay (author)amigurumi2012-10-25

yes you can do that but you must have a BT shield connected to your arduino to do that....

amigurumi (author)rmagtibay2012-11-05

hi again :) if its not to much can you suggest an arduino that we can use for lighting bulbs (we are just new in arduino kit) we will use smartphone and bluetooth thank you :)

rmagtibay (author)amigurumi2012-11-06

some additional components are needed in order to pull this project off.
Materials:
1. Arduino
2. a BT sheild
3. Solid State Relay that could handle 5vDC and switches up to 220vAC
4. An android phone (prefffered)
im lacking now of components (such as SSR and BT shield) so i cant give you the full details but these are the materials you need as a start.

you can also get a driver relay instead of the solid state relay

amigurumi (author)amigurumi2012-10-27

thank you again :))

rmagtibay (author)amigurumi2012-10-25

try this instructable:

https://www.instructables.com/id/Androino-Talk-with-an-Arduino-from-your-Android-d/

amigurumi (author)2012-10-23

hi i was just wondering if you can light multiple bulbs using this?? thank you :)

rmagtibay (author)amigurumi2012-10-24

yes you can do multiple lights... you just have to add on the program for both the arduino and androi... ill try to post it as soon as im free...

amandaghassaei (author)2012-09-24

awesome! it would also be cool if you added dimming capability to this, you would have to change the hardware of course... have you had a chance to try this out with real home lights?

rmagtibay (author)amandaghassaei2012-09-24

thanks! actually i have made this using home lights during my first test w/o the android
. i used an SSR to connect the coil terminals of the arduino and contact line to an CFL bulb. actually i could make the dimming of the LED, i'll just actually adjust the software for this (on a real home light change of hardware)

Analogue-Chick (author)2012-09-23

Woohoo!!! :D

About This Instructable

94,927views

98favorites

License:

Bio: the simpler, the better!!
More by rmagtibay:Arduino Based Automated Lighting ControlArduino I/O-Matlab basic tutorial
Add instructable to: