Instructables
Picture of Ethernet Switching - with Arduino
Aim:

Switch relays from the ethernet or the internet, using your mobile, tablet or computer with a nice graphical user interface.

Update V4.06
Please read the below steps to Step 2 if you are viewing this article for the first time.
Please go to step 3 for the latest revision which is V4.06
A user modified version with logon option is placed in step 5 for easy download.

Material:

    * Arduino MEGA 2560
    * Arduino Ethernet Shield
    * Relay board
    * RJ45 cable


Tools:

    * Arduino Software version 1.0.1 (downloadable from Arduino Website )
    * A / B USB cable


Infrastructure:

    * Internet access with fixed IP for Arduino
    * Access to your router to share the port for internet access
    * Testing devices - your pc, mobile etc


Disclaimer:

    * This project was tested with iPhone 3GS, iPad 2 and MacBook Pro running Safari and PC running Safari, Firefox, Opera and IE.
    * This project was created on October 2012 with the mentioned material.
    * Binary sketch size: 22,322 bytes (of a 258,048 byte maximum).
    * This sketch does not offer any sort of authentification, therefore if required to be used from outside the network or from the internet, I suggest to configure your network to connect trough VPN. Nowadays many routers and smartphones support VPN.



 
Remove these adsRemove these ads by Signing Up

Step 1: Ethernet Switching - with Arduino - Description

Picture of Ethernet Switching - with Arduino - Description
iPadScreenshot.png
relay board.JPG
iPhone3GSPortrait.png
Description:

    * With this project, I had not included any images, or links to images from the internet. It only make use of CSS3 and HTML5.
    * The simulated LEDs are created from CSS3 code.
    * Some browsers does not make full use of CSS3 and HTML5. Thus I suggest using Safari.
1-40 of 63Next »
BuiT27 days ago

#include <Ethernet.h>

#include <SPI.h>

#include <EEPROM.h>

////////////////////////////////////////////////////////////////////////

//CONFIGURATION

////////////////////////////////////////////////////////////////////////

//IP manual settings

byte ip[] = {192, 168, 137, 100 }; //Manual setup only

byte gateway[] = {192, 168, 1, 1 }; //Manual setup only

byte subnet[] = {255, 255, 255, 0 }; //Manual setup only

byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

//Ethernet Port

EthernetServer server = EthernetServer(80); //default html port 80

//The number of outputs going to be switched.

int outputQuantity = 16; //should not exceed 10

//Invert the output of the leds

boolean outputInverted = false; //true or false

// This is done in case the relay board triggers the relay on negative, rather then on positive supply

//Html page refresh

int refreshPage = 15; //default is 10sec.

//Beware that if you make it refresh too fast, the page could become inacessable.

//Display or hide the "Switch on all Pins" buttons at the bottom of page

int switchOnAllPinsButton = false; //true or false

int outputAddress[] = { 22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37}; //Allocate 10 spaces and name the output pin address.

String buttonText[16] = {

"01. Right Lamp","02. Left Lamp","03. Bedroom","04. Kitchen","05. Water Heater","06. Gate","07. Toilet","08. Main Heater","09. Roof Light","10. Basement","11. Test","12. TEST2","13. TEST3","14. TEST4","15. TEST5","16. TEST6"};

// Set the output to retain the last status after power recycle.

int retainOutputStatus[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};//1-retain the last status. 0-will be off after power cut.

////////////////////////////////////////////////////////////////////////

//VARIABLES DECLARATION

////////////////////////////////////////////////////////////////////////

int outp = 0;

boolean printLastCommandOnce = false;

boolean printButtonMenuOnce = false;

boolean initialPrint = true;

String allOn = "";

String allOff = "";

boolean reading = false;

boolean outputStatus[16]; //Create a boolean array for the maximum ammount.

String rev = "V4.06";

unsigned long timeConnectedAt;

boolean writeToEeprom = false;

/////////////////////////////////////////////////

// Temperature Related Reading

const int tempInPin = A1;

int tempInValue = 0; //temperature read

int tempScaleOutValue = 0; //temperature formatted

int tempOutValue = 0; //temperature formatted

float tempOutDeg = 0.0;

////////////////////////////////////////////////////////////////////////

//RUN ONCE

////////////////////////////////////////////////////////////////////////

//Beginning of Program

void setup(){

Serial.begin(9600);

initEepromValues();

readEepromValues();

//Set pins as Outputs

boolean currentState = false;

int var;

for (int i = 0; i < outputQuantity; i++){

pinMode(outputAddress[i], OUTPUT);

var = outputAddress[i];

//Switch all outputs to either on or off on Startup

if(outputInverted == true) {

//digitalWrite(outputAddress[var], HIGH);

if(outputStatus[i] == 0){currentState = true;}else{currentState = false;} //check outputStatus if off, switch output accordingly

digitalWrite(var, currentState);

}

else{

//digitalWrite(outputAddress[var], LOW);

if(outputStatus[i] == 0){currentState = false;}else{currentState = true;}//check outputStatus if off, switch output accordingly

digitalWrite(var, currentState);

}

}

//Setting up the IP address. Comment out the one you dont need.

//Ethernet.begin(mac); //for DHCP address. (Address will be printed to serial.)

Ethernet.begin(mac, ip, gateway, subnet); //for manual setup. (Address is the one configured above.)

server.begin();

Serial.print("Server started at ");

Serial.println(Ethernet.localIP());

}

////////////////////////////////////////////////////////////////////////

//LOOP

////////////////////////////////////////////////////////////////////////

//Run once

void loop(){

//Read Temperature Sensor

tempInValue = analogRead(tempInPin);

// Connecting a 10K3 Thermistor to the Arduino Input

// +5V �—————————[10Kohms]—————————[Thermistor]——� 0V

// To Arduino IP �———————————|

tempScaleOutValue = map(tempInValue, 0, 1023, 1023, 0); //Arduino value and NTC of the 10K3 Thermistor

tempOutValue = map(tempScaleOutValue, 130, 870, -170, 730); //range of Arduino Value compared with Temperature

tempOutValue = tempOutValue -45; //Adjustments

tempOutDeg = tempOutValue / 10.0;

checkForClient();

}

////////////////////////////////////////////////////////////////////////

//checkForClient Function

////////////////////////////////////////////////////////////////////////

//

void checkForClient(){

EthernetClient client = server.available();

if (client) {

boolean currentLineIsBlank = true;

boolean sentHeader = false;

int temp,temp1;

while (client.connected()) {

if (client.available()) {

char c = client.read();

if(c == '*'){

printHtmlHeader(client); //call for html header and css

printLoginTitle(client);

printHtmlFooter(client);

break;

}

if(!sentHeader){

printHtmlHeader(client); //call for html header and css

printHtmlButtonTitle(client); //print the button title

sentHeader = true;

}

if(reading && c == ' '){

reading = false;

}

if(c == '?') {

reading = true; //found the ?, begin reading the info

}

if(reading){

//if user input is H set output to 1

if(c == 'H') {

outp = 1;

}

if(c == 'L') {

outp = 0;

}

// Serial.println(c); //print the value of c to serial communication

//---------------------------------------------------------------------------------------------

// ? H 1 0

// ^ ^ ^ ^

// | | | |____________read 4 ( 10,11,12,13....)

// | | |______________read 3 ( 1....9)

// | |________________read 2 if user input is H set output to L

// |__________________read 1

//---------------------------------------------------------------------------------------------

if( c == '1'){

char c = client.read();

switch (c) {

case '0':

triggerPin(outputAddress[10], client, outp);

break;

case '1':

triggerPin(outputAddress[11], client, outp);

break;

case '2':

triggerPin(outputAddress[12], client, outp);

break;

case '3':

triggerPin(outputAddress[13], client, outp);

break;

case '4':

triggerPin(outputAddress[14], client, outp);

break;

case '5':

triggerPin(outputAddress[15], client, outp);

break;

default:

char c = client.read();

triggerPin(outputAddress[1], client, outp);

}

}

else {

switch (c) {

case '0':

triggerPin(outputAddress[0], client, outp);

break;

// case '1':

// triggerPin(outputAddress[1], client, outp);

// break;

case '2':

triggerPin(outputAddress[2], client, outp);

break;

case '3':

//add code here to trigger on 3

triggerPin(outputAddress[3], client, outp);

break;

case '4':

//add code here to trigger on 4

triggerPin(outputAddress[4], client, outp);

break;

case '5':

//add code here to trigger on 5

triggerPin(outputAddress[5], client, outp);

//printHtml(client);

break;

case '6':

//add code here to trigger on 6

triggerPin(outputAddress[6], client, outp);

break;

case '7':

//add code here to trigger on 7

triggerPin(outputAddress[7], client, outp);

break;

case '8':

//add code here to trigger on 8

triggerPin(outputAddress[8], client, outp);

break;

case '9':

//add code here to trigger on 9

triggerPin(outputAddress[9], client, outp);

break;

} //end of switch case

}

}//end of switch switch the relevant output

//if user input was blank

if (c == '\n' && currentLineIsBlank){

printLastCommandOnce = true;

printButtonMenuOnce = true;

triggerPin(777, client, outp); //Call to read input and print menu. 777 is used not to update any outputs

break;

}

}

}

printHtmlFooter(client); //Prints the html footer

}

else{

if (millis() > (timeConnectedAt + 60000)){

if (writeToEeprom == true){

writeEepromValues(); //write to EEprom the current output statuses

Serial.println("No Clients for more then a minute - Writing statuses to Eeprom.");

writeToEeprom = false;

}

}

}

}// END

////////////////////////////////////////////////////////////////////////

//triggerPin Function

////////////////////////////////////////////////////////////////////////

//

void triggerPin(int pin, EthernetClient client, int outp){

if (pin != 777){

// Serial.println(pin);

if(outp == 1) {

if (outputInverted ==false){

digitalWrite(pin, HIGH);

}

else{

digitalWrite(pin, LOW);

}

}

if(outp == 0){

if (outputInverted ==false){

digitalWrite(pin, LOW);

}

else{

digitalWrite(pin, HIGH);

}

}

}

//Refresh the reading of outputs

readOutputStatuses();

//Prints the buttons

if (printButtonMenuOnce == true){

printHtmlButtons(client);

printButtonMenuOnce = false;

}

}

////////////////////////////////////////////////////////////////////////

//printHtmlButtons Function

////////////////////////////////////////////////////////////////////////

//print the html buttons to switch on/off channels

void printHtmlButtons(EthernetClient client){

//Start to create the html table

client.println("");

//client.println("<p>");

client.println("<FORM>");

client.println("<table border=\"0\" align=\"center\">");

//Printing the Temperature

client.print("<tr>\n");

client.print("<td><h4>");

client.print("Temperature");

client.print("</h4></td>\n");

client.print("<td></td>");

client.print("<td>");

client.print("<h3>");

client.print(tempOutDeg);

client.print(" °C</h3></td>\n");

client.print("<td></td>");

client.print("</tr>");

//Start printing button by button

for (int var = 0; var < outputQuantity; var++) {

//set command for all on/off

allOn += "H";

allOn += outputAddress[var];

allOff += "L";

allOff += outputAddress[var];

//Print begining of row

client.print("<tr>\n");

//Prints the button Text

client.print("<td><h4>");

client.print(buttonText[var]);

client.print("</h4></td>\n");

//Prints the ON Buttons+++++++++++++++++++++++++++++++++++++++++++++++

client.print("<td>");

client.print("<INPUT TYPE=\"button\" VALUE=\"ON ");

client.print("\" onClick=\"parent.location='/?H");

client.print(var);

client.print("'\"></td>\n");

//Prints the OFF Buttons ---------------------------------------------

client.print(" <td><INPUT TYPE=\"button\" VALUE=\"OFF");

client.print("\" onClick=\"parent.location='/?L");

client.print(var);

client.print("'\"></td>\n");

//Invert the LED display if output is inverted.

if (outputStatus[var] == true ){ //If Output is ON

if (outputInverted == false){ //and if output is not inverted

client.print(" <td><div class='green-circle'><div class='glare'></div></div></td>\n"); //Print html for ON LED

}

else{ //else output is inverted then

client.print(" <td><div class='black-circle'><div class='glare'></div></div></td>\n"); //Print html for OFF LED

}

}

else //If Output is Off

{

if (outputInverted == false){ //and if output is not inverted

client.print(" <td><div class='black-circle'><div class='glare'></div></div></td>\n"); //Print html for OFF LED

}

else{ //else output is inverted then

client.print(" <td><div class='green-circle'><div class='glare'></div></div></td>\n"); //Print html for ON LED

}

}

//Print end of row

client.print("</tr>\n");

}

//Display or hide the Print all on Pins Button

if (switchOnAllPinsButton == true ){

//Prints the ON All Pins Button

client.print("<tr>\n<td><INPUT TYPE=\"button\" VALUE=\"Switch ON All Pins");

client.print("\" onClick=\"parent.location='/?");

client.print(allOn);

client.print("'\"></td>\n");

//Prints the OFF All Pins Button

client.print("<td><INPUT TYPE=\"button\" VALUE=\"Switch OFF All Pins");

client.print("\" onClick=\"parent.location='/?");

client.print(allOff);

client.print("'\"></td>\n<td></td>\n<td></td>\n</tr>\n");

}

//Closing the table and form

client.println("</table>");

client.println("</FORM>");

//client.println("</p>");

}

////////////////////////////////////////////////////////////////////////

//readOutputStatuses Function

////////////////////////////////////////////////////////////////////////

//Reading the Output Statuses

void readOutputStatuses(){

for (int var = 0; var < outputQuantity; var++) {

outputStatus[var] = digitalRead(outputAddress[var]);

//Serial.print(outputStatus[var]);

}

}

////////////////////////////////////////////////////////////////////////

//readEepromValues Function

////////////////////////////////////////////////////////////////////////

//Read EEprom values and save to outputStatus

void readEepromValues(){

for (int adr = 0; adr < outputQuantity; adr++) {

outputStatus[adr] = EEPROM.read(adr);

}

}

////////////////////////////////////////////////////////////////////////

//writeEepromValues Function

////////////////////////////////////////////////////////////////////////

//Write EEprom values

void writeEepromValues(){

for (int adr = 0; adr < outputQuantity; adr++) {

EEPROM.write(adr, outputStatus[adr]);

}

}

////////////////////////////////////////////////////////////////////////

//initEepromValues Function

////////////////////////////////////////////////////////////////////////

//Initialiaze EEprom values

//if eeprom values are not the correct format ie not euqual to 0 or 1 (thus greater then 1) initialize by putting 0

void initEepromValues(){

for (int adr = 0; adr < outputQuantity; adr++){

if (EEPROM.read(adr) > 1){

EEPROM.write(adr, 0);

}

}

}

////////////////////////////////////////////////////////////////////////

//htmlHeader Function

////////////////////////////////////////////////////////////////////////

//Prints html header

