Original source : http://malaysiascada.blogspot.kr/2011/06/memperkenalkan-arduino.html



This project is the W5100 Ethernet shield using a Web Server is a learning base examples.

Using a variable resistor, Aanlog value  is an example to check at Web.

Look at the photos below, A stack made Arduino UNO and W5100 Ethernet Shield, connected to the wire to the variable resistance.



<Written code>

#include 
#include 

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 10,34,248, 177 };
Server server(80);

void setup()
{
 Ethernet.begin(mac, ip);
  server.begin();
}
void loop()
{
  Client client = server.available();
  if (client) {
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        if (c == '\n' && currentLineIsBlank) {
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
          for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
            client.print("analog input ");
            client.print(analogChannel);
            client.print(" is ");
            client.print(analogRead(analogChannel));
            client.println("
"); } break; } if (c == '\n') { currentLineIsBlank = true; } else if (c != '\r') { currentLineIsBlank = false; } } } delay(1); client.stop(); } }


<Execution result>

analog input 0 is 464
analog input 1 is 423
analog input 2 is 880
analog input 3 is 769
analog input 4 is 693
analog input 5 is 673


If you're a beginner, this simple code can operate a Web Server. Try the challenge!!



+ Recent posts