Arduino as a webserver, pure HTML

So, how can you get a webpage like this showing the values of the analog inputs of your Arduino?

Well, of course you need the Ethernet shield with the SD card socket.

It can be done easily by the use of the "HR" tag of HTML (horizontal rule). You can provide length, width, color and the noshade option and it takes you only a few lines of code.
Look for the value assignment of the color variable to see how the colors are produced.
The sketch uses 28,320 bytes so it would run on an Arduino UNO, but if you want to add any code you better go for the ATmega2560. (On the UNO, you have to use pin 10 instead of pin 53 to access the SD card.)

#define FILENAME "Webserver7"
/* see: 
Arduino Cookbook by Michael Margolis 
15.6 Setting Up an Arduino to Be a Web Server (p. 511)
tested 24.9.14 with SD card: o.k.
Web Server
A simple web server that shows the values of the analog input pins.
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
char outBuf[128]; // global, written to in eRcv, in this unit only read
byte by[6];
byte mac[4]; 

int port = 80;
EthernetServer server(port);
File fh;
int count = 0;

void setup() {

  pinMode(53, OUTPUT); // the Pin on the ATmega2560 / ATmega1280
  digitalWrite(53, HIGH);
  if (SD.begin(4) == 0) { Serial.println("Error-SD"); } 
  String temp; 
  fh ="config.txt");  
  if (!fh) return;
  temp = getValue(fh,"mac");
  // set my IP address:
  temp = getValue(fh,"ip");
  IPAddress ip(by[0],by[1],by[2],by[3]);
  printIPaddress("IP address: ");
  // set the gateway IP address:
  temp = getValue(fh,"gateway");
  IPAddress gateway(by[0],by[1],by[2],by[3]);
  printIPaddress("Gateway address: ");
  // set the subnet IP address:
  temp = getValue(fh,"subnet");
  IPAddress subnet(by[0],by[1],by[2],by[3]);
  printIPaddress("Subnet address: ");

  Ethernet.begin(mac, ip);
  Serial.println("Server started ");

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 =;
        // 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 (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();                          // <- this line is essential!
          client.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"\">");
          client.print("<meta http-equiv=\"refresh\" content=\"2; URL=http://");
          client.println("<body bgcolor=#999999>");          
          // output the value of each analog input pin:
          client.println("<p> request no: ");
          client.println("<table border=1 width=100%>");
          client.print("<colgroup> ");
          client.print("<col width=10> ");
          client.print("<col width=20> ");
          client.println("</colgroup> ");
          for (int i = 0; i < 6; i++) {
            client.print("<tr> <td>");
            client.print("</td> <td>");
            int x = analogRead(i);
            client.print("</td> <td> <hr color=#");
            long color = 0x1FFF0000 >> (3*i); 
            color = color & 0xffffff;
            if (color < 0x100000) client.print("0");
            if (color < 0x10000) client.print("0");
            client.print(" noshade align=left size=20 width=");
            client.print(100L * x / 1024);
            client.println("%> </td> </tr>");
        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

// get value from the config file
String getValue(File f, String s1) {
  // sequential search for string s1 in file f
  // returns the rest behind "="
  boolean EOL = !f.available();
  boolean found = false;
  String s2;;
  while (!found) {
    while (!EOL) {
      char c =;
      if (c != '\n') s2.concat(c); else EOL = true;
    EOL = false;
    if (s2.startsWith(s1)) {
      found = true;
      if (found) {
        int p = s1.length();
        s2 = s2.substring(p+1); // start behind "=" 
        s2.trim(); // cut CR/LF 
        return s2;
    } else s2 = "";

// copies bytes from a string to the global array by[]
void string2bytes(String s) { //, byte n) {
  s.toCharArray(outBuf, s.length()+1);
  char *tStr = strtok(outBuf,",");
  // these numbers will be coied into by[]:
  int i = 0;
  while (tStr != NULL) {
    by[i] = atoi(tStr);
    tStr = strtok(NULL,",");

// dump the data found on the  SD card
void printIPaddress(String name) {
  for (int i = 0; i < 3; i++) {
  } Serial.println(by[3]);

Don't forget to insert an SD card (the smallest one you can get) containing a "config.txt" file with the data of your network, looking something like this:

; data of the Arduino:
; data of the LAN:
; end

contact: nji(at)