void printHtmlHeader(EthernetClient client){

// Serial.print("Serving html Headers at ms -");

timeConnectedAt = millis(); //Record the time when last page was served.

// Serial.print(timeConnectedAt); // Print time for debbugging purposes

writeToEeprom = true; // page loaded so set to action the write to eeprom

// send a standard http response header

client.println("HTTP/1.1 200 OK");

client.println("Content-Type: text/html");

client.println("Connnection: close");

client.println();

client.println("<!DOCTYPE HTML>");

client.println("<head>");

// add page title

client.println("<title>Ethernet Switching</title>");

client.println("<meta name=\"description\" content=\"Ethernet Switching\"/>");

// add a meta refresh tag, so the browser pulls again every x seconds:

client.print("<meta http-equiv=\"refresh\" content=\"");

client.print(refreshPage);

client.println("; url=/\">");

// add other browser configuration

client.println("<meta name=\"apple-mobile-web-app-capable\" content=\"yes\">");

client.println("<meta name=\"apple-mobile-web-app-status-bar-style\" content=\"default\">");

client.println("<meta name=\"viewport\" content=\"width=device-width, user-scalable=no\">");

//inserting the styles data, usually found in CSS files.

client.println("<style type=\"text/css\">");

client.println("");

//This will set how the page will look graphically

client.println("html { height:100%; }");

client.println(" body {");

client.println(" height: 100%;");

client.println(" margin: 0;");

client.println(" font-family: helvetica, sans-serif;");

client.println(" -webkit-text-size-adjust: none;");

client.println(" }");

client.println("");

client.println("body {");

client.println(" -webkit-background-size: 100% 21px;");

client.println(" background-color: #c5ccd3;");

client.println(" background-image:");

client.println(" -webkit-gradient(linear, left top, right top,");

client.println(" color-stop(.75, transparent),");

client.println(" color-stop(.75, rgba(255,255,255,.1)) );");

client.println(" -webkit-background-size: 7px;");

client.println(" }");

client.println("");

client.println(".view {");

client.println(" min-height: 100%;");

client.println(" overflow: auto;");

client.println(" }");

client.println("");

client.println(".header-wrapper {");

client.println(" height: 44px;");

client.println(" font-weight: bold;");

client.println(" text-shadow: rgba(0,0,0,0.7) 0 -1px 0;");

client.println(" border-top: solid 1px rgba(255,255,255,0.6);");

client.println(" border-bottom: solid 1px rgba(0,0,0,0.6);");

client.println(" color: #fff;");

client.println(" background-color: #8195af;");

client.println(" background-image:");

client.println(" -webkit-gradient(linear, left top, left bottom,");

client.println(" from(rgba(255,255,255,.4)),");

client.println(" to(rgba(255,255,255,.05)) ),");

client.println(" -webkit-gradient(linear, left top, left bottom,");

client.println(" from(transparent),");

client.println(" to(rgba(0,0,64,.1)) );");

client.println(" background-repeat: no-repeat;");

client.println(" background-position: top left, bottom left;");

client.println(" -webkit-background-size: 100% 21px, 100% 22px;");

client.println(" -webkit-box-sizing: border-box;");

client.println(" }");

client.println("");

client.println(".header-wrapper h1 {");

client.println(" text-align: center;");

client.println(" font-size: 20px;");

client.println(" line-height: 44px;");

client.println(" margin: 0;");

client.println(" }");

client.println("");

client.println(".group-wrapper {");

client.println(" margin: 9px;");

client.println(" }");

client.println("");

client.println(".group-wrapper h2 {");

client.println(" color: #4c566c;");

client.println(" font-size: 17px;");

client.println(" line-height: 0.8;");

client.println(" font-weight: bold;");

client.println(" text-shadow: #fff 0 1px 0;");

client.println(" margin: 20px 10px 12px;");

client.println(" }");

client.println("");

client.println(".group-wrapper h3 {");

client.println(" color: #4c566c;");

client.println(" font-size: 12px;");

client.println(" line-height: 1;");

client.println(" font-weight: bold;");

client.println(" text-shadow: #fff 0 1px 0;");

client.println(" margin: 20px 10px 12px;");

client.println(" }");

client.println("");

client.println(".group-wrapper h4 {"); //Text for description

client.println(" color: #212121;");

client.println(" font-size: 14px;");

client.println(" line-height: 1;");

client.println(" font-weight: bold;");

client.println(" text-shadow: #aaa 1px 1px 3px;");

client.println(" margin: 5px 5px 5px;");

client.println(" }");

client.println("");

client.println(".group-wrapper table {");

client.println(" background-color: #fff;");

client.println(" -webkit-border-radius: 10px;");

client.println(" -moz-border-radius: 10px;");

client.println(" -khtml-border-radius: 10px;");

client.println(" border-radius: 10px;");

client.println(" font-size: 17px;");

client.println(" line-height: 20px;");

client.println(" margin: 9px 0 20px;");

client.println(" border: solid 1px #a9abae;");

client.println(" padding: 11px 3px 12px 3px;");

client.println(" margin-left:auto;");

client.println(" margin-right:auto;");

client.println(" -moz-transform :scale(1);"); //Code for Mozilla Firefox

client.println(" -moz-transform-origin: 0 0;");

client.println(" }");

client.println("");

//how the green (ON) LED will look

client.println(".green-circle {");

client.println(" display: block;");

client.println(" height: 23px;");

client.println(" width: 23px;");

client.println(" background-color: #0f0;");

//client.println(" background-color: rgba(60, 132, 198, 0.8);");

client.println(" -moz-border-radius: 11px;");

client.println(" -webkit-border-radius: 11px;");

client.println(" -khtml-border-radius: 11px;");

client.println(" border-radius: 11px;");

client.println(" margin-left: 1px;");

client.println(" background-image: -webkit-gradient(linear, 0% 0%, 0% 90%, from(rgba(46, 184, 0, 0.8)), to(rgba(148, 255, 112, .9)));@");

client.println(" border: 2px solid #ccc;");

client.println(" -webkit-box-shadow: rgba(11, 140, 27, 0.5) 0px 10px 16px;");

client.println(" -moz-box-shadow: rgba(11, 140, 27, 0.5) 0px 10px 16px; /* FF 3.5+ */");

client.println(" box-shadow: rgba(11, 140, 27, 0.5) 0px 10px 16px; /* FF 3.5+ */");

client.println(" }");

client.println("");

//how the black (off)LED will look

client.println(".black-circle {");

client.println(" display: block;");

client.println(" height: 23px;");

client.println(" width: 23px;");

client.println(" background-color: #040;");

client.println(" -moz-border-radius: 11px;");

client.println(" -webkit-border-radius: 11px;");

client.println(" -khtml-border-radius: 11px;");

client.println(" border-radius: 11px;");

client.println(" margin-left: 1px;");

client.println(" -webkit-box-shadow: rgba(11, 140, 27, 0.5) 0px 10px 16px;");

client.println(" -moz-box-shadow: rgba(11, 140, 27, 0.5) 0px 10px 16px; /* FF 3.5+ */");

client.println(" box-shadow: rgba(11, 140, 27, 0.5) 0px 10px 16px; /* FF 3.5+ */");

client.println(" }");

client.println("");

//this will add the glare to both of the LEDs

client.println(" .glare {");

client.println(" position: relative;");

client.println(" top: 1;");

client.println(" left: 5px;");

client.println(" -webkit-border-radius: 10px;");

client.println(" -moz-border-radius: 10px;");

client.println(" -khtml-border-radius: 10px;");

client.println(" border-radius: 10px;");

client.println(" height: 1px;");

client.println(" width: 13px;");

client.println(" padding: 5px 0;");

client.println(" background-color: rgba(200, 200, 200, 0.25);");

client.println(" background-image: -webkit-gradient(linear, 0% 0%, 0% 95%, from(rgba(255, 255, 255, 0.7)), to(rgba(255, 255, 255, 0)));");

client.println(" }");

client.println("");

//and finally this is the end of the style data and header

client.println("</style>");

client.println("</head>");

//now printing the page itself

client.println("<body>");

client.println("<div class=\"view\">");

client.println(" <div class=\"header-wrapper\">");

client.println(" <h1>Ethernet Switching</h1>");

client.println(" </div>");

//////

} //end of htmlHeader

////////////////////////////////////////////////////////////////////////

//htmlFooter Function

////////////////////////////////////////////////////////////////////////

//Prints html footer

void printHtmlFooter(EthernetClient client){

//Set Variables Before Exiting

printLastCommandOnce = false;

printButtonMenuOnce = false;

allOn = "";

allOff = "";

//printing last part of the html

client.println("\n<h3 align=\"center\">Development - Chinh Truc <br> 01 - August - 2014 - V5.0");

client.println("\n<h3 align=\"center\">© Author - Claudio Vella <br> Malta - October - 2012 - ");

client.println(rev);

client.println("</h3></div>\n</div>\n</body>\n</html>");

delay(1); // give the web browser time to receive the data

client.stop(); // close the connection:

Serial.println(" - Done, Closing Connection.");

delay (2); //delay so that it will give time for client buffer to clear and does not repeat multiple pages.

} //end of htmlFooter

////////////////////////////////////////////////////////////////////////

//printHtmlButtonTitle Function

////////////////////////////////////////////////////////////////////////

//Prints html button title

void printHtmlButtonTitle(EthernetClient client){

client.println("<div class=\"group-wrapper\">");

client.println(" <h2>Switch Device output.</h2>");

client.println();

}

////////////////////////////////////////////////////////////////////////

//printLoginTitle Function

////////////////////////////////////////////////////////////////////////

//Prints html button title

void printLoginTitle(EthernetClient client){

// client.println("<div class=\"group-wrapper\">");

client.println(" <h2>Please enter the user data to login.</h2>");

client.println();

}

Untitled.png
la3bna1 month ago

This is a really good project, Im tring to get this working on an Nano and a WIZ550io module, I have updated libs. Examples work but not this. I have changed the MAC (the wiz550 has a mac sticker on it).

Changed araound with pins and removed some of them.

tcvella (author)  la3bna1 month ago

Hi la3bna,

As per my instructions, I had tested this with the Arduino MEGA. If you read older posts you will find out that users had issues with the A. UNO probably due to low RAM size. So I am guessing you are encountering a similar issue with the Nano.

In other words to use the NANO you should compromise and leave some code out.

la3bna tcvella1 month ago

Ok I have trimmed it down some. I will try to leave out part of the HTML code and see if I get it running. The main reason I was looking at this is becase of the way it looks. If I dont get it working I will have to buy a MEGA ;).

Thanks replaying so fast

la3bna la3bna1 month ago

I saw that the issue would be resolved by commenting the CCS stuff. I am going to test that and maybe hav a ccs file on a network computer and poinit the html style ref to it. hoping that will work.

la3bna la3bna1 month ago

The browser only tried to download from the server address. Nothing is displayed

pgupta311 month ago

Hi, nice project wanted to make one for me but I have uno board with w5100 shield. This program is not working on Uno. Can you help. I have tried other 8 relay program and it was working fine but I want to make this one with temperature sensor

.

iwrk4dedpr2 months ago

Thanks for posting all this great information. I have just bought 2 arduino controlers ( 1 for me and one for my 12 year old daughter ). Years ago my interest was in building smart homes. While the concept is out there presently I'd sure like to see my daughter find ways to make intelligent homes more reasonable and efficient. I think at my age my usefulness in this endeavor will be limited.

What you have done here is exactly where I'd like to get to ( and quickly ) I can't do much in a house that's all ready built but I'd like to design some system for new built homes where wiring can be done in a proper fashion.

Again thanks for demonstrating and, more importantly, sharing your knowledge with strangers.

tcvella (author)  iwrk4dedpr2 months ago
Thanks for your comments. I appreciate that you like the project and are making use of it.
teqmo tcvella2 months ago

This is a great project just started picking it up but the on and off are backwards for me would you mind giving some advice?

lights on the webpage come on when the relay lights go off.

jlout2 months ago

Hello,

Can this tutorial be used for RF transmitter as well?

So every button sends a code like that "mySwitch.switchOn("11111", "00010");" in order to turn on or off RF plugs.

I have a working RF transmitter GUI which is rather lame + it does not work properly under mobile devices.

tcvella (author)  jlout2 months ago
​I guess so. It depends on what your transmitter is, and does. If your transmitter can be switched by an arduino, then instead of sending the port to go high or low, you will send the command you need.
jlout tcvella2 months ago

I have a 433Mhz transmitter and i have successfully tested it with RCSwitch webserver.

The only problem i have is that it has a very simplistic UI and it does not work properly with mobile devices. I can only turn on and off 1 or 2 times a power outlet until it stops working (but it is working properly from firefox/chrome etc from a desktop browser).

The commands i'm using look like this:

void processCommand(char* command) {
if (strcmp(command, "1-on") == 0) {
mySwitch.switchOn("11111", "00010");
} else if (strcmp(command, "1-off") == 0) {
mySwitch.switchOff("11111", "00010");

and so on.

Could you elaborate on the code changes so it can work with RF transmitter?

It would be really cool since you only need some RF outlets (i currently have 8).

Thank you

ShalvaN3 months ago

Hi there,

Great project i already set it up, but i have few questions:

1) is there a possibility to change NTC to DS18B20 (lets say 2 of them)?

2) can we add DHT22 to check also humidity?

the web page could look like this

temp in (dht22 - nr1)

humidity in (dht22 - nr1)

temp out (dht22-nr2)

humidity out (dht22-nr2)

temp something 1 (DS18B20)

temp something 2 (DS18B20)

and at last all of them could be programable ( so i can tourn them visible or invisible, change the names)

kitjawat6 months ago

When I'm browsing from a computer on the same LAN as the Arduino, everything works fine. But when I'm browsing from a remote location via my VPN, the page waiting and timeout from the Arduino Ethernet Shield web server and some time it work fine.

do you know how to fix it?

sidbin6 months ago

Problem will be at UNO with RAM (2kB RAM vs. MEGA 8KB).

After deleting the css page arduino works.
erojs8 months ago
First of all it's nice to hear that someone else is interested in pulse solution.
I have to warn everyone that for my compilation I used original 4.06 code and added DS18B20 and login parts adjusted from drewpalmer04 code.

Please note, when used with login function, the device hangs very rapidly! sometimes after 24h.
maybe it is a millis issue, however without the login elements the code works like a charm.
Could also be issue with string.h usage and note that drewpalmer04 login solution uses also the password part to let you in, for example if your password is 'password123', if you input 'password12345' it will also work.

In my project I used
4 relays in pulse mode
4 relays in on/off mode
5 Dallas DS18B20 temperature sensors
temperature sensors data is sent to ksduino.org for data logging. (free service like Pachube, Cosm etc. )
For pulse effect the function triggerPinPulse is used, where delay has to be set, if need, change 250 milliseconds to 2000 or 3000. this function basically changes the value to previous state after set delay.

I had power issues too, if I connected 5V DC adapter to Mega, not all of the relays worked.
Actually No4 didn't work, and if login function is used No8 (last) also had different state than No5, No6, No7. Without login No5, No6, No7, and No8 works all the same.
I solved my project by connecting DC 9V power adapter and USB cable connected to 5V 1A power adapter (my arduino is not connected to PC, when it operates).
After power loss it hangs, but works fine again after reset button pressed.

Here is the file:
http://failiem.lv/u/rnqpjmi
I will be happy to hear your comments and experience, as I would be happy to find bugs.
erojs9 months ago
The project is indeed great!

I tied to adjust ir for my needs, but somewhere I did something wrong.

I would really appreciate some advices.

The first thing I wanted to implement were the simple trigger buttons i needed along with on/off switches. I got it by modifying triggerPin function, I just created new one on base of it and added few lines to switch button back:

digitalWrite(pin, HIGH);

delay(250);

digitalWrite(pin, LOW);

Basically it works, both buttons does the same function.

The only problem is that if the new trigger relays after reconnecting power I want to remain off after disconnecting/connecting power, on/off switches will be on, and I can't get both off.



Maybe someone has solution?



Another thing I wanted to implement is multiple DS18B20 sensors to be read and displayed. I tried both parastatic and average mode, but no success.

Every time something goes down, either IP is 0.0.0.0 and temperatures 0.0, or mostly temperature is constantly 85.
Only once I managed to get both temperature + switches, but after reconnecting the power, temperature was back to 85.
Does someone has experience with DS18B20?

Thank you.

It seems you managed to send only a pulse to your board?, i can't get this to work, i don't want it to stay on, just to get on for a second or two.
Carlos, me puedes ayudar?, necesito que el botón mande un pulso de unos 2 segundos al relay y se cierre enseguida, cuando usas para puertas o garages el mantener prendido provoca problemas.

Estoy feliz con este proyecto, mil gracias.

