I thought I would share a cludge I put together to read all the analog pins and then output them to a browser page. I made this to make it easier to read multiple analog signals and to easily display them without the use of an LCD (which I only have a 16x2).
This uses the ethernet shield to set up a port 80 web page. Its curently configured to use DHCP but its easy to mod the code to a fixed IP. I modded and stripped down the example baromenter read script. The output page lists all 6 analog inputs in numeric as well as a bargraph next to it for an easy visual representation of the inputs.
/*
Analog Sensor Display
This script estabilishes a simple HTML server on port 80.
When hit with a browser, it will display the analog readings
of all 6 Analog ports.
The page sends a refresh meta tag so the page will continually refresh.
Adapted from the BarometricPressureWebServer Example Script
Circuit:
Any sensors properly wired to A0-A5
created Jun 3 2012
by Mike Audleman
*/
#include <Ethernet.h>
// the sensor communicates using SPI, so include the library:
#include <SPI.h>
// assign a MAC address for the ethernet controller.
// fill in your address here:
byte mac[] = {
0x31, 0x13, 0x31, 0x13, 0x31, 0x13 };
// Going to use DHCP so don't set all the IPs
// assign an IP address for the controller:
//IPAddress ip(192,168,1,20);
//IPAddress gateway(192,168,1,1);
//IPAddress subnet(255, 255, 255, 0);
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
void setup() {
// start the SPI library:
SPI.begin();
Serial.begin(9600);
// start the Ethernet connection and the server:
Ethernet.begin(mac);
Serial.print("My IP address: ");
for (byte thisByte = 0; thisByte < 4; thisByte++) {
// print the value of each byte of the IP address:
Serial.print(Ethernet.localIP()[thisByte], DEC);
Serial.print(".");
}
Serial.println();
server.begin();
// startup delay:
delay(1000);
}
void loop() {
// listen for incoming Ethernet connections:
listenForEthernetClients();
}
void listenForEthernetClients() {
String outString;
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
Serial.println("Got a client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
// Send header and title
client.println("<html><head>");
client.println("<meta http-equiv='refresh' content='0'> ");
client.println("<title>Arduino Analog Read</title></head><body>");
// Send the reading of each of the 6 analog ports.
for (int i = 0; i <= 5; i++) {
int PortRead = analogRead( i );
client.print("<table border=0><tbody><tr>");
client.print("<th width=10>A" + String(i) +"</th>");
client.print("<td width=30 align=right>" + String(PortRead) + "</td>" );
client.print("<td width=" + String(PortRead/2) + " BGCOLOR=black></td>");
client.println("</tr></tbody></table>
");
}
// Send the footer
client.println("</body></html>");
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
}
}
If you don't set the IPs, upload the sketch and start the serial monitor. It will display the IP address of the board. Copy that and drop it in your browser URL bar on your PC. Poof, you got an instant analog read page that refreshes constantly.
I am attaching a screenshot of Firefox displaying the page.
Enjoy.
Wolfie
[edit] Correct typo in the meta tag for double quotes. Replaced with single quotes.