Interfacing Ethernet Shield with Arduino: How to send data to server

Interfacing Ethernet Shield with Arduino” In today’s tutorial we will learn about the interfacing of Ethernet Shield with Arduino. We will learn about the working of Ethernet and how it is used with Arduino? We will make a project using Ethernet and Arduino. We will communicate over Ethernet for controlling the real life objects. You may also like to check how to interface esp8266 wifi module with arduinoEthernet module interfacing with Arduino

Introduction to ethernet module interfacing with Arduino

Traditional Ethernet supports data transfers at the rate of 10 megabits per second. As the needs evolved with time additional new Ethernet specifications have been developed by industry for Fast Ethernet and Gigabit Ethernet. Fast internet has speed up to 100Mbps and Gigabit Ethernet has speed of 1000Mbps. Ethernet cables are also prepared for specific standards. CAT 5 is the most popular cable which support both traditional and Fast Ethernet. The CAT 5e and CAT 6 cables support Gigabit Ethernet. To connect Ethernet cables to a computer or other network device, a person plugs a cable directly into the device’s Ethernet port. Some devices without Ethernet supports can also support Ethernet connections through USB to Ethernet Adapters which are called dongles.

Working of Ethernet:

Working of Ethernet is a stepwise process. Following are the steps involved in the working of internet.

  1. First of all, users should have Ethernet card i.e. network interface card in the computer systems it is one of main components in transmitting the data from one place to another. Generally, Ethernet is used to transmit data in the form of different data packets, so it is the main hardware component for working with Ethernet.
  2. Second component is the recommended networking cable for the working of the Ethernet. There are number of wires in single cable on which the transmission of data depends and these cable also enable us to transmit data in both directions.
  3. The final step in the working of the Ethernet is to deliver the data from one place to another. For this purpose routers are used. They direct the computers to the network and help in working to share the data across different computers.
  4. Connect the computers having Ethernet connection to the internet or the any networking source. In this case routers of the Ethernet connect to the modem and then send or receive data with other networked systems.

Ethernet Shield for Arduino

Ethernet Shield comes with different pins, provided for connections. We place this shield on Arduino board properly and connect the Ethernet Port with the router providing the internet service.Note that The Ethernet shield is attached to pins 10, 11, 12, 13 so those cannot be used as general purpose input output pins.

Circuit Diagram of interfacing 

  1. Connect the Ethernet shield with router.
  2. Connect led positive pin at pin 8 of Ethernet Shield through resistor of 220ohm.
  3. Connect negative pin of LED with GND of Ethernet Shield.

Note: In program use the ip address of your connection and if your default port is blocked by internet service provider i.e. 80 use your own. Most of the times 80 works fine.

Code for interfacing with Arduino


  Web Server

A simple web server


* Ethernet shield attached to pins 10, 11, 12, 13



#include <SPI.h>

#include <Ethernet.h>

// Enter a MAC address and IP address for your controller below.

byte mac[] = {0x90, 0xA2, 0xDA, 0x0D, 0x48, 0xD3 };

// The IP address will be dependent on your local network:

// assign an IP address for the controller:

IPAddress ip(192,168,1,2);

IPAddress gateway(192,168,10,1);

IPAddress subnet(255, 255, 255, 0);

// Initialize the Ethernet server library with the port you want to use.

EthernetServer server(80);

String readString;



// Any extra codes for Declaration :

// Declare Pin 8 as an LED because thats what we will be connecting the LED to.You could use any other pin and would then have to change the pin number.

int led = 8;



void setup()



// Extra Set up code:

pinMode(led, OUTPUT); //pin selected to control



//enable serial data print


  //start Ethernet

  Ethernet.begin(mac, ip, gateway, subnet);


  Serial.print("Server is at ");


  Serial.println("LED Controller Test 1.0");




void loop()


  // listen for incoming clients

  EthernetClient client = server.available();

  if (client)


    Serial.println("new 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 you've gotten to the end of the line (received a newline

          // character) and the line is blank, the http request has ended,

          // so you can send a reply

          //if HTTP request has ended

          if (c == '\n') {

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


// Needed to Display Site:

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

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






// what is being Displayed :    


            client.println("<TITLE>Home Automation</TITLE>");




            client.println("<H1>Home Automation</H1>");

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


            client.println("<a href=\"/?lighton\"\">Turn On Light</a>");

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

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

            client.println("<a href=\"/?lightoff\"\">Turn Off Light</a><br />");    




            //stopping client



            // Code which needs to be Implemented:

            if(readString.indexOf("?lighton") >0)//checks for on


              digitalWrite(8, HIGH);    // set pin 8 high

              Serial.println("Led On");



              if(readString.indexOf("?lightoff") >0)//checks for off


                digitalWrite(8, LOW);    // set pin 8 low

                Serial.println("Led Off");



            //clearing string for next read


            // give the web browser time to receive the data


            // close the connection:


            Serial.println("client disonnected");








After uploading program copy ip address from Arduino serial monitor and paste it in browser. You will see a html page which give you provision of controlling LED.


  1. Ethernet Layer 2 Virtual Private Networks maximize the performance of existing IT infrastructure increasing network control.
  2. The deterministic and dynamic service attributes of Ethernet benefit the way cloud computing is used and consumed.
  3. Provides added performance and higher bandwidth levels along with service standardization at all locations.
  4. Offers better transparency, standardization at all locations and easier performance management.
  5. Provides better quality of service in video applications.
  6. Voice over Internet Protocol is well-known for its cost-savings.  Ethernet provides quality of service options and improved performance management.
  7. Provides added performance and higher bandwidth levels in distributed storage areas.
  8. Ethernet connectivity offers consistent cost and ubiquity enabling improved service management in CCTV applications.
  9. Ethernet allow business continuity and disaster recovery networks to optimally perform with measurable performance and flexible bandwidth levels.
  10. Ethernet delivers the higher bandwidth required for distributed imaging systems including picture archiving and communications system.


1 thought on “Interfacing Ethernet Shield with Arduino: How to send data to server”

  1. Hello, could you help what the problem might be?
    During the check, I get the following error:

    Ethernet2:3:7: error: expected constructor, destructor, or type conversion before ‘Server’
    In file included from D:\Arduino\_SajátProgramok\Ethernet2\Ethernet2.ino:15:0:
    C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src/SPI.h:178:39: error: ‘SPISettings’ has not been declared
    inline static void beginTransaction(SPISettings settings) {
    C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src/SPI.h: In static member function ‘static void SPIClass::beginTransaction(int)’:
    C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src/SPI.h:203:21: error: request for member ‘spcr’ in ‘settings’, which is of non-class type ‘int’
    SPCR = settings.spcr;
    C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI\src/SPI.h:204:21: error: request for member ‘spsr’ in ‘settings’, which is of non-class type ‘int’
    SPSR = settings.spsr;
    exit status 1
    expected constructor, destructor, or type conversion before ‘Server’

    Thank you.


Leave a Comment