Example Webserver Arduino


I'm trying to communicate Arduino UNO+Ethernet Shield with internet. I have began with Webserver example include in Arduino IDE, but when i type internet said thai it cannot connect. I checked before 105 is free.I don`t know if maybe i need to open some port in my router.

Thank you.


Put up your code.

The IP address you use must be compatible with (in the same range) as others on your lan but unique.

Then your code needs to instantiate an ethernetclient object when the incoming URL request is detected by the Ethernet shield.

You should be able to use any port but will need a unique port if you want to access the arduino system from the outside world through a router.

Use the serial monitor for debugging.


Catweazle NZ

Have you tried in your browser?

Thank you for your answers. Yes I’have tried with 105 but it still doesn’t work

I have set the router with the following actions:

1º Asign ip direction the MAC is type in arduino sketch (I attach picture)
2º Open ports 80 and 5400 for ip direction (I attach picture)

I know it doesn’t work for man reasons:

1ª in ms-dos i type ipconfig and it said me ítems disconnected (I attach picture)
2º I have tried with ipscan and position 177 is free (I attach picture)
3º When i open serial monitor it doen’t show me nothing
ON led in Ethernet shield is ON (Green)


100 is Green
LINK is orange aldo FDX


ACT sometimes is Green other time is switch off.

the code i’m using

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

// Configuración de direccion MAC e IP.
byte mac = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,177);

// Inicia la libreria Ethernet server con el puerto 80 (por defecto el puerto HTTP).
EthernetServer server(5400);

void setup() {
// Inicia el puerto serie.

// Inicia la conexión Ethernet y el servidor.
Ethernet.begin(mac, ip);
Serial.print("IP local del servidor ");

void loop() {
EthernetClient client = server.available(); // Escucha a los clientes entrantes.
if (client) { // Si un cliente se conecta al servidor:
Serial.println(“Nuevo cliente”);
boolean currentLineIsBlank = true; // Marcador para enviar la respuesta desde el servidor.
while (client.connected()) { // Repite mientas existe clientes conectados:
if (client.available()) {
char c = client.read();
Serial.write(c); // Imprime por el puerto serie la petición del cliente (caracter a caracter)
if (c == ‘\n’ && currentLineIsBlank) { // Se envia la respuesta a una petición de un cliente cuando a finalizado la petición:
// Respuesta:
client.println(“HTTP/1.1 200 OK”); // Enviar un encabezado de respuesta HTTP estándar
client.println(“Content-Type: text/html”);
client.println(“Connection: close”); // Se cerrará la conexiós despues de enviar la respuesta.
client.println(“Refresh: 5”); // Refrescar automáticamente la página después de 5 segundos.
client.println(""); // Tipo de documento.
client.println(""); // Etiqueta html inicio del documento.
client.print("Hola soy Arduino!! - ");
client.print(millis()); // Tiempo de funcionamiento en ms.
client.print(“ms encendido. “);
“); // Etiqueta html salto de linea.
client.println(””); // Etiqueta html fin del documento.
if (c == ‘\n’) { // Si el caracter es un salto de linea:
currentLineIsBlank = true; // La petición a terminado, se respondera a dicha peticón en el sigueitne ciclo.
else if (c != ‘\r’) { // Si el caracter no es un retorno de carro (la petición no a terminado).
currentLineIsBlank = false; // Seguimos escuchando la petición.
delay(1); // Espera para dar tiempo al navegador a recivir los datos.
client.stop(); // Cierra la conexión.
Serial.println(“Cliente desconectado”);



Simple server code you might try. Also #7 below:


//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 = client.read();

        //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


Hello zoomkat

I've tried with you code but I still doesn't work. I have gone backwards and I tried just the example IDE Websever, I changed IP addres but when I type 192.168.0.number browser said error. I've tried with same manual to know if arduino es connect properly with serial monitor but when i checked it is empty.


but when I type 192.168.0.number browser said error

Reply #2?

Sorry typed as is typed in scketch

The point I'm trying to make is that you may need to precede the IP address with http:// for the url to work in a browser. Try clicking the below link and see if the page loads.

If you are using zoomkat's example above, he uses port 84, not 80.

You were using port 5400 in your code.