Videotutorial – Arduino Ethernet LED Control

In this videotutorial I want to show you how to control a green LED from a web interface by using Arduino Ethernet Shield.

What we need?

1 KOhm resistor

1 Arduino Ethernet Shield

1 Green Led

This is the schematic of the project:

Schema_bb

 

This is the full code of the project:

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

byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
EthernetServer server(80);
int led = 4;

void setup() {
  pinMode(led, OUTPUT);
  Ethernet.begin(mac);
  server.begin();
  Serial.begin(9600);
  Serial.println("Server address:");
  Serial.println(Ethernet.localIP());
}

void loop() {
  EthernetClient client = server.available();
  if (client){
    boolean currentLineIsBlank = true;
    String buffer = "";  
    while (client.connected()){
      if (client.available()) {
        char c = client.read(); 
        buffer+=c;       
        if (c == '\n' && currentLineIsBlank) {
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();    
          client.print("<center><br><h1>Led Control</h1><br><br><br><FORM>");
          client.print("<P> <INPUT type=\"submit\" name=\"status\" value=\"Turn ON\">");
          client.print("<P> <INPUT type=\"submit\" name=\"status\" value=\"Turn OFF\">");
          client.print("</FORM></center>"); 
          break;
        }
        if (c == '\n') { 
          currentLineIsBlank = true;
          buffer="";       
        } 
        else 
          if (c == '\r') {     
          if(buffer.indexOf("GET /?status=Turn+ON")>=0)
            digitalWrite(led, HIGH);
          if(buffer.indexOf("GET /?status=Turn+OFF")>=0)
            digitalWrite(led, LOW);   
        }
        else {
          currentLineIsBlank = false;
        }  
      }
    }
    client.stop();
  }
}

 

 

2 thoughts on “Videotutorial – Arduino Ethernet LED Control”

  1. Hello!
    I upload the code the i open the serial monitor but nothing.
    Doesn’t writes to me the ip adres.
    Can you help me?

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.