A  simple webpage to control your 8 leds.

What you need:
Ethernet shield.
8 x leds.
8 x 1k resistors.
1 x jumper cable.
<p>hi .. code not work ??</p><p>can you help me !! </p><p>I use:</p><p> arduino Uno</p><p>Ethernet Module</p>
<p>You only show 7 leds instead of eight. I only could get lines 2-7 to work.</p>
<p>Have not tested the electronics part of it yet, but did a little window dressing to make it easier for me to read.</p>
<p>Now it should be noted that the diagram for LEDs is reversed. the Anode is tie to ground making the LEDs not light. Tie the Anodes to 5v or 3.3v and it will work. BUT the webpage display would be wrong. If the Cathodes were tied to ground then all works as shown. </p>
<p>I've made this and noticed something... The pins and their respectful outputs don't match up, so after a few &quot;TWEAKS&quot; I've fixed it to work for me.</p><p>Here is the changed code below:</p><p>#include &lt;Ethernet.h&gt;</p><p>#include &lt;SPI.h&gt;</p><p>//network NB: Pins 10, 11, 12 and 13 are reserved for Ethernet module. </p><p>byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };</p><p>byte ip[] = { 192, 168, 2, 200 }; </p><p>byte gateway[] = { 192, 168, 1, 1 };</p><p>byte subnet[] = { 255, 255, 255, 0 };</p><p>String inString = String(35);</p><p>String Led;</p><p><strong><em>int led[] = {00, 1, 2, 3, 4, 5, 6, 7, }; //Led pins num 0 in arry is not used</em></strong></p><p>int numofleds = 8; //numofleds</p><p>String value[] = {&quot;on&quot;,&quot;on&quot;,&quot;on&quot;,&quot;on&quot;,&quot;on&quot;,&quot;on&quot;,&quot;on&quot;,&quot;on&quot;,&quot;on&quot;}; //startup all led are off</p><p>EthernetServer server(80);</p><p>String data;</p><p>void setup()</p><p>{</p><p> Serial.begin(9600);</p><p> Ethernet.begin(mac, ip,gateway,subnet); </p><p> server.begin();</p><p> //set pin mode</p><p> for (<strong><em>int j = 0;</em></strong> j &lt; (numofleds + 1); j++){</p><p> pinMode(led[j], OUTPUT);</p><p> }</p><p> Serial.println(&quot;Serial READY&quot;);</p><p> Serial.println(&quot;Ethernet READY&quot;);</p><p> Serial.println(&quot;Server READY&quot;);</p><p>}</p><p>void loop()</p><p>{</p><p> EthernetClient client = server.available();</p><p> if(client){</p><p> // an http request ends with a blank line</p><p> boolean current_line_is_blank = true;</p><p> while (client.connected()) {</p><p> if(client.available()) {</p><p> char c = client.read();</p><p> // if we've gotten to the end of the line (received a newline</p><p> // character) and the line is blank, the http request has ended,</p><p> // so we can send a reply</p><p> if (inString.length() &lt; 35) {</p><p> inString.concat(c);</p><p> } </p><p> if (c == '\n' &amp;&amp; current_line_is_blank) {</p><p> // send a standard http response header</p><p> client.println(&quot;HTTP/1.1 200 OK&quot;);</p><p> client.println(&quot;Content-Type: text/html&quot;);</p><p> client.println();</p><p> client.println(&quot;&lt;html&gt;&lt;body&gt;&lt;form method=get&gt;&quot;);</p><p> client.println(&quot;&lt;p&gt;Led controller&lt;/p&gt;&quot;);</p><p> for(int i=1;i &lt; (numofleds + 1) ;i++){ </p><p> Led = String(&quot;led&quot;) + i;</p><p> if(inString.indexOf(Led+&quot;=on&quot;)&gt;0 || inString.indexOf(&quot;all=on&quot;)&gt;0){</p><p> Serial.println(Led+&quot;on&quot;);</p><p> digitalWrite(led[i], HIGH);</p><p> value[i] = &quot;off&quot;; </p><p> }else if(inString.indexOf(Led+&quot;=off&quot;)&gt;0 || inString.indexOf(&quot;all=off&quot;)&gt;0 ){ </p><p> Serial.println(Led+&quot;on&quot;);</p><p> digitalWrite(led[i], LOW);</p><p> value[i] = &quot;on&quot;;</p><p> }</p><p> client.println(&quot;&lt;br&gt;&quot;+Led+&quot; &lt;input type=submit name=&quot;+Led+&quot; value=&quot;+value[i]+&quot;&gt;&quot;);</p><p> }</p><p> client.println(&quot;&lt;br&gt;All &lt;input type=submit name=all value=on&gt;&lt;input type=submit name=all value=off&gt;&quot;);</p><p> client.println(&quot;&lt;/form&gt;r&lt;html&gt;&lt;/body&gt;&quot;);</p><p> break;</p><p> }</p><p> if (c == '\n') {</p><p> // we're starting a new line</p><p> current_line_is_blank = true;</p><p> } else if (c != '\r') {</p><p> // we've gotten a character on the current line</p><p> current_line_is_blank = false;</p><p> }</p><p> }</p><p> }</p><p> // give the web browser time to receive the data</p><p> delay(10);</p><p> inString = &quot;&quot;;</p><p> client.stop();</p><p> }</p><p>}</p>
<p>For some reason its got a &quot; r&quot; at the end of the page any ideas?</p>
<p>The line of code that cantains the invalid &quot;r&quot; is as follows </p><p>client.println(&quot;&lt;/form&gt;<strong>r</strong>&lt;html&gt;&lt;/body&gt;&quot;);</p><p>Just find and remove the &quot;r&quot; in your copy of the code and it shouldn't be displayed anymore.</p><p>A simple typo was all it was. </p>
<p>Good job, i want to use relay for lamps, the code working? Or must to do something else with the code? Thanks in advance! </p>
<p>Would there be a way to eliminate the Ethernet cable and do this over wifi?</p>
Nicely done.

About This Instructable




More by drphill:Arduino Led Server 
Add instructable to: