Uno R3 as web server with Ethernet shield

Hello, and welcome to our today's blog contribution.


Today we put to you oursEthernet Shield W5100 before. The Shield can be simply put on our Mikrokontroller, compatibly with Arduino UN R3, and extends the microcontroller by an Ethernet interface and a map reader SD.

Background the inquiry of a friend was supervised by means of a Mikrokontroller, compatibly with Arduino UN R3, a single analogous sensor. He would like to question on this now by web interface. Nevertheless, he would like to fall back not on an ESP and a binding by WLAN, but him Mikrokontroller, compatibly with Arduino UNR3 by LAN cable with his network connect, because to him WLAN is too unreliable and generates zuviele EM issues.


1. Test construction

For our experiment we need beside the W5100 Ethernet Shield oneMikrokontroller, compatibly with Arduino UN R3and any analogous sensor. I use an easy one in this example Brightness sensor which can be substituted, nevertheless, with any analogous sensor.

We put the Ethernet-Shield carefully on him Mikrokontroller, compatibly with Arduino UNR3. We connect the brightness sensor as follows:



Brightness sensor

5 V







2. The programming

The programming Mikrokontrollers, compatibly with Arduino UNR3 is almost as easy thanks to the Arduino libraries as with the modules ESP.

We need merely the librariesSPI.h and Ethernet.h, weilche are installed with the IDE with.

We find practical proofs a functioning example under "file" -> "examples" ->  "Ethernet" -> "web server" which we must adapt only slightly.

Because we would like to be of use DHCP if available, we substitute for the line "Ethernet.begin (Mac, ip);" by the following code:



  if (Ethernet.begin(Mac) == 0) {     Serial.println("Failed to configure Ethernet using DHCP");     //try to congifure using IP address instead of DHCP:     Ethernet.begin(Mac, ip);   server.begin();   Serial.print("server is At");   Serial.println(Ethernet.localIP());   }

Because we loop in "void ()" only one value must be economical, we can substitute for the "for" loop by:


            int sensorReading = analogRead(0);             client.print("analogously input");             client.print("0");             client.print("is");             client.print(sensorReading);             client.println("<br />");

Then the complete code looks as follows:



 Web server

 A simple ones weave server that shows the value of the analogously input pins.
 using in Arduino Wiznet Ethernet shield.

 * Ethernet shield attached to pins 10, 11, 12, 13
 * Analogously input attached to pins A0 through A5 (optionally)

 created 18 Dec in 2009
 by David A. Mellis
 modified 9 Apr in 2012
 by Tom Igoe
 modified 02 Sept in 2015
 by Arturo Guadalupi


#include <SPI.H>
#include <Ethernet.H>

//Enter a MAC address and IP address for your controller below.
//The IP address wants Be dependent on your local network:
byte Mac[] = {   0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
IPAD DRESS ip(192, 168, 168, 51);

//Initialize the Ethernet server library
//with the IP address and port you shroud to use
//(port 80 is default for HTTP):
EthernetServer server(80);

void set-up() {   //Open serial communications and wait for port to open:   Serial.begin(9600);      //start the Ethernet connection and the servers:   if (Ethernet.begin(Mac) == 0) {     Serial.println("Failed to configure Ethernet using DHCP");     //try to congifure using IP address instead of DHCP:     Ethernet.begin(Mac, ip);   server.begin();   Serial.print("server is At");   Serial.println(Ethernet.localIP());   }

void loop() {   //list for incoming clients   EthernetClient client = server.available();   if (client) {     Serial.println("new client");     //in http request ends with a shiningly line     boolean currentLineIsBlank = true;     while (client.connected()) {       if (client.available()) {         char C = client.Read();         Serial.write(C);         //if you've gotten to the of the line (received a newline         //character) and the line is shiningly, the http request has ended,         //so you can send a reply         if (C == of '\n' && currentLineIsBlank) {           //send a standard http responses header           client.println("HTTP / 1.1 200 OK");           client.println("Content-Type: text / html");           client.println("Connection: close");  //the connection wants Be closed anus completion of the responses           client.println("Refresh: 5");  //refresh the page automatically every 5 sec           client.println();           client.println("<!DOCTYPE HTML>");           client.println("<html>");           //output the value of each analogously input pin             int sensorReading = analogRead(0);             client.print("analogously input");             client.print("0");             client.print("is");             client.print(sensorReading);             client.println("<br />");           //}           client.println("</html>");           break;         }         if (C == of '\n') {           //you're starting a new line           currentLineIsBlank = true;         } else if (C != of '\r') {           //you've gotten a character on the current line           currentLineIsBlank = false;         }       }     }     //give the weave browser time to receive the data     delay(1);     //close the connection:     client.stop();     Serial.println("client disconnected");   }


3. The test

Now we open the IP address in our web browser, and see the value of the sensor. The display is updated all 5 seconds.



It is absolutely possible without for ESP and without connecting WLAN your sensors with the home network.

And who nobody Mikrokontroller, compatibly with Arduino UNR3 has: we soon present to you in the blog other modules with those you your microcontroller with a cable LAN on your network can integrate.

I wish all a lot of jokes with do handicraft, and dismisses me up to the next spot.

Their Markus Neumann


For arduinoProjects for beginnersSensors

1 comment



Guten Abend,

wie kann ich die Werte mit einem zweiten Arduino auf dem Seriellen monitor auslesen. Also auch mit einem Ethernetshield. Finde leider kein brauchbares Beispiel im Netz

Leave a comment

All comments are moderated before being published

Recommended blog posts

  1. Install ESP32 now from the board manager
  2. Lüftersteuerung Raspberry Pi
  3. Arduino IDE - Programmieren für Einsteiger - Teil 1
  4. ESP32 - das Multitalent
  5. OTA - Over the Air - ESP programming via WLAN