Go Down

Topic: Web browser control (Read 2667 times) previous topic - next topic


I'm new to Arduino, although I have experience with industrial and marine automation and control. Also a bit of Pascal background.

My problem is simple, I have connected my arduino to my network with the ethernet shield and used the examples to view the data in a web browser, etc. I want to toggle a LED from my web browser, just put it on and off, but my lack of programming knowledge makes this extremely difficult! I have searched for examples but find them difficult to understand.

Thanks in advance for any help! (details please....Thanks again :-[)


Not sure what you are specifically asking for here.
Have you got an example code that does this?
Most Ethernet shields do come with one that will toggle an LED from a web browser.
Best bet is if you get some code, post it or post a link to it and say what you don't understand about it or ask if someone can modify it to do ... what ever you want.


Nov 04, 2010, 12:59 pm Last Edit: Nov 04, 2010, 02:02 pm by edenlgx Reason: 1
My apologies, here is the code from an example I use. I have slightly modified it to display an input box with a send button. If the input box contains the character "1", and the send button is pressed, the LED on my PIN 9 should switch on. I just don't know how to "read" the character in the input box.

Code: [Select]

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

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 10,200,1,245 };

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
Server server(80);

void setup()
 // start the Ethernet connection and the server:
 Ethernet.begin(mac, ip);

void loop()
 // listen for incoming clients
 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 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("<TD><NOBR>Digital State: <INPUT NAME=""digitalin"" SIZE=4></NOBR></TD>");
client.println("<TD><INPUT TYPE=BUTTON OnClick=""digitalin(this.form);"" VALUE=""Send""></TD>");

         // output the value of each analog input pin
         for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
           client.print("analog input ");
           client.print(" is ");
           client.println("<br />");
       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
   // close the connection:

Thanks for the reply


Could you edit your post and put the code inside [ code]code here[ /code] tags? (minus the space, obviously)

Also, what ethernet shield do you use? there are 3 floating around to my knowledge, one easier than the other.


I use the Arduino ETHShield SD


Hi Edenlgx,
I have been thinking about this as well - I can't decide whether I need to configure the Arduino as a client or a server. I wanted the page to be in synch with the Arduino - so LED on - page button on - I guess the Arduino would have to serve a different page depending on it's state
Any thoughts?


The difference between client and server is easy...

If you want to ask it about things -> server
If you want it to ask something from something else -> client

Though there are plenty of projects conceivable that would use both methods (they are combineable).
As for ethernet shield, perhaps a link to the product will be more helpful.
I myself have a DFRobot ethernet shield, which uses the wiz5100 chip, there are two other variants that use cheaper chips.. which use a different library than the default one shipped with the IDE.


Link to the Shield I use


Go Up