This is Open Source Home Automation Project based on Arduino Uno and Arduino Wiznet-based Ethernet shield.
How Does it Work
STEP 1:
Relay Controller Board Build Tutorial:
Sr.No | Component Names | Quantity |
1 | Relay (I have used GOODSKY RWH-SH-105D Relay) | 1 |
2 | Transistor 2N3904 | 1 |
3 | 1K Resistor | 2 |
4 | 10K Resistor | 1 |
5 | 1N4148 Diode | 1 |
6 | Red Led 3mm | 1 |
7 | 3 Pin PCB Mount Connector | 1 |
8 | 1 Pin PCB Mount Connector | 1 |
Note:
STEP 2:
Getting IP Address Of Arduino Ethernet Shield:
STEP 3:
Arduino Digital Pin No. | Pin Usage |
4 | will be used for Infrared Receiver |
5 | used as Output Pins to control Relays |
6 | used as Output Pins to control Relays |
7 | used as Output Pins to control Relays |
8 | used as Output Pins to control Relays |
9 | used as Output Pins to control Relays |
10 | will be used by Arduino Ethernet Shield |
11 | will be used by Arduino Ethernet Shield |
12 | will be used by Arduino Ethernet Shield |
13 | will be used by Arduino Ethernet Shield |
//for use with IDE 1.0
//open serial monitor to see what the arduino receives
//use the \ slash to escape the ” in the html
//for use with W5100 based ethernet shields
// this project is hosted at
// http://code.google.com/p/arduino-autohome/
#include <
#include
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x78, 0xE0 }; // <——- PUT YOUR MAC Address Here
byte ip[] = { 192, 168, 1, 102 }; // <——- PUT YOUR IP Address Here
byte gateway[] = { 192, 168, 1, 254 }; // <——- 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
EthernetServer server(80); // <——- It’s Defaulf Server Port for Ethernet Shield
String readString;
//////////////////////
void setup()
{
pinMode(6, OUTPUT); // Pin Assignment through which relay will be controlled
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
//start Ethernet
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
//enable serial data print
Serial.begin(9600);
Serial.println(“server LED test 1.0”); // so that we can know what is getting loaded
}
void loop()
{
// Create a client connection
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
//read char by char HTTP request
if (readString.length() < 100) {
//store characters to string
readString += c;
//Serial.print(c);
}
//if HTTP request has ended
if (c == ‘\n’) {
///////////////
Serial.println(readString); //print to serial monitor for debuging
/* Start OF HTML Section. Here Keep everything as it is unless you understands its working */
client.println(“HTTP/1.1 200 OK”); //send new page
client.println(“Content-Type: text/html”);
client.println();
//client.println(“”);
client.println(“”);
client.println(“”);
client.println(“”);
client.println(“”);
client.println(” “);
client.println(“”);
client.println(“”);
client.println(”
“);
client.println(”
“);
client.println(”
“);
client.println(”
“);
client.println(”
“);
client.println(”
“);
client.println(”
“);
client.println(”
“);
client.println(”
“);
client.println(”
“);
// Relay Control Code
client.println(“Turn On Light 1”);
client.println(“Turn Off Light 1
“);
client.println(”
“);
client.println(”
“);
client.println(”
“);
client.println(”
“);
client.println(“Turn On Light 2”);
client.println(“Turn Off Light 2
“);
client.println(”
“);
client.println(”
“);
client.println(”
“);
client.println(”
“);
client.println(“Turn On Light 3”);
client.println(“Turn Off Light 3
“);
client.println(”
“);
client.println(”
“);
client.println(”
“);
client.println(”
“);
client.println(“Turn On Light 4”);
client.println(“Turn Off Light 4
“);
client.println(”
“);
client.println(”
“);
// control arduino pin via ethernet Start //
if(readString.indexOf(“?relay1on”) >0)//checks for on
{
digitalWrite(6, HIGH); // set pin 4 high
Serial.println(“Led On”);
client.println(” “);
//client.println(“Light 1 Is On”);
client.println(”
“);
}
else{
if(readString.indexOf(“?relay1off”) >0)//checks for off
{
digitalWrite(6, LOW); // set pin 4 low
Serial.println(“Led Off”);
client.println(” “);
//client.println(“Light 1 Is Off”);
client.println(”
“);
}
}
if(readString.indexOf(“?relay2on”) >0)//checks for on
{
digitalWrite(7, HIGH); // set pin 4 high
Serial.println(“Led On”);
client.println(” “);
//client.println(“Light 2 Is On”);
client.println(”
“);
}
else{
if(readString.indexOf(“?relay2off”) >0)//checks for off
{
digitalWrite(7, LOW); // set pin 4 low
Serial.println(“Led Off”);
client.println(” “);
//client.println(“Light 2 Is Off”);
client.println(”
“);
}
}
if(readString.indexOf(“?relay3on”) >0)//checks for on
{
digitalWrite(8, HIGH); // set pin 4 high
Serial.println(“Led On”);
client.println(” “);
// client.println(“Light 3 Is On”);
client.println(”
“);
}
else{
if(readString.indexOf(“?relay3off”) >0)//checks for off
{
digitalWrite(8, LOW); // set pin 4 low
Serial.println(“Led Off”);
client.println(” “);
//client.println(“Light 3 Is Off”);
client.println(”
“);
}
}
if(readString.indexOf(“?relay4on”) >0)//checks for on
{
digitalWrite(9, HIGH); // set pin 4 high
Serial.println(“Led On”);
client.println(” “);
//client.println(“Light 4 Is On”);
client.println(”
“);
}
else{
if(readString.indexOf(“?relay4off”) >0)//checks for off
{
digitalWrite(9, LOW); // set pin 4 low
Serial.println(“Led Off”);
client.println(” “);
//client.println(“Light 4 Is Off”);
client.println(”
“);
}
}
// control arduino pin via ethernet End //
// Relay Status Display
client.println(”
“);
client.println(”
“);
if (digitalRead(6))
{
client.print(”
“);
}
else
{
client.print(”
“);
}
client.println(”
“);
if (digitalRead(7))
{
client.print(”
“);
}
else
{
client.print(”
“);
}
client.println(”
“);
client.println(”
“);
if (digitalRead(8))
{
client.print(”
“);
}
else
{
client.print(”
“);
}
if (digitalRead(9))
{
client.print(”
“);
}
else
{
client.print(”
“);
}
client.println(”
“);
client.println(”
Light 1 is ON | Light 1 is OFF | Light 2 is ON | Light 2 is OFF |
Light 3 is ON | Light 3 is OFF | Light 4 is ON | Light 4 is OFF |
“);
client.println(”
“);
//clearing string for next read
readString=””;
client.println(“”);
client.println(""); delay(1); //stopping client client.stop(); } } } } }
So you will have the control page as shown below:
So enjoy controlling things wirelessly..