I recently went out and bought an Arduino Ethernet Shield but couldnt really put it to use as i couldnt find any easy tutorials so i started to try to code by myself.I was able to come up with a simple section of code which turned on a LED from your internet broweser.Unfortunatly so far i have not been able to control the LED from outside of my home network.

Step 1: Parts

An Arduino
An Arduino Ethernet Shield
A Breadboard
Connecting Wires
An Ethernet cable 

Step 2: Initial Hardware Set Up

If you have one of the newer Arduino Ethernet Shields,it will come with the Mac Address writen on the back of it.
Write that down seperatly before attaching your Shield to the Arduino Board.

To set up,just plug in the header pins from the shield into your Arduino.

Use the ethernet cable to conect your Arduino Ethernet Shield to your Network via your Router.

Note that The Ethernet shield is attached to pins 10, 11, 12, 13 so those cannot be used.

Connect the Positive end of the LED on a breadboard and in turn to Pin 8 and the negative end of the LED to Ground on the Ethernet shield.

Step 3: Acquiring the Basic Info (MAC Address,IP Address,Port Number)

If you have one of the newer Shields it should come with the Mac adress written on the back.

The IP address will be dependent on your local network and to find that out you can use Comamnd Promt.
Open up command promt and type in "ipconfig"

It should then show you your IP Address,default gateway and your subnet mask

You will also need the port you want to use.Port 80 is default for HTTP but since my internet provider had it blocked i ended up using port 8081.

Step 4:

  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,20);
IPAddress gateway(192,168,1,1);
IPAddress subnet(255, 255, 255, 0);

// Initialize the Ethernet server library with the port you want to use.
EthernetServer server(8081);
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 = client.read();

        //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");


Step 5: Feedback

Try the steps and see if it works out if it doesnt work i will try to figure out what went wrong and do leaves comments so i can improve.
<p></p><p>Hi,</p><p>Iam new to arduino ,i tried executing the same code but iam not getting the gui page and the blink of led too.Can you please help me.I have put the screen shot of com3 too.</p>
<p>Hi,</p><p>nice instructable.</p><p>How could I access different arduinos via my ethernet? EG five arduinos, accessible from the web via port forwarded IP through my router - or would I have to use one arduino to route appropriate traffic to relevant arduinos?</p><p>Many thanks</p><p>D6</p>
<p>If you want to use an adress from &quot;the outside of your network&quot; you need to portforward your router. So you may ask yourself what is portforwarding? For example http servers uses port 80. In your house you have let's say 5 PCs, each with a different internal IP adress. The router needs to know where to transfer the info from port 80 because when you use the ip provided by the internet provider you contact the router not the arduino/pc. If you want to acces your arduino, you have to say the router to which computer he has to redirect that port. Something like: Internet -&gt; router -&gt; tell the router to send the information to arduino (portforward)-&gt;arduino. I never used a ethernet shield on my arduino and never dealt with ethernet on arduino, but I think that is your problem.</p>
<p>Hello everyone,</p><p>I am a beginner with Arduino, actually, I want to use an ethernet shield with Arduino. but there is one question my mind. </p><p>Can the ethernet shield attached with Arduino be used as OUTPUT to collect the data from sensors or always it only works as an INPUT for the internet connection?</p><p>Thank you in advance for your precious time.</p>
<p>Very nice! As a beginner, this taught me a lot. I reworked the code to control a SainSmart 8ch relay board with momentary and latching contacts over the web.</p>
<p>Hi MikeT14!</p><p>I am interested by your code. Could you share it with us?</p><p>Thank you!</p>
<p>This is what I use to this day and it works flawlessly for control of my home with my phone.</p>
<p>Dear Mike,</p><p>Thank you very much for your prompt answer!</p><p>This is very close to what I need! I have to change high by low and low by high because relay from my board turn ON with a 5 volts signal!</p><p>I will let you know if it works well, but not tomorrow, I am waiting for my Arduino board....I will normally receive it soon....</p><p>Thank you again to share your work, it will help me for sure!</p><p>Regards</p>
<p>very good, like I said this works perfectly for me. let me know your outcome! good luck!</p>
<p>OK, I will tell you as soon as I receive my arduino!</p>
<p> //----------------------------------------------------------------------------------------------<br>/*<br> A customized home automation web server to control burglar alarm and a few doors.<br> * Ethernet Shield attached to pins 10, 11, 12, 13 - DO NOT USE Shield pins!<br> * Much thanks to NIkheel94!<br> */<br> //----------------------------------------------------------------------------------------------<br> // Device Init.<br> #include &lt;SPI.h&gt;<br> #include &lt;Ethernet.h&gt;<br> boolean reading = false;</p><p> #define REQ_BUF_SZ 8</p><p> // MAC setting.<br> byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };</p><p> // IP setting.<br> IPAddress ip(127, 0, 0, 1);<br> IPAddress gateway(255, 255, 255, 0);<br> IPAddress subnet(127, 0, 0, 0);</p><p> // Server port init.<br> EthernetServer server(80);<br> String readString;<br> //----------------------------------------------------------------------------------------------<br> // Device Init.<br> void setup()<br> {<br> // Set digi. pins 02-09 to OUTPUTS and set pins HIGH to turn off relays:<br> pinMode(2, OUTPUT); // ~ Relay 1<br> pinMode(3, OUTPUT); // ~ Relay 2<br> pinMode(4, OUTPUT); // ~ Relay 3<br> pinMode(5, OUTPUT); // ~ Relay 4<br> pinMode(6, OUTPUT); // ~ Relay 5<br> pinMode(7, OUTPUT); // ~ Relay 6<br> pinMode(8, OUTPUT); // ~ Relay 7<br> pinMode(9, OUTPUT); // ~ Relay 8<br> //----------------------------------------------------------------------------------------------<br> digitalWrite(2, HIGH); // Pins set to HIGH to turn off relays<br> digitalWrite(3, HIGH); // ~<br> digitalWrite(4, HIGH); // ~<br> digitalWrite(5, HIGH); // ~<br> digitalWrite(6, HIGH); // ~<br> digitalWrite(7, HIGH); // ~<br> digitalWrite(8, HIGH); // ~<br> digitalWrite(9, HIGH); // ~ <br> //----------------------------------------------------------------------------------------------<br> // Start Ethernet<br> Ethernet.begin(mac, ip, gateway, subnet, dns);<br> server.begin();<br> delay(1000); // Give time to init.<br> }<br> //----------------------------------------------------------------------------------------------<br> // Main loop<br> void loop()<br> {<br> // Listen for incoming clients<br> EthernetClient client = server.available();<br> if (client)</p><p> boolean currentLineIsBlank = true;<br> boolean sentHeader = false;</p><p> {<br> while (client.connected())<br> {<br> if (client.available())<br> {<br> char c = client.read();</p><p> //read char. by char. HTTP request<br> if (readString.length() &lt; 250)<br> {<br> //store characters to string<br> readString += c;<br> if (c == '\n') <br> {<br> //----------------------------------------------------------------------------------------------<br> // Site Init:<br> client.println(&quot;HTTP/1.1 200 OK&quot;); //send new page<br> client.println(&quot;Content-Type: text/html&quot;);<br> client.println();<br> client.println(&quot;&lt;HTML&gt;&quot;);<br> client.println(&quot;&lt;HEAD&gt;&quot;);</p><p> //----------------------------------------------------------------------------------------------<br> // WEB txt:<br> client.println(&quot;&lt;TITLE&gt;awtomazzjoni&lt;/TITLE&gt;&quot;); // Basic HTML<br> client.println(&quot;&lt;center&gt;&quot;);<br> client.println(&quot;&lt;/HEAD&gt;&quot;);<br> client.println(&quot;&lt;BODY&gt;&quot;);<br> client.println(&quot;&lt;style&gt;&quot;);<br> client.println(&quot;body {background-color:darkgrey}&quot;);<br> client.println(&quot;h1 {color:blue}&quot;);<br> client.println(&quot;p {color:yellow}&quot;);<br> client.println(&quot;&lt;/style&gt;&quot;);<br> client.println(&quot;&lt;H1&gt;Remote Controls&lt;/H1&gt;&lt;hr /&gt;&quot;);<br> client.println(&quot;&lt;center&gt;&quot;);<br> client.println(&quot;&lt;p&gt;If you know the drill, make it happen.&lt;/p&gt;&lt;br /&gt;&quot;);<br> client.println(&quot;&lt;p&gt;Otherwise, you can leave this page by clicking below:&lt;/p&gt;&lt;br /&gt;&quot;);<br> client.println(&quot;&lt;a href=\&quot;https://www.google.com/\&quot;\&quot;&gt;Go to Google&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&quot;);<br> client.println(&quot;&lt;a href=\&quot;https://www.yahoo.com/\&quot;\&quot;&gt;Go to Yahoo!&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&quot;);<br> client.println(&quot;&lt;/BODY&gt;&quot;);<br> client.println(&quot;&lt;/HTML&gt;&quot;);</p><p> // Stop client<br> delay(250);<br> client.stop();<br> //----------------------------------------------------------------------------------------------<br> // Begin &quot;ALARM&quot; relay control:<br> if(readString.indexOf(&quot;?RELAY_1&quot;) &gt;0) // Momentarily Activate Relay 1 for 2.5 secs.<br> {<br> digitalWrite(2, LOW);<br> delay(2500);<br> digitalWrite(2, HIGH);<br> }<br> if(readString.indexOf(&quot;?RELAY_2&quot;) &gt;0) // Momentarily Activate Relay 2 for 2.5 secs.<br> {<br> digitalWrite(3, LOW);<br> delay(2500);<br> digitalWrite(3, HIGH);<br> }<br> if(readString.indexOf(&quot;?RELAY_3&quot;) &gt;0) // Momentarily Activate Relay 3 for 2.5 secs.<br> {<br> digitalWrite(4, LOW);<br> delay(2500);<br> digitalWrite(4, HIGH);<br> }<br> if(readString.indexOf(&quot;?RELAY_4&quot;) &gt;0) // Momentarily Activate Relay 4 for 2.5 secs.<br> {<br> digitalWrite(5, LOW);<br> delay(2500);<br> digitalWrite(5, HIGH);<br> }<br> if(readString.indexOf(&quot;?RELAY_5&quot;) &gt;0) // Momentarily Activate Relay 5 for 2.5 secs.<br> {<br> digitalWrite(6, LOW);<br> delay(2500);<br> digitalWrite(6, HIGH);<br> } <br> // Begin &quot;Door&quot; relay control: <br> if(readString.indexOf(&quot;?RELAY_6&quot;) &gt;0) // Momentarily Activate Relay 6 for 2.5 secs.<br> {<br> digitalWrite(7, LOW);<br> delay(2500);<br> digitalWrite(7, HIGH);<br> }<br> if(readString.indexOf(&quot;?RELAY_7&quot;) &gt;0) // Momentarily Activate Relay 7 for 2.5 secs.<br> {<br> digitalWrite(8, LOW);<br> delay(2500);<br> digitalWrite(8, HIGH);<br> }<br> if(readString.indexOf(&quot;?RELAY_8&quot;) &gt;0) // Momentarily Activate Relay 8 for 2.5 secs.<br> {<br> digitalWrite(9, LOW);<br> delay(2500);<br> digitalWrite(9, HIGH);<br> }<br> //----------------------------------------------------------------------------------------------<br> // Begin &quot;LATCHING&quot; relay control: <br> if(readString.indexOf(&quot;?LATCH_R1&quot;) &gt;0) // Latch Relay 1<br> {<br> digitalWrite(2, LOW);<br> }<br> // if(readString.indexOf(&quot;?LATCH_R2&quot;) &gt;0) // SPARE-Latching Uncomment to activate, dupe as needed<br> // {<br> // digitalWrite(X, LOW);<br> // }<br> // All latching reset<br> if(readString.indexOf(&quot;?RST_LATCH&quot;) &gt;0) // Checks LR activation VIA WEB<br> {<br> delay(1000);<br> digitalWrite(2, HIGH); // Resets all latching, turns off all relays<br> digitalWrite(3, HIGH); // ~<br> digitalWrite(4, HIGH); // ~<br> digitalWrite(5, HIGH); // ~<br> digitalWrite(6, HIGH); // ~<br> digitalWrite(7, HIGH); // ~<br> digitalWrite(8, HIGH); // ~<br> digitalWrite(9, HIGH); // ~<br> }<br> {<br> // clear string for next read<br> readString=&quot;&quot;;</p><p> // Give the web browser time to receive the data<br> delay(250); // close the connection:<br> readString=&quot;&quot;;<br> client.stop();<br> }<br> }<br> }<br> }<br> }<br> }<br> }<br> // END---------------------------------------------------------------------------------------END</p>
<p>Nice one Mate :)<br>I was planning on doing something similar, just haven't had a chance to get to it yet.<br></p>
<p>Got it working on Arduino Nano with UIPEthernet library! Thanks!</p><p><a href="https://twitter.com/Kaji_fi/status/688701859125678080" rel="nofollow">https://twitter.com/Kaji_fi/status/688701859125678...</a></p><p><a href="https://github.com/ntruchsess/arduino_uip" rel="nofollow">https://github.com/ntruchsess/arduino_uip</a></p>
<p>Hi,</p><p>I am having Arduino Uno board with me. Which ethernet shield is compatible with Arduino Uno?</p><p>Thanks.</p>
<p>Hi, </p><p>good tutorial, i found it very useful, however i was wondering could you write me a code example, so it could control 9 LED's?</p><p>Thank you.</p>
I want to know does i need to make server or webpage additionaly for controlling my led or i can access my led through this program only over the internet
<p>How to connect Independent 5 leds, please help me this is my project for school, Thanks</p>
<p>worked fine on win 7 with internet explorer 8.0.7601..... , but not on win 7 with chrome Version 42.0.2311.135 M</p><p>Strange - will look into it.</p>
<p>If i remember correctly when i tried it i think it worked on all browsers. <br>I dont remember the exact version i was using at the time.<br>Unfortunately this is not my field of expertise so i have no idea why it may not have worked.</p>
<p>Cool instructable! I added a resistor to the LED so I didn't fry it and added a motor for max effect. Now let's do something useful with it!</p>
<p>Cool stuff. Smart putting the resistor.<br>Yeah i forgot to add the resistor to mine. I was really exited and in rush to get it to work that i forgot about the resistor. Fail.</p>
<p>the question is , how can the arduino work as a MAC chip? </p>
<p>Hello AgentWolf :)<br><br>I have a few question to ask. Currently now I'm on my progress to finish up my final year bachelor degree project. My project title namely as, a web based controlling home equipment using Arduino.<br><br>So, may I know, the suitable programming language to develop my web based software? and the list of programming or library that I may used for my Arduino and my project.<br><br>:)</p>
<p>I am not an expert but only an enthusiast so i am not the best person to ask. I would suggest you do the research on your own because its better than me giving you the wrong information. I apologize in advance.<br><br>You can Use Just the Arduino language on its own as i did using the following libraries depending on what you want to achieve: </p><p><a href="http://arduino.cc/en/Reference/Ethernet" rel="nofollow">Ethernet</a> - for connecting to the internet using the Arduino Ethernet Shield</p><p><a href="http://arduino.cc/en/Reference/WiFi" rel="nofollow">WiFi</a> - for connecting to the internet using the Arduino WiFi shield</p><p><a href="http://arduino.cc/en/Reference/LiquidCrystal" rel="nofollow">LiquidCrystal</a> - for controlling liquid crystal displays (LCDs)</p><p><a href="http://arduino.cc/en/Reference/Servo" rel="nofollow">Servo</a> - for controlling servo motors</p><p><a href="http://arduino.cc/en/Reference/Stepper" rel="nofollow">Stepper</a> - for controlling stepper motors</p><p>Best Place of Reference would be the Arduino Website and Github and other similar projects. I have seen alot of people use Python and HTML in conjunction with the Arduino Platform.</p><p>You can take what i have and edit/add on to it to fit your needs. You can change the code for the LED section to work with Relays.<br><br>Once again my apologies. Good Luck.</p>
Nice job! <br>Have been tinkering with a similar project that lets you control relays in the same manner if you want this to work over the internet you have to route the port you are using to the arduinos local IP address. I have a dlink router and use the virtual server section to map the public port comming from the internet to my arduino's local ip and port (can use the same or different ports, i use the same to make it simpler). <br>Do bear in mind that anyone in the world could potentially have access to it tho as there's no authentication portal to keep out unwanted guests. <br> <br>To answer the question from yyyazj, yes chrome or any other web browser becomes the client
Thanks for you input and answering that Question. <br>I am currently busy with school so i haven't had the chance to experiment with Relays but i did think about tinkering with it.I am planning it out in my head and i just need to implement it.As for controlling it from outside my network i have failed to make it work.I just need to keep trying till i finally get it. <br> <br>
I have a question, because the Arduino is working as the websever, so everytime we open the Chrome, and type the IP and the port of Arduino, is the time we use the Chrome as the client ? Right?
Nice instructable!test it and works great!thumbs up!
Thanks. <br>Glad it worked.
To have it controlled form the outside you have to open a port on your router. Not recommended unless you really know what you are doing. You may want to add a resistor in series with the led for safety reasons on your Arduino. <br> <br>The code obviously took some to to prepare. Must have been a big job for you.
Thanks. <br>I dont know if its bad but for a &quot;Noob&quot; it took me about a Month to figure everything out and understand what i was doing and finally have it working. <br>I tired to open up a port and have it work from the outside but unfortunately failed to do so.Thanks for the tip i will keep the resistor in mind for next time.

About This Instructable




More by NIkheel94:Streaming the Xbox 360 to Twitch using an older VGA/DVI PC Monitor with Seperate Sound (Monitor Without Speakers) Easy Basic Arduino Ethernet Controller Most Basic Form of Hydroponics 
Add instructable to: