Arduino Home Automation

531K43666

Intro: Arduino Home Automation

This is a relatively simple controller for controlling equipment in your home.

At the moment I control my central heating, security and lighting.
By sending commands from my home computer.

My homeeasy central heating controller hack.
https://www.instructables.com/id/BampQ_homeeasy_home_automation_central_heating_c/

I am also able to login remotely from the internet to control the equipment at home connected to this controller.

This project is built around an Arduino board.

http://www.arduino.cc/

The arduino board is a hardware interface allowing you to control and monitor hardware devices with your computer.

And the homeeasy home automation controllers available from B&Q.

http://www.homeeasy.eu/home.php

These are basically plug-in module which allows you to switch devices on and off using a remote control.

The idea behind this project was. I wanted to be able to login to my home computer and send commands that would allow me to turn lights on remotely.
Or have the computer do it automatically at a set time or when it gets dark.

STEP 1: Parts Needed

1 arduino board.
1 homeeasy controller - part number HE300
1 prototype board - Vero board
10 resistors - 47 ohm
10 led's
4 opto isolators - RS part 308-613
Some ribbon cable.
a strip of pins to connect to the headers on the arduino board.
1 box - to put it all in.
some HE302S - remote control socket


Tools

Soldering iron
Solder
Cutters

STEP 2: Basic Principle

Hardware

Basically the arduino board when programmed will switch the digital outputs high.
Which will send 5 volts through the resistor and light the led's.
Which will activate the opto isolator which will connect the contacts on the remote control.
which will send the comand to the remote control sockets
And turn on or off the lights, heating or anything you want.

this circuit shown is for the first on and off switches.
just repeat the circuit for the following channels

software

I programed the software so when I pressed (H) in the terminal the arduino board will send a 1 second pulse to my remote control and switch my heating on.
when I press(h) the board will send a 1 second pulse my heating switches off.
(S) for security on
(s) for security off
(G) garden lights on
(g) garden lights off

and so on this can be changed to any button you want

STEP 3: Building the Board

The board I built on some prototype project board available from most electronic stores.

It was just a matter of soldering on the components as show in the circuit diagram.
And making sure there were no short circuits.

the first led connects to pin 1 on the opto isolator, led 2 connects to pin 4 on the opto isolator.
pins 2 and 3 are then connected to ground. which is next to digital pin 13 on the arduino board.

opto isolator pins 6 and 7 are connected together and go to the center contact on the remote control for the first on off buttons.
opto isolator pin 8 goes to the left track on the remote.
pin 5 goes to the right track on the remote.

and then it's just a matter of repeating the circuit for the other channels.







STEP 4: Modifying the Remote Control

I unscrewed the screw under the rear label. And carefully prised open the case.

When open you will see the PCB.
On the PCB there is one track on the left which when connected to the centre contacts will switch devices on.
And there is a track on the right which when connected to the centre contacts will switch equipment off.

I just attached the contacts to my circuit as shown in my diagram.

and soldered on a link in place of the remote switch.

Next I attached the battery to the 3v output on the arduino board.
You don't have to do this. But I did it so I wouldn't need a battery in the remote control.

STEP 5: The Software

the arduino board is controlled from it's own software this can be downloaded from here.
http://www.arduino.cc/en/Main/Software

you can then copy and paste this code in to the arduino software and upload it to the board.

char val; // variable to receive data from the serial port
int ledpin = 2; // LED connected to pin 2 (on-board LED)

void setup()
{
pinMode(ledpin = 2, OUTPUT); // pin 2 (on-board LED) as OUTPUT
pinMode(ledpin = 3, OUTPUT); // pin 3 (on-board LED) as OUTPUT
pinMode(ledpin = 4, OUTPUT); // pin 4 (on-board LED) as OUTPUT
pinMode(ledpin = 5, OUTPUT); // pin 5 (on-board LED) as OUTPUT
pinMode(ledpin = 6, OUTPUT); // pin 6 (on-board LED) as OUTPUT
pinMode(ledpin = 7, OUTPUT); // pin 7 (on-board LED) as OUTPUT
pinMode(ledpin = 8, OUTPUT); // pin 8 (on-board LED) as OUTPUT
pinMode(ledpin = 9, OUTPUT); // pin 9 (on-board LED) as OUTPUT
pinMode(ledpin = 10, OUTPUT); // pin 9 (on-board LED) as OUTPUT
pinMode(ledpin = 11, OUTPUT); // pin 9 (on-board LED) as OUTPUT

Serial.begin(9600); // start serial communication at 9600bps

}

void loop() {
if( Serial.available() ) // if data is available to read
{;}
val = Serial.read(); // read it and store it in 'val'

if( val == 'h' ) // if '2' was received

{
digitalWrite(ledpin = 2, HIGH); // turn ON the LED
delay(1000); // waits for a second
Serial.println("h = Heating off");
digitalWrite(ledpin, LOW); // sets the LED off

}
if( val == 'H' ) // if '3' was received
{
digitalWrite(ledpin = 3, HIGH); // turn ON the LED
delay(1000); // waits for a second
Serial.println("H = Heating on");
digitalWrite(ledpin, LOW); // sets the LED off
}
if( val == 's' ) // if '4' was received
{
digitalWrite(ledpin = 4, HIGH); // turn ON the LED
delay(1000); // waits for a second
Serial.println("s = gate off");
digitalWrite(ledpin, LOW); // sets the LED off
}
if( val == 'S' ) // if '5' was received
{
digitalWrite(ledpin = 5, HIGH); // turn ON the LED
delay(1000); // waits for a second
Serial.println("S = gate on");
digitalWrite(ledpin, LOW); // sets the LED off
}
if( val == 'g' ) // if '6' was received
{
digitalWrite(ledpin = 6, HIGH); // turn ON the LED
delay(1000); // waits for a second
Serial.println("g = Garden lights off");
digitalWrite(ledpin, LOW); // sets the LED off
}
if( val == 'G' ) // if '7' was received
{
digitalWrite(ledpin = 7, HIGH); // turn ON the LED
delay(1000); // waits for a second
Serial.println("G = Garden lights on");
digitalWrite(ledpin, LOW); // sets the LED off
}
if( val == 'b' ) // if '8' was received
{
digitalWrite(ledpin = 8, HIGH); // turn ON the LED
delay(1000); // waits for a second
Serial.println("b = Bedroom light off");
digitalWrite(ledpin, LOW); // sets the LED off
}
if( val == 'B' ) // if '9' was received
{
digitalWrite(ledpin = 9, HIGH); // turn ON the LED
delay(1000); // waits for a second
Serial.println("B = Bedroom light on");
digitalWrite(ledpin, LOW); // sets the LED off
}
if( val == '9' ) // if '9' was received
{
digitalWrite(ledpin = 10, HIGH); // turn ON the LED
delay(1000); // waits for a second
Serial.println("9");
digitalWrite(ledpin, LOW); // sets the LED off
}
if( val == '0' ) // if '9' was received
{
digitalWrite(ledpin = 11, HIGH); // turn ON the LED
delay(1000); // waits for a second
Serial.println("0");
digitalWrite(ledpin, LOW); // sets the LED off
}

}

STEP 6: Testing

After I had set up the homeeasy module to respond to the remote.
(You can find out how to do this in the instructions for the modules.)

I loaded the software on to the arduino board.
And ran the command (H)

And my heating switches on.
I tested the other commands for the lights and security and they all responded as planned.

STEP 7: Final Assembly

the last job was to fix all the boards in a plastic box and made a hole for the USB to plug in to the arduino board.

You may find when the boards are in the box the range at which they work is shortened.
If this happens you can mount the remote antenna on the out side of the box as I have done this to solved the problem I had with range. But you will have to keep the leads short or they will effect the frequency at which the antena transmits at.

STEP 8: Controlling Remotely From the Internet Method 1 and 2

The computer I have connected to the arduino board is running Linux ubuntu.
But this board will work with windows, mac and Linux.

I have 3 ways of remotely controlling the board from the internet at the moment.

The first way will work with any computer. And that is using VNC to remotely login and control the board from the desktop. There are other software alternatives to remotely login.

Such as windows remote desktop.

And log me in https://secure.logmein.com/home.asp?lang=en

The second way which I use most of the time because of security.

Is to login using the Linux SSH terminal from windows using a program called putty.

you can also you do it this way using a mac.

When logged in

You can find out which device the arduino board is, by typing this command.

ls /dev/tty*

You should get a screen like this.

My device is USB0 but this can be different.

Then you can send the command.

screen /dev/ttyUSB0 9600

to open the tty terminal.

When the tty terminal is open you can then type the command to turn the device on or off. I.e. G or g for garden lights.

And that is about it.

if you have any problems here are some more usefull commands.
these comands will show you which tty services are running.
ps -lt ttyUSB0
ps ax | grep tty

this command will stop the service running.
kill (job number)

STEP 9: Controlling From the Internet Method 3 (using a Script)(even From My Phone)

This is a new update I have just set up to alow me to control the arduino board from any web browser.

I wanted to control my home automation from my phone but this was not very easy using VNC or SSH.

So installed webmin on my server this will give me full control of the machine from within a web browers.

In web min there is a page called command shell that will allow me to run commands from the web browser.

I original tried to run the comands I was using in the SSH terminal. but they didn't work in webmin.

So with help from my brother we wrote a script.

so now all I have to do is send a command like "home_auto h1" and the heating will switch on. or "home_auto h0" to switch the heating off.

so now it can all be controlled from my phone

here is a copy of the script.

#!/bin/bash

_usage () {
echo "gl1 it will run this comand echo G > /dev/ttyUSB0 9600 and turn my garden lights on"
echo "gl0 it will run this comand echo g > /dev/ttyUSB0 9600 and turn my garden lights off"
echo "s1 it will run this comand echo S > /dev/ttyUSB0 9600 and turn my gates on"
echo "s0 it will run this comand echo s > /dev/ttyUSB0 9600 and turn my gates off"
echo "h1 it will run this comand echo H > /dev/ttyUSB0 9600 and turn my heating on"
echo "h0 it will run this comand echo h > /dev/ttyUSB0 9600 and turn my heating off"
echo "b21 it will run this comand echo B > /dev/ttyUSB0 9600 and turn my bedroom 2 lights on"
echo "b20 it will run this comand echo b > /dev/ttyUSB0 9600 and turn my bedroom 2 lights off"
echo "N it will run this comand echo N > /dev/ttyUSB0 9600 and turn next bank of outputs on for 5 seconds"
echo "R it will run this comand echo R > /dev/ttyUSB0 9600 and turn the Relay on"
echo "r it will run this comand echo r > /dev/ttyUSB0 9600 and turn the Relay off"

}

case "$1" in

gl1)
#garden lights on
/bin/echo G > /dev/ttyUSB0 9600 && echo "Lights On"
;;

gl0)
#garden lights off
/bin/echo g > /dev/ttyUSB0 9600 && echo "Lights Off"
;;

s1)
# gates on
/bin/echo S > /dev/ttyUSB0 9600 && echo "Gates On"
;;

s0)
# gates off
/bin/echo s > /dev/ttyUSB0 9600 && echo "Gates Off"
;;

h1)
#heating on
/bin/echo H > /dev/ttyUSB0 9600 && echo "Heating on"
;;

h0)
# heating off
/bin/echo h > /dev/ttyUSB0 9600 && echo "Heating Off"
;;

b21)
# bedroom 2 lights on
/bin/echo B > /dev/ttyUSB0 9600 && echo "Bedroom 2 Lights On"
;;

b20)
#bedroom 2 lights off
/bin/echo b > /dev/ttyUSB0 9600 && echo "Bedroom 2 Lights Off"
;;

N)
#Next Bank on
/bin/echo N > /dev/ttyUSB0 9600 && echo "Next Bank on for 5 seconds"
;;

R)
#Relay on
/bin/echo R > /dev/ttyUSB0 9600 && echo "Relay on"
;;

r)
#Relay off
/bin/echo r > /dev/ttyUSB0 9600 && echo "Relay off"
;;

*)
#echo $0 ": Not a valid command";
echo "Please retype command";
_usage;
;;

esac

STEP 10: Updates and Upgrades

Update

I have now added the option of switching to the next set of button. It was just a matter of wiring in a spdt relay.

so when the relay is off the first bank of buttons are selected.

and when the relay is energised the second bank of buttons are selected.

I have also added a second relay incase I want to conect anything up in the future.

STEP 11: Future Upgrades

I am now in the process of connecting light and tempiture sensors to the arduino board.
which can help automate devices.




57 Comments

Hello, I want to add a username and password to the web page of my home automation system that I am using now. I tried very hard but I couldn't combine the two codes. I'm adding the codes
/*
Web Server
with
http auth mod by Minh Truong
5-18-215
*/
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 33);
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
//char userPass[200];
//char header[500];
String header;
//int bufferSize = 0;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
void loop() {
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
header += c;
if (c == '\n' && currentLineIsBlank) {
//parse headers
//bWluaDp0ZXN0 = 'minh:test' (user:password) base64 encode
Serial.print(header);
// Simpler just to find the credential string
// send a standard http response header
if(header.indexOf("bWluaDp0ZXN0") >= 0) {
//successful login
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close"); // the connection will be closed after completion of the response
//client.println("Refresh: 5"); // refresh the page automatically every 5 sec
client.println();
if(header.indexOf("GET / HTTP/1.1") >= 0) {
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.println("index");
client.println("</html>");
} else {
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.println("hello world!");
client.println("</html>");
}
} else {
// wrong user/pass
//client.println("HTTP/1.0 401 Authorization Required");
client.println("HTTP/1.1 401 Unauthorized");
client.println("WWW-Authenticate: Basic realm=\"Secure\"");
client.println("Content-Type: text/html");
client.println();
client.println("<html>Text to send if user hits Cancel button</html>"); // really need this for the popup!
}
header = "";
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println("client disconnected");
}
}

}//Loop





/* Web Server
A simple web server that shows the value of the analog input pins.
using an Arduino Wiznet Ethernet shield.
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
* Analog inputs attached to pins A0 through A5 (optional)
created 18 Dec 2009
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe
*/
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x2D };
byte gateway[] = { 192, 168, 0, 1 }; // <------- PUT YOUR ROUTERS IP Address to which your shield is connected Here
byte subnet[] = { 255, 255, 255, 0 }; // <------- It will be as it is in most of the cases
IPAddress ip(192,168,0,199);
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
#define RELAY_CH1 2
#define RELAY_CH2 3
#define RELAY_CH3 4
#define RELAY_CH4 5
#define RELAY_CH5 6
#define RELAY_CH6 7
#define RELAY_CH7 8
#define RELAY_CH8 9
String readString;
void setup() {
pinMode(RELAY_CH1, OUTPUT);
digitalWrite(RELAY_CH1, HIGH); // switch on LED1
pinMode(RELAY_CH2, OUTPUT);
digitalWrite(RELAY_CH2, HIGH); // switch on LED2
pinMode(RELAY_CH3, OUTPUT);
digitalWrite(RELAY_CH3, HIGH); // switch on LED3
pinMode(RELAY_CH4, OUTPUT);
digitalWrite(RELAY_CH4, HIGH); // switch on LED4
pinMode(RELAY_CH5, OUTPUT);
digitalWrite(RELAY_CH5, HIGH); // switch on LED5
pinMode(RELAY_CH6, OUTPUT);
digitalWrite(RELAY_CH6, HIGH); // switch on LED6
pinMode(RELAY_CH7, OUTPUT);
digitalWrite(RELAY_CH7, HIGH); // switch on LED7
pinMode(RELAY_CH8, OUTPUT);
digitalWrite(RELAY_CH8, HIGH); // switch on LED8
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
void loop() {
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
if (readString.length() < 100) {
//store characters to string
readString += c;//Serial.print(c);
}
Serial.write(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close"); // the connection will be closed after completion of the response
client.println("Refresh: 5"); // refresh the page automatically every 5 sec
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.println("<HEAD>");
client.println("<meta name='apple-mobile-web-app-capable' content='yes' />");
client.println("<meta name='apple-mobile-web-app-status-bar-style' content='black-translucent' />");
//client.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"http://www.digital2u.net/autohome.css\" />");
client.println("<meta http-equiv=\"refresh\" content=\"5;url=http://192.168.0.199/\"/&gt;" );
client.println("</HEAD>");
client.println("<body bgcolor=\"#D0D0D0\">");
//client.println("<hr/>");
//client.println("<hr/>");
//client.println("<h4><center><img border=\"2\" src=\"https://lh3.googleusercontent.com/-C6BoJrRUFko/UEUFeCwkvdI/AAAAAAAAAOc/E7gcYvPV6r4/s960/Logo.jpg\" /></center></h4>");
//client.println("<hr/>");
//client.println("<hr/>");
client.print("<center> <p> <h1>Welcome to Arduino Home Control V0.25 (Active Low) </h1></p> ");
//client.println("<br />");
//client.println("<br />");
// Relay Status Display
client.println("<center>");
client.println("<table border=\"5\">");
client.println("<tr>");
if (!digitalRead(RELAY_CH1))
{
client.print("<td> <p style=\"font-family:arial;color:black;font-size:26px;\">Device 1.</p><p style=\"font-family:arial;color:green;font-size:35px;\">ON</p> </td>");
}
else
{
client.print("<td> <p style=\"font-family:arial;color:black;font-size:26px;\">Device 1.</p><p style=\"font-family:arial;color:red;font-size:35px;\">OFF</p></td>");
}
if (!digitalRead(RELAY_CH2))
{
client.print("<td> <p style=\"font-family:arial;color:black;font-size:26px;\">Device 2.</p><p style=\"font-family:arial;color:green;font-size:35px;\">ON</p></td>");
}
else
{
client.print("<td> <p style=\"font-family:arial;color:black;font-size:26px;\">Device 2.</p><p style=\"font-family:arial;color:red;font-size:35px;\">OFF</p></td>");
}
if (!digitalRead(RELAY_CH3))
{
client.print("<td><p style=\"font-family:arial;color:black;font-size:26px;\">Device 3.</p><p style=\"font-family:arial;color:green;font-size:35px;\">ON</p></td>");
}
else
{
client.print("<td><p style=\"font-family:arial;color:black;font-size:26px;\">Device 3.</p><p style=\"font-family:arial;color:red;font-size:35px;\">OFF</p></td>");
}
if (!digitalRead(RELAY_CH4))
{
client.print("<td><p style=\"font-family:arial;color:black;font-size:26px;\">Device 4.</p><p style=\"font-family:arial;color:green;font-size:35px;\">ON</p></td>");
}
else
{
client.print("<td><p style=\"font-family:arial;color:black;font-size:26px;\">Device 4.</p><p style=\"font-family:arial;color:red;font-size:35px;\">OFF</p></td>");
}
if (!digitalRead(RELAY_CH5))
{
client.print("<td><p style=\"font-family:arial;color:black;font-size:26px;\">Device 5.</p><p style=\"font-family:arial;color:green;font-size:35px;\">ON</p></td>");
}
else
{
client.print("<td><p style=\"font-family:arial;color:black;font-size:26px;\">Device 5.</p><p style=\"font-family:arial;color:red;font-size:35px;\">OFF</p></td>");
}
if (!digitalRead(RELAY_CH6))
{
client.print("<td><p style=\"font-family:arial;color:black;font-size:26px;\">Device 6.</p><p style=\"font-family:arial;color:green;font-size:35px;\">ON</p></td>");
}
else
{
client.print("<td><p style=\"font-family:arial;color:black;font-size:26px;\">Device 6.</p><p style=\"font-family:arial;color:red;font-size:35px;\">OFF</p></td>");
}
if (!digitalRead(RELAY_CH7))
{
client.print("<td><p style=\"font-family:arial;color:black;font-size:26px;\">Device 7.</p><p style=\"font-family:arial;color:green;font-size:35px;\">ON</p></td>");
}
else
{
client.print("<td><p style=\"font-family:arial;color:black;font-size:26px;\">Device 7.</p><p style=\"font-family:arial;color:red;font-size:35px;\">OFF</p></td>");
}
if (!digitalRead(RELAY_CH8))
{
client.print("<td><p style=\"font-family:arial;color:black;font-size:26px;\">Device 8.</p><p style=\"font-family:arial;color:green;font-size:35px;\">ON</p></td>");
}
else
{
client.print("<td><p style=\"font-family:arial;color:black;font-size:26px;\">Device 8.</p><p style=\"font-family:arial;color:red;font-size:35px;\">OFF</p></td>");
}
client.println("</tr>");
client.println("</table>");
client.println("</center>");
client.println("<br />");
/* Relay Control Code */
client.println("<a href=\"/?relay1on\"\"> <button style=\"width:360px;height:120px\"> <font size=\"7\"; color:red ;>Device 1 ON </font> </button> </a> ");
client.println("<a href=\"/?relay1off\"\"> <button style=\"width:360px;height:120px\"> <font size=\"7\">Device 1 OFF </font> </button> </a> <br />");
client.println("<br />");
client.println("<a href=\"/?relay2on\"\"> <button style=\"width:360px;height:120px\"> <font size=\"7\">Device 2 ON </font> </button> </a> ");
client.println("<a href=\"/?relay2off\"\"> <button style=\"width:360px;height:120px\"> <font size=\"7\">Device 2 OFF </font> </button> </a> <br />");
client.println("<br />");
client.println("<a href=\"/?relay3on\"\"> <button style=\"width:360px;height:120px\"> <font size=\"7\">Device 3 ON </font> </button> </a> ");
client.println("<a href=\"/?relay3off\"\"> <button style=\"width:360px;height:120px\"> <font size=\"7\">Device 3 OFF </font> </button> </a> <br />");
client.println("<br />");
client.println("<a href=\"/?relay4on\"\"> <button style=\"width:360px;height:120px\"> <font size=\"7\">Device 4 ON </font> </button> </a> ");
client.println("<a href=\"/?relay4off\"\"> <button style=\"width:360px;height:120px\"> <font size=\"7\">Device 4 OFF </font> </button> </a> <br />");
client.println("<br />");
client.println("<a href=\"/?relay5on\"\"> <button style=\"width:360px;height:120px\"> <font size=\"7\">Device 5 ON </font> </button> </a> ");
client.println("<a href=\"/?relay5off\"\"><button style=\"width:360px;height:120px\"> <font size=\"7\">Device 5 OFF </font> </button> </a> <br />");
client.println("<br />");
client.println("<a href=\"/?relay6on\"\"><button style=\"width:360px;height:120px\"> <font size=\"7\">Device 6 ON </font> </button> </a> ");
client.println("<a href=\"/?relay6off\"\"><button style=\"width:360px;height:120px\"> <font size=\"7\">Device 6 OFF </font> </button> </a> <br />");
client.println("<br />");
client.println("<a href=\"/?relay7on\"\"><button style=\"width:360px;height:120px\"> <font size=\"7\">Device 7 ON </font> </button> </a> ");
client.println("<a href=\"/?relay7off\"\"><button style=\"width:360px;height:120px\"> <font size=\"7\">Device 7 OFF </font> </button> </a> <br />");
client.println("<br />");
client.println("<a href=\"/?relay8on\"\"><button style=\"width:360px;height:120px\"> <font size=\"7\">Device 8 ON </font> </button> </a> ");
client.println("<a href=\"/?relay8off\"\"><button style=\"width:360px;height:120px\"> <font size=\"7\">Device 8 OFF </font> </button> </a> <br />");
client.println("<br />");
// control arduino pin via ethernet Start //
if(readString.indexOf("?relay1on") >0)//checks for on
{
digitalWrite(RELAY_CH1, LOW); // set pin 4 high
//Serial.println("Led On");

client.println("<link rel='apple-touch-icon' href='http://chriscosma.co.cc/on.png' />");
//client.println("Light 1 Is On");
client.println("<br />");
}
else{
if(readString.indexOf("?relay1off") >0)//checks for off
{
digitalWrite(RELAY_CH1, HIGH); // set pin 4 low
//Serial.println("Led Off");
client.println("<link rel='apple-touch-icon' href='http://chriscosma.co.cc/off.png' />");
//client.println("Light 1 Is Off");
client.println("<br />");
}
}
if(readString.indexOf("?relay2on") >0)//checks for on
{
digitalWrite(RELAY_CH2, LOW); // set pin 4 high
//Serial.println("Led On");

client.println("<link rel='apple-touch-icon' href='http://chriscosma.co.cc/on.png' />");
//client.println("Light 1 Is On");
client.println("<br />");
}
else{
if(readString.indexOf("?relay2off") >0)//checks for off
{
digitalWrite(RELAY_CH2, HIGH); // set pin 4 low
//Serial.println("Led Off");
client.println("<link rel='apple-touch-icon' href='http://chriscosma.co.cc/off.png' />");
//client.println("Light 1 Is Off");
client.println("<br />");
}
}
if(readString.indexOf("?relay3on") >0)//checks for on
{
digitalWrite(RELAY_CH3, LOW); // set pin 4 high
//Serial.println("Led On");

client.println("<link rel='apple-touch-icon' href='http://chriscosma.co.cc/on.png' />");
//client.println("Light 1 Is On");
client.println("<br />");
}
else{
if(readString.indexOf("?relay3off") >0)//checks for off
{
digitalWrite(RELAY_CH3, HIGH); // set pin 4 low
//Serial.println("Led Off");
client.println("<link rel='apple-touch-icon' href='http://chriscosma.co.cc/off.png' />");
//client.println("Light 1 Is Off");
client.println("<br />");
}
}
if(readString.indexOf("?relay4on") >0)//checks for on
{
digitalWrite(RELAY_CH4, LOW); // set pin 4 high
//Serial.println("Led On");

client.println("<link rel='apple-touch-icon' href='http://chriscosma.co.cc/on.png' />");
//client.println("Light 1 Is On");
client.println("<br />");
}
else{
if(readString.indexOf("?relay4off") >0)//checks for off
{
digitalWrite(RELAY_CH4, HIGH); // set pin 4 low
//Serial.println("Led Off");
client.println("<link rel='apple-touch-icon' href='http://chriscosma.co.cc/off.png' />");
//client.println("Light 1 Is Off");
client.println("<br />");
}
}
if(readString.indexOf("?relay5on") >0)//checks for on
{
digitalWrite(RELAY_CH5, LOW); // set pin 4 high
//Serial.println("Led On");

client.println("<link rel='apple-touch-icon' href='http://chriscosma.co.cc/on.png' />");
//client.println("Light 1 Is On");
client.println("<br />");
}
else{
if(readString.indexOf("?relay5off") >0)//checks for off
{
digitalWrite(RELAY_CH5, HIGH); // set pin 4 low
//Serial.println("Led Off");
client.println("<link rel='apple-touch-icon' href='http://chriscosma.co.cc/off.png' />");
//client.println("Light 1 Is Off");
client.println("<br />");
}
}
if(readString.indexOf("?relay6on") >0)//checks for on
{
digitalWrite(RELAY_CH6, LOW); // set pin 4 high
//Serial.println("Led On");

client.println("<link rel='apple-touch-icon' href='http://chriscosma.co.cc/on.png' />");
//client.println("Light 1 Is On");
client.println("<br />");
}
else{
if(readString.indexOf("?relay6off") >0)//checks for off
{
digitalWrite(RELAY_CH6, HIGH); // set pin 4 low
//Serial.println("Led Off");
client.println("<link rel='apple-touch-icon' href='http://chriscosma.co.cc/off.png' />");
//client.println("Light 1 Is Off");
client.println("<br />");
}
}
if(readString.indexOf("?relay7on") >0)//checks for on
{
digitalWrite(RELAY_CH7, LOW); // set pin 4 high
//Serial.println("Led On");

client.println("<link rel='apple-touch-icon' href='http://chriscosma.co.cc/on.png' />");
//client.println("Light 1 Is On");
client.println("<br />");
}
else{
if(readString.indexOf("?relay7off") >0)//checks for off
{
digitalWrite(RELAY_CH7, HIGH); // set pin 4 low
//Serial.println("Led Off");
client.println("<link rel='apple-touch-icon' href='http://chriscosma.co.cc/off.png' />");
//client.println("Light 1 Is Off");
client.println("<br />");
}
}
if(readString.indexOf("?relay8on") >0)//checks for on
{
digitalWrite(RELAY_CH8, LOW); // set pin 4 high
//Serial.println("Led On");

client.println("<link rel='apple-touch-icon' href='http://chriscosma.co.cc/on.png' />");
//client.println("Light 1 Is On");
client.println("<br />");
}
else{
if(readString.indexOf("?relay8off") >0)//checks for off
{
digitalWrite(RELAY_CH8, HIGH); // set pin 4 low
//Serial.println("Led Off");
client.println("<link rel='apple-touch-icon' href='http://chriscosma.co.cc/off.png' />");
//client.println("Light 1 Is Off");
client.println("<br />");
}
}
// INPUT
// output the value of each analog input pin
//for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
// int sensorReading = analogRead(analogChannel);
// client.print("analog input ");
// client.print(analogChannel);
// client.print(" is ");
// client.print(sensorReading);
// client.println("<br />");
//}
client.println("<hr> <p> By <a href=\"http://androidcontrol.blogspot.com\"></p><p style=\"font-family:arial;color:blue;font-size:20px;\">Android Control Blogspot</p></a>");
readString="";
client.println("</body>");
client.println("</html>");
break;
}// if ( c == \n )
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
//client.println("<meta http-equiv=\"refresh\" content=\"10;url=http://192.168.0.199/\"/&gt;" );
// close the connection:
client.stop();
Serial.println("client disonnected");
}//if(Client)
}//Loop

