Introduction: Arduino Led Server

A  simple webpage to control your 8 leds.


What you need:
Arduino.
Ethernet shield.
8 x leds.
8 x 1k resistors.
1 x jumper cable.

Comments

author
MohammedT59 made it! (author)2017-05-05

hi .. code not work ??

can you help me !!

I use:

arduino Uno

Ethernet Module

WhatsApp Image 2017-05-05 at 11.49.21 PM.jpeg
author
Computothought (author)2015-05-09

You only show 7 leds instead of eight. I only could get lines 2-7 to work.

author
Computothought (author)2015-05-09

Have not tested the electronics part of it yet, but did a little window dressing to make it easier for me to read.

Screenshot from 2015-05-09 19:00:44.png
author
JohnC20 made it! (author)2015-04-21

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.

LED Server.jpg
author
Fearce1 (author)2014-07-27

I've made this and noticed something... The pins and their respectful outputs don't match up, so after a few "TWEAKS" I've fixed it to work for me.

Here is the changed code below:

#include <Ethernet.h>

#include <SPI.h>

//network NB: Pins 10, 11, 12 and 13 are reserved for Ethernet module.

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

byte ip[] = { 192, 168, 2, 200 };

byte gateway[] = { 192, 168, 1, 1 };

byte subnet[] = { 255, 255, 255, 0 };

String inString = String(35);

String Led;

int led[] = {00, 1, 2, 3, 4, 5, 6, 7, }; //Led pins num 0 in arry is not used

int numofleds = 8; //numofleds

String value[] = {"on","on","on","on","on","on","on","on","on"}; //startup all led are off

EthernetServer server(80);

String data;

void setup()

{

Serial.begin(9600);

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

server.begin();

//set pin mode

for (int j = 0; j < (numofleds + 1); j++){

pinMode(led[j], OUTPUT);

}

Serial.println("Serial READY");

Serial.println("Ethernet READY");

Serial.println("Server READY");

}

void loop()

{

EthernetClient client = server.available();

if(client){

// an http request ends with a blank line

boolean current_line_is_blank = true;

while (client.connected()) {

if(client.available()) {

char c = client.read();

// if we've gotten to the end of the line (received a newline

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

// so we can send a reply

if (inString.length() < 35) {

inString.concat(c);

}

if (c == '\n' && current_line_is_blank) {

// send a standard http response header

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

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

client.println();

client.println("<html><body><form method=get>");

client.println("<p>Led controller</p>");

for(int i=1;i < (numofleds + 1) ;i++){

Led = String("led") + i;

if(inString.indexOf(Led+"=on")>0 || inString.indexOf("all=on")>0){

Serial.println(Led+"on");

digitalWrite(led[i], HIGH);

value[i] = "off";

}else if(inString.indexOf(Led+"=off")>0 || inString.indexOf("all=off")>0 ){

Serial.println(Led+"on");

digitalWrite(led[i], LOW);

value[i] = "on";

}

client.println("<br>"+Led+" <input type=submit name="+Led+" value="+value[i]+">");

}

client.println("<br>All <input type=submit name=all value=on><input type=submit name=all value=off>");

client.println("</form>r<html></body>");

break;

}

if (c == '\n') {

// we're starting a new line

current_line_is_blank = true;

} else if (c != '\r') {

// we've gotten a character on the current line

current_line_is_blank = false;

}

}

}

// give the web browser time to receive the data

delay(10);

inString = "";

client.stop();

}

}

author
teqmo (author)Fearce12014-08-04

For some reason its got a " r" at the end of the page any ideas?

author
Fearce1 (author)teqmo2014-09-06

The line of code that cantains the invalid "r" is as follows

client.println("</form>r<html></body>");

Just find and remove the "r" in your copy of the code and it shouldn't be displayed anymore.

A simple typo was all it was.

author
alexm313 (author)2014-03-02

Good job, i want to use relay for lamps, the code working? Or must to do something else with the code? Thanks in advance!

author
cheesecurd1899 (author)2014-02-18

Would there be a way to eliminate the Ethernet cable and do this over wifi?

author
bboudreau (author)2012-08-17

Nicely done.

About This Instructable

16,592views

40favorites

License:

More by drphill:Arduino Led Server
Add instructable to: