HTML Button Turn ON/OFF with Ethernet Wiznet

Hello, i'm needing a source code for HMTL Button to turn ON and turn OFF a port of arduino with Ethernet Wiznet...

arduinohtml:
Hello, i'm needing a source code for HMTL Button to turn ON and turn OFF a port of arduino with Ethernet Wiznet...

Do you expect someone to just make it for you, or do you plan on putting some effort in yourself too?

Have you tried searching?

I just did, and found some projects involving exactly this.

And lastly, it looks like you already asked it here too Ligar/Desligar relé em html(usando botao) com Wiznet - Português - Arduino Forum another language, but still, double posting only leads to more frustrations than results.

Thank you for the link, very helpful! Unlike other users who talk a lot but do not add anything.

arduinohtml:
Thank you for the link, very helpful! Unlike other users who talk a lot but do not add anything.

By that, I guess you didn't do what I suggested, to search for it. If you had done that, you would have found what you needed too.

But well, easier to just have others do the work, instead of actually having to figure it out.

sui, I put this code in my ArduinoUno and is now available. To test I'm trying to turn off the digital port 13 (which already has an LED).
I changed the "int RCTransmissionPin = 7;" to 13 but did not work. You know how to do?

arduinohtml - Like yourself I am very new to Arduinos and the programming environment having bought my first Arduino only 6 weeks ago.

There are many useful resources available within this forum, but i think you need to start at the begining and learn the basics before jumping in the deep end. This will give you a good platform to learn from.

Within the Arduino programming environment, click on FILE, EXAMPLES, BASICS there you will find some basic examples and I suggest you start wit BLINK.

With these forums, its always best to post some code and ask for assistance so people can see what you are trying to achieve.

With the help of one board member particulalry, I have learnt an awful lot and been very appriciative, so there are good people on this forum.

Very simple web based gui for turning pin 4 on and off.

//zoomkat 9-5-11
//routerbot code
//for use with IDE 0021
//open serial monitor to see what the arduino receives
//use the \ slash to escape the " in the html 
//address will look like http://192.168.1.102:84/ when submited
//for use with W5100 based ethernet shields

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 102 }; // ip in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
Server server(84); //server port

String readString; 

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

void setup(){

  pinMode(4, OUTPUT); //pin selected to control
  //start Ethernet
  Ethernet.begin(mac, ip, gateway, subnet);
  server.begin();

  //enable serial data print 
  Serial.begin(9600); 
  Serial.println("servertest1"); // so I can keep track of what is loaded
}

void loop(){
  // Create a client connection
  Client 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 

          //now output HTML data header
             if(readString.indexOf('?') >=0) { //don't send new page
               client.println("HTTP/1.1 204 Zoomkat");
               client.println();
               client.println();  
             }
             else {
          client.println("HTTP/1.1 200 OK"); //send new page
          client.println("Content-Type: text/html");
          client.println();

          client.println("<HTML>");
          client.println("<HEAD>");
          client.println("<TITLE>Arduino GET test page</TITLE>");
          client.println("</HEAD>");
          client.println("<BODY>");

          client.println("<H1>Zoomkat's simple Arduino button</H1>");
          
          client.println("<a href=\"/?on\" target=\"inlineframe\">ON</a>"); 
          client.println("<a href=\"/?off\" target=\"inlineframe\">OFF</a>"); 

          //client.println("<IFRAME name=inlineframe src=\"res://D:/WINDOWS/dnserror.htm\" width=1 height=1\">");
          client.println("<IFRAME name=inlineframe style=\"display:none\" >");          
          client.println("</IFRAME>");

          client.println("</BODY>");
          client.println("</HTML>");
             }

          delay(1);
          //stopping client
          client.stop();

          ///////////////////// control arduino pin
          if(readString.indexOf("on") >0)//checks for on
          {
            digitalWrite(4, HIGH);    // set pin 4 high
            Serial.println("Led On");
          }
          if(readString.indexOf("off") >0)//checks for off
          {
            digitalWrite(4, LOW);    // set pin 4 low
            Serial.println("Led Off");
          }
          //clearing string for next read
          readString="";

        }
      }
    }
  }
}

Zoomkat, exactly what I needed to find my problem. I put this code on my Arduino and it worked. The problem is that Google Chrome, click the "OFF" it flashes the pin 4 and turn on again. Already IExplorer8 by clicking on "OFF" it really turns off pin 4 normally. How the browser works requests are generating this flaw in this code. Have you seen this problem?

Have you used the serial monitor to see if something different is being sent to the arduino from the different brousers?

Hi, as I've read this post, I' ve decided to start working on my Ethernet Shield.
I've tried out the code given by Zookmat.
It seems the Ethernet part of the code is working fine, but the led ( I used the PIN 13 one),
is not lighting up.
In serial monitor I receive this output:

servertest1
GET /?on HTTP/1.1

Led On
GET /?off HTTP/1.1

Led Off
GET /?on HTTP/1.1

Led On

Ofc I' ve written 13 where there was the 4 as pin.
Also the code seems correct, I don't find any apparent error, it just seems
Arduino is ignoring the instruction:

 digitalWrite(13, HIGH);

It seems the Ethernet part of the code is working fine, but the led ( I used the PIN 13 one), is not lighting up.

I forget the reason, but I don't think you can use pin 13 with the ethernet library. If you look close at the pin 13 led, it appears to be turning on/off very rapidly. I test the setup just by connecting my multimeter to pin 4 and watch the voltage change when the buttons are used.

Another worked example is at....

