Go Down

Topic: HTML Button Turn ON/OFF with Ethernet Wiznet (Read 24793 times) previous topic - next topic

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

Arrch


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.

Mohannad_Rawashdeh

I modified this Code hope it's helpful

Code: [Select]

// 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<br>");
          client.println("<input type= radio name=LED value= 0>Off<br>");
          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  .
no thing is impossible except that the state of your mind keeps it so...

Go Up