how many cost is required on this project

Hi..
I am trying to do this project but i am stucked at a point..
I am not getting how to connect it to my home lights,tv and fridge with the circuit you have made above..
Please reply as soon as possible..
Thank You..

just connect the lode in realy

You need to connect the switches of your home devices to the arduino pins.

How many relay can be connected to arduino uno? Can anyone help?

This seems very long winded and expensive as those home plugs aren't cheap.

I've just automated a lot of things but using a WIFI shield for the arduino. It also acts as a web server and puts out a nice graphical front end to turn things on/off. Additionally instead of using all those components you have I simply bought an 8 ch relay controller for around £5. Now I can turn many things on/off from the web and it works great on any mobile phone too. I've also purchased a £4 RF remote kit which can also turn the volume up/down on things but again you can send signals to this over WIFI as it will be going through the Arduino 1st :)

Hello Shayneg,

I would like us to connect via my mail privately. I need you to put me through some things as I am about working on my final year project.

You can access me on chimelo2002@yahoo.com or you could still drop yours. I would contact you.

Thanks

So via your project can we switch on/off the devices even from a great distance of about 5 or 6km??

Dear, Can you please specify from website https://store.arduino.cc/ , which arduino board have you used to be specific?

I'm taking up this as my graduating project , please help me

Can we have a telephonic contact?

Your project introduced me to arduino's and is awesome. I however am using Blynk to control this from my phone. I also connected a DHT11 to send me temperature and humidity. You can expand this by using an arduino mega. My question is: how do you choose the proper optoisolator?

Hai Admin!

My name is Shila.

Ive 1 question.

why you choose arduino instead of raspberry pi to control home appliance?

Thanks ;)

The Arduino is more like an industrial programmable controller, while the Raspberry Pi is more like a personal computer. For automation with simple LED and pushbutton interfaces the Arduino is more cost-effective and can deliver better performance in direct control of hardware. However, in recent years bridge devices have appeared, allowing one to combine an Arduino board with a Raspberry Pi, providing the advantages of both.

Fantastic. Thank you for your time and instruction.I will be using this guide.

hiii
i want to prepare it, but

if i try to control 10 system with this project than ,can i do it??????
reply

your only limited to the number of pins on the arduino, you could, however by two arduinos and connect pin 0 (or the RX pin) of each board to each other and set one to respond to one list of commands and ignore others wile the other one responds to the commands the first one ignores.

how do you get the computer to atomaticly send commands to the bord? PLZ reply!

More Comments