Great work Zoomkat,
indeed it works very fine, using other pins.
Thank to this now i can switch on/off my HVAC at home even if I'm at
work and I can restart my dsl router that unfortunately locks up too often at work.
Thanks.

arcom:
work and I can restart my dsl router that unfortunately locks up too often at work.

How are you going to contact it when the router is stalled?

I read here :

that the arduino uses pins 9 to 13 to communicate with the ethernet shield, therefore those pins cannot be used as general I/O in your project.

Texy

Texy:
I read here :
http://arduino.cc/en/Tutorial/WebServer

that the arduino uses pins 9 to 13 to communicate with the ethernet shield, therefore those pins cannot be used as general I/O in your project.

Texy

Should be 10-13 unless they changed something recently.

I modified this Code hope it's helpful

// orginal code found here 
//http://www.instructables.com/id/Arduino-WebServer-controlled-LED/?ALLSTEPS
//modified by : Mohannad Rawashdeh
//ethernet code  
//turn LED Connected to pin D5 On/Off
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 100 }; // ip in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port

String incoming; 

void setup(){

  pinMode(5, OUTPUT); //pin selected to control
  //start Ethernet
  Ethernet.begin(mac);
  server.begin();

  //enable serial data print 
  Serial.begin(9600); 
  Serial.println(Ethernet.localIP()); // print your IP Address on Serial Monitor 
}

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 (incoming.length() < 100) {

          //store characters to string 
          incoming += c; 
          //Serial.print(c);
        } 

        //if HTTP request has ended
        if (c == '\n') {

          ///////////////
          Serial.println(incoming); //print to serial monitor for debuging 

          //now output HTML data header
             if(incoming.indexOf('?') >=0) { //don't send new page
               client.println("HTTP/1.1 204 no data");
               client.println();
               client.println();  
             }
             else {
          client.println("HTTP/1.1 200 OK"); //send new page
          client.println("Content-Type: text/html");
          client.println();

          client.println("<html>");
          client.println("<head>");
          client.println("<TITLE> Genotronex Ethernet </TITLE>");
          client.println("</head>");
          client.println("<body>");

          client.println("<H2>Mohannad Rawashdeh</H2>");
          client.println("<H4>Turn On/Off LED connected To pin D5 </H4>");
          client.print("<FORM action=\"http://192.168.1.103/\" >");//change here to your ip address
          client.println("<input type=radio name=LED value= 1>On
"); 
          client.println("<input type= radio name=LED value= 0>Off
"); 
          client.println("<input type= submit value= Submit></FORM>");
         
          client.println("</BODY>");
          client.println("</HTML>");
             }

          delay(1);
          //stopping client
          client.stop();

       
          if(incoming.indexOf("GET /?LED=1") >=0)
          {
            digitalWrite(5, HIGH);    
            Serial.println("Led On");
          }
          if(incoming.indexOf("GET /?LED=0") >=0)//checks for off
          {
            digitalWrite(5, LOW);    
            Serial.println("Led Off");
          }
          delay(10);
          incoming=" ";//clear 

        }
      }
    }
  }
}

just connect led to D5 To blink it on /off

worked well on chrome and firefox .

bld:
How are you going to contact it when the router is stalled?

I thought the same! How will he pilot relay from arduino via web if the router is stuck thus unreachable?

Hi.

When I try to load this code into Adruino Uno:

//zoomkat 9-5-11
//routerbot code
//for use with IDE 0021
//open serial monitor to see what the arduino receives
//use the \ slash to escape the " in the html 
//address will look like http://192.168.1.102:84/ when submited
//for use with W5100 based ethernet shields

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 102 }; // ip in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
Server server(84); //server port

String readString; 

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

void setup(){

  pinMode(4, OUTPUT); //pin selected to control
  //start Ethernet
  Ethernet.begin(mac, ip, gateway, subnet);
  server.begin();

  //enable serial data print 
  Serial.begin(9600); 
  Serial.println("servertest1"); // so I can keep track of what is loaded
}

void loop(){
  // Create a client connection
  Client 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 

          //now output HTML data header
             if(readString.indexOf('?') >=0) { //don't send new page
               client.println("HTTP/1.1 204 Zoomkat");
               client.println();
               client.println();  
             }
             else {
          client.println("HTTP/1.1 200 OK"); //send new page
          client.println("Content-Type: text/html");
          client.println();

          client.println("<HTML>");
          client.println("<HEAD>");
          client.println("<TITLE>Arduino GET test page</TITLE>");
          client.println("</HEAD>");
          client.println("<BODY>");

          client.println("<H1>Zoomkat's simple Arduino button</H1>");
          
          client.println("<a href=\"/?on\" target=\"inlineframe\">ON</a>"); 
          client.println("<a href=\"/?off\" target=\"inlineframe\">OFF</a>"); 

          //client.println("<IFRAME name=inlineframe src=\"res://D:/WINDOWS/dnserror.htm\" width=1 height=1\">");
          client.println("<IFRAME name=inlineframe style=\"display:none\" >");          
          client.println("</IFRAME>");

          client.println("</BODY>");
          client.println("</HTML>");
             }

          delay(1);
          //stopping client
          client.stop();

          ///////////////////// control arduino pin
          if(readString.indexOf("on") >0)//checks for on
          {
            digitalWrite(4, HIGH);    // set pin 4 high
            Serial.println("Led On");
          }
          if(readString.indexOf("off") >0)//checks for off
          {
            digitalWrite(4, LOW);    // set pin 4 low
            Serial.println("Led Off");
          }
          //clearing string for next read
          readString="";

        }
      }
    }
  }
}

Then I have such error message:

Any hints?