Read URL with Ethernet-shield

I found this skatch online. With this sketch you can write your webfile on a SD-Card.

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

// MAC address from Ethernet shield sticker under board
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 0, 20); // IP address, may need to change depending on network
EthernetServer server(80);  // create a server at port 80

File webFile;

void setup()
    Ethernet.begin(mac, ip);  // initialize Ethernet device
    server.begin();           // start to listen for clients
    Serial.begin(9600);       // for debugging
    // initialize SD card
    Serial.println("Initializing SD card...");
    if (!SD.begin(4)) {
        Serial.println("ERROR - SD card initialization failed!");
        return;    // init failed
    Serial.println("SUCCESS - SD card initialized.");
    // check for index.htm file
    if (!SD.exists("index3.htm")) {
        Serial.println("ERROR - Can't find index.htm file!");
        return;  // can't find index file
    Serial.println("SUCCESS - Found index.htm file.");

void loop()
{   delay(500);
    EthernetClient client = server.available();  // try to get client

    if (client) {  // got client?
        boolean currentLineIsBlank = true;
        while (client.connected()) {
            if (client.available()) {
             // client data available to read
                char c =; // read 1 byte (character) from client
                // last line of client request is blank and ends with \n
                // respond to client only after last line received
                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");
                    // send web page
                    webFile ="index3.htm");        // open web page file
                    if (webFile) {
                        while(webFile.available()) {
                            client.write(; // send web page to client
                // every line of text received from the client ends with \r\n
                if (c == '\n') {
                    // last character on line of received text
                    // starting new line with next character read
                    currentLineIsBlank = true;
                else if (c != '\r') {
                    // a text character was received from client
                    currentLineIsBlank = false;
            } // end if (client.available())
        } // end while (client.connected())
        delay(1);      // give the web browser time to receive the data
        client.stop(); // close the connection
    } // end if (client)

and this is my HTML Code

<!DOCTYPE html>
		<title>Arduino LED Control</title>
		<p>Click to switch LED on and off</p>
		<form method="get">
			<input type="checkbox" name="LED2" value="2" onclick="submit();">LED2

At first I entre the webserver.

No this shows the URL

and when I click the Button the new URL is

Now I want read the URL

Only the Part “LED=2” I used so many commands like readString.indexOf(“LED2=2”) or readString.indexOf("?LED2=2")

or Http request…

and nothing worked.

I want to switch on a LED

for example

If ( URL= LED2=2){


But I´m not able to read the URL.


I hope Someone can help, I googled so many hours and nothing worked.


                char c =; // read 1 byte (character) from client

What do you do with that character then?

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

You see if it's a carriage return. If it isn't, you:

                if (c == '\n') {

You see if it's a carriage return. If it still isn't, you:

                else if (c != '\r') {
                    // a text character was received from client
                    currentLineIsBlank = false;

You see if it's a line feed. If it isn't, you:

Hmmm, you throw it away.

I used so many commands like readString.indexOf("LED2=2") or readString.indexOf("?LED2=2")

But, you never populate readString, so you are just jerking around.

Perhaps it's now clear what you need to do.

I want to switch on a LED

Very simple server test code for controlling an arduino pin.

//zoomkat 10-6-13
//simple button GET with iframe code
//open serial monitor to see what the arduino receives
//use the ' instead of " in html ilnes 
//address will look like when submited
//for use with W5100 based ethernet shields

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

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

String readString; 


void setup(){

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

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

void loop(){
  // Create a client connection
  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c =;

        //read char by char HTTP request
        if (readString.length() < 100) {

          //store characters to string 
          readString += 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\r\n\r\n");
             else {
          client.println("HTTP/1.1 200 OK"); //send new page
          client.println("Content-Type: text/html");

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

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

          client.println("<IFRAME name=inlineframe style='display:none'>");          


          //stopping client

          ///////////////////// control arduino pin
          if(readString.indexOf("on1") >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