Puedes agregar la autenticación en tu versión original?, la que pusieron aquí no compila bonito.
I beleive you don't speak Spanish, I thought you did since you have a latin name, just in case I will ask in English.

I need some of the relays to send a pulse (2-3 seconds) and then turn off, instead of staying on or off, since for garage door openers or 12v driven front doors. How can I do this.

Also, could you include the authentication and instruccions in your comments, I tried the one some user posted here but It won't compile, I beleive is made for the UNO and I have the Mega as you suggested

I'm really happy with this project, thanks alot
Perdón, Claudio. Me equivoqué de nombre
rdomarkas9 months ago
hello, i wanted to ask a question, is it possible to reach my router via vpn and then arduino server (arduino ethernet shield) using smartphone? do i need to use some apps for that aswell? thanks alot :)!!
jaquesdev9 months ago
Hi There

I would love to use this but, I would need to use the actual wall buttons to switch the lights on and off as well and not just via the website has anyone mange to get this to work?
dede4410 months ago
"All on/off buttons" doesn't works for me, it disables only the first pin.
I tested with 3 outputs (pin 38, 36 and 34)

the URL is that : http://myip/?L38L36L34
It only sets pin 38 low, not 36 and 34.

do you have an idea for fixing that ?
Thanks a lot for sharing your work
DISKJOHN10 months ago
Good morning I want to know the access to the display options for the switches on and off is done by entering the ip or is there some password first;
squid51610 months ago
have tried his on arduino uno but seems the code for css are not working in arduino uno...is there any way to solve it?
HansiEdi squid51610 months ago
Hello squid516,
you can purchase an Arduino Mega clone from China ~10 USD (Shipping free)

bye Hans
HansiEdi10 months ago
Hello tcvalla,

No-IP function in your EthernetSwitch

I have found the follow:
http://forum.arduino.cc//index.php?PHPSESSID=bld0709qub18o9fi4d54mn3pb4&topic=95456.15

It is very great and works fine :-)
Can you please integrate it to your EthernetSwitch?

It is a perfect combination :-)

bye Hans
rmvandek11 months ago
Great project. But also i have problems when downloaded to an UNO or the new Ethernet board. On the Mega I have it working well even when downscale it in the sofware to only 2 channels (uno can handle the amount of channels). Then change the boards and upload on an UNO, gives no reaction on the set IP adres. Compiling and sending is no problem after that I see only a continu stream of strange caracters (Aooo) in the serieel monitor. The UNO and Ethernet boards working well with other simpler ethernet switch software so it have to be something to do with this software. Anyone ideas what the difference can be. Tried a lot of thinks but all without positive results.
Acidjazz541 year ago
Claudio,

Great post and the interface is very nice. I'm wondering if you have any idea how I can convert this to work with the EtherCard library? I have a board that I made which uses the ENC28J60 chip instead of the WIZnet chip. Any help would be greatly appreciated.

Obrigado,

David Vaughn
asayegh1 year ago
i upload the same code on arduino but its not work ??
can you help me?
HansiEdi1 year ago
Hello and thanks.
I bought an Arduino MEGA and your project works.
tcvella, good afternoon.

Congratulations, beautiful and functional.
A doubt.
What would need to change the code to write the name of each button?
For example, where is Switch ON - write pin2 Light Room or any other room in the house.
You can?

Thank you and congratulations.

Alexandre / Sao Paulo / Brazil
tcvella (author)  Alexandre Yoshikawa1 year ago
This have been done on the latest versions. So check it out.
tcvella (author)  Alexandre Yoshikawa1 year ago
Hi Alexandre,

First thanks for your comments.
Currently the program does not have that option.
However that could be easily done by creating an array of the required names. Then instead of calling the var number to be displayed, you will call the var number of that array you have created.
Hope that this helped a bit.

Claudio Vella
HansiEdi1 year ago
Hi, I have the Arduino UNO as others, but unfortunately it does not work the sketch.
Can you write an update or do you need an Arduino Uno to eliminate the problem?

bye
tcvella (author)  HansiEdi1 year ago
Hi HansEdi,
I had tested the sketch with Arduino Mega, I don t have an Arduino uno to test the sketch on. It depends on the errors it is giving up. There are some things to inestigate. 1) Check the pinouts and arrange the sketch as required. 2) Check if you are having any missing library. These are the first points to check. Of course if having an Arduino Uno will help into solving such issue as one can tackle the issue.
Ya I have an UNO and can't seem to get it to work, but will keep trying.
Removed external links.

See page 5 for the login option for this great looking layout.

Also, The authentication option has 16 relay control... :)
1-40 of 63Next »