Arduino Relay Web Control

I have been researching Arduino Relay web control and have found a lot of info on the topic. However, I have noticed that there is a lot of out dated code being used that will not compile on newer versions of Arduino IDE. I have mainly been looking into this thread: http://forum.arduino.cc/index.php?topic=20862.0.

I have come here the ask for help in updating this code as it seems to be producing a lot of error messages.

Arduino

#include <WString.h>
#include <Ethernet.h>

byte mac[] = { 0x00, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 2, 150 };
Server server(80);
String readString = String(30);

void setup(){
 Serial.begin(9600);
 Ethernet.begin(mac, ip);
 pinMode(3, OUTPUT); digitalWrite(3, LOW); // led 1
 pinMode(4, OUTPUT); digitalWrite(4, LOW); // used as a ground
 pinMode(8, OUTPUT); digitalWrite(8, LOW); // led 2
 pinMode(9, OUTPUT); digitalWrite(9, LOW); // used as a ground
}

void loop(){
 Client client = server.available();
 if (client) {
   while (client.connected()) {
     if (client.available()) {
       char c = client.read();
       if (readString.length() < 100){
         readString.append(c);
       }
       if (c == '\n') {
       
            if(readString.contains("led8")) {
              toggle(8);
            } else
            if(readString.contains("led3")) {
              toggle(3);
            }
            client.println("<html><center>");
            client.println("Light 3
");
            if (digitalRead(3) == LOW){
              client.println("<img src='http://192.168.2.9/images/lightoff.png'>");
            } else if (digitalRead(3) == HIGH){
              client.println("<img src='http://192.168.2.9/images/lighton.png'>");
            }
            client.println("<form method='get'><input type=submit name=led3 value=toggle></form>");
            
            client.println("Light 8
");
            if (digitalRead(8) == LOW){
              client.println("<img src='http://192.168.2.9/images/lightoff.png'>");
            } else if (digitalRead(8) == HIGH){
              client.println("<img src='http://192.168.2.9/images/lighton.png'>");
            }
            client.println("<form method='get'><input type=submit name=led8 value=toggle></form>");
            client.println("</center></html>");
         readString="";
         client.stop();
       }
     }
   }
 }
}

int toggle(int pin){
 if(digitalRead(pin) == LOW){
   digitalWrite(pin, HIGH);
 } else {
   digitalWrite(pin, LOW);
 }
}
// EOF *******************************

PHP

<html>
<head>
<title>Home Automation Control Panel (SaSaa version: 0.01)</title>
<script type="text/JavaScript" src="scripts/jquery.js"></script>
<script type="text/JavaScript" src="scripts/js/jquery-ui-1.8.2.custom.min.js"></script>
<link type="text/css" href="scripts/css/start/jquery-ui-1.8.2.custom.css" rel="stylesheet" />
<script type="text/javascript"> 
     //accordion code set to mouseover and no autoheight
     $(function() {
           $("#accordion").accordion({
                 event: "mouseover",
                 autoHeight: false
           });
     });
</script>
</head>
<body BGcolor='grey'>
<div id=accordion style="width:250px;">
<h3><a href="#">Lights</a></h3>
<div bgcolor='grey'>
<iframe width='150' height='350' allowtransparency=true frameborder=0 scrolling=none  src="http://192.168.2.150"></iframe>
</div>
<h3><a href="#">Locks</a></h3>
<div>
N/A
</div>
<h3><a href="#">A/C</a></h3>
<div>
N/A
</div>
</div>

!Best viewed in Firefox!

</body>
</html>

I have already tried my hand at making some adjustments from reading around on the web. I am unsure if my changes are actually helping, however.

#define RELAY1  1                        
#define RELAY2  2                        
#define RELAY3  3                        
#define RELAY4  4
#define RELAY5  5                        
#define RELAY6  6                        
#define RELAY7  7                        
#define RELAY8  8

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


byte mac[] = { 0x00, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 31 };
Server server(80);
String readString = String(30);

 
void setup()
{    
// Initialise the Arduino data pins for OUTPUT
 Serial.begin(9600);
 Ethernet.begin(mac, ip);
 pinMode(RELAY1, OUTPUT); digitalWrite(1,LOW);      
 pinMode(RELAY2, OUTPUT); digitalWrite(2,LOW);
 pinMode(RELAY3, OUTPUT); digitalWrite(3,LOW);
 pinMode(RELAY4, OUTPUT); digitalWrite(4,LOW);
 pinMode(RELAY5, OUTPUT); digitalWrite(5,LOW);       
 pinMode(RELAY6, OUTPUT); digitalWrite(6,LOW);
 pinMode(RELAY7, OUTPUT); digitalWrite(7,LOW);
 pinMode(RELAY8, OUTPUT); digitalWrite(8,LOW);
}


void loop(){
 Client client = server.available();
 if (client) {
   while (client.connected()) {
     if (client.available()) {
       char c = client.read();
       if (readString.length() < 100){
         readString.concat(c);
       }
       if (c == '\n') {
       
            if(readString.indexOf("led8")) {
              toggle(RELAY8);

            } else
            if(readString.indexOf("led3")) {            
              toggle(RELAY3);
            }
            client.println("<html><center>");
            client.println("Light 3
");
            if (digitalRead(3) == LOW){
              client.println("<img src='http://192.168.2.9/images/lightoff.png'>");
            } else if (digitalRead(3) == HIGH){
              client.println("<img src='http://192.168.2.9/images/lighton.png'>");
            }
            client.println("<form method='get'><input type=submit name=led3 value=toggle></form>");
            
            client.println("Light 8
");
            if (digitalRead(8) == LOW){
              client.println("<img src='http://192.168.2.9/images/lightoff.png'>");
            } else if (digitalRead(8) == HIGH){
              client.println("<img src='http://192.168.2.9/images/lighton.png'>");
            }
            client.println("<form method='get'><input type=submit name=led8 value=toggle></form>");
            client.println("</center></html>");
         readString="";
         client.stop();
       }
     }
   }
 }
}

int toggle(int pin){
 if(digitalRead(pin) == LOW){
   digitalWrite(pin, HIGH);
 } else {
   digitalWrite(pin, LOW);
 }
}
// EOF *******************************

I am sorry if I am not following correct forum posting rules or if I am posting this in the wrong place as this is my first post on this website.

Thank you in advance.

String readString = String(30);

Pure crap. You do NOT need to piss away resources on the String class. You most certainly do NOT need to initialize readString to “30”. That makes no f**king sense.

 pinMode(3, OUTPUT); digitalWrite(3, LOW); // led 1

ONE statement per line, if you expect anyone to read your code.

I have come here the ask for help in updating this code as it seems to be producing a lot of error messages.

But you elected not to share them. Well, I’m electing not to share the answers I wrote down, either.

But, some clues. Putting a relay on the hardware serial pin is not something that will prove reasonable.

Thank you for the response,

this is the error code I am receiving when I run the original code

Arduino: 1.6.3 (Mac OS X), Board: "Arduino Uno"

Build options changed, rebuilding all
sketch_may11a.ino:6:17: error: no matching function for call to 'Server::Server(int)'
sketch_may11a.ino:6:17: note: candidates are:
In file included from /Applications/Arduino.app/Contents/Java/libraries/Ethernet/src/EthernetServer.h:4:0,
                 from /Applications/Arduino.app/Contents/Java/libraries/Ethernet/src/Ethernet.h:8,
                 from sketch_may11a.ino:2:
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Server.h:25:7: note: Server::Server()
 class Server : public Print {
       ^
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Server.h:25:7: note:   candidate expects 0 arguments, 1 provided
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Server.h:25:7: note: Server::Server(const Server&)
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Server.h:25:7: note:   no known conversion for argument 1 from 'int' to 'const Server&'
sketch_may11a.ino:6:8: error: cannot declare variable 'server' to be of abstract type 'Server'
In file included from /Applications/Arduino.app/Contents/Java/libraries/Ethernet/src/EthernetServer.h:4:0,
                 from /Applications/Arduino.app/Contents/Java/libraries/Ethernet/src/Ethernet.h:8,
                 from sketch_may11a.ino:2:
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Server.h:25:7: note:   because the following virtual functions are pure within 'Server':
 class Server : public Print {
       ^
In file included from /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Stream.h:26:0,
                 from /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/HardwareSerial.h:29,
                 from /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Arduino.h:223,
                 from /Applications/Arduino.app/Contents/Java/libraries/Ethernet/src/EthernetClient.h:3,
                 from /Applications/Arduino.app/Contents/Java/libraries/Ethernet/src/Ethernet.h:7,
                 from sketch_may11a.ino:2:
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Print.h:48:20: note: 	virtual size_t Print::write(uint8_t)
     virtual size_t write(uint8_t) = 0;
                    ^
In file included from /Applications/Arduino.app/Contents/Java/libraries/Ethernet/src/EthernetServer.h:4:0,
                 from /Applications/Arduino.app/Contents/Java/libraries/Ethernet/src/Ethernet.h:8,
                 from sketch_may11a.ino:2:
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Server.h:27:16: note: 	virtual void Server::begin()
   virtual void begin() =0;
                ^
sketch_may11a.ino: In function 'void loop()':
sketch_may11a.ino:19:25: error: 'class Server' has no member named 'available'
sketch_may11a.ino:19:9: error: cannot declare variable 'client' to be of abstract type 'Client'
In file included from /Applications/Arduino.app/Contents/Java/libraries/Ethernet/src/EthernetClient.h:5:0,
                 from /Applications/Arduino.app/Contents/Java/libraries/Ethernet/src/Ethernet.h:7,
                 from sketch_may11a.ino:2:
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Client.h:26:7: note:   because the following virtual functions are pure within 'Client':
 class Client : public Stream {
       ^
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Client.h:31:18: note: 	virtual size_t Client::write(uint8_t)
   virtual size_t write(uint8_t) =0;
                  ^
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Client.h:32:18: note: 	virtual size_t Client::write(const uint8_t*, size_t)
   virtual size_t write(const uint8_t *buf, size_t size) =0;
                  ^
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Client.h:33:15: note: 	virtual int Client::available()
   virtual int available() = 0;
               ^
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Client.h:34:15: note: 	virtual int Client::read()
   virtual int read() = 0;
               ^
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Client.h:36:15: note: 	virtual int Client::peek()
   virtual int peek() = 0;
               ^
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Client.h:37:16: note: 	virtual void Client::flush()
   virtual void flush() = 0;
                ^
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Client.h:29:15: note: 	virtual int Client::connect(IPAddress, uint16_t)
   virtual int connect(IPAddress ip, uint16_t port) =0;
               ^
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Client.h:30:15: note: 	virtual int Client::connect(const char*, uint16_t)
   virtual int connect(const char *host, uint16_t port) =0;
               ^
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Client.h:35:15: note: 	virtual int Client::read(uint8_t*, size_t)
   virtual int read(uint8_t *buf, size_t size) = 0;
               ^
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Client.h:38:16: note: 	virtual void Client::stop()
   virtual void stop() = 0;
                ^
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Client.h:39:19: note: 	virtual uint8_t Client::connected()
   virtual uint8_t connected() = 0;
                   ^
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Client.h:40:11: note: 	virtual Client::operator bool()
   virtual operator bool() = 0;
           ^
sketch_may11a.ino:25:21: error: 'class String' has no member named 'append'
sketch_may11a.ino:29:27: error: 'class String' has no member named 'contains'
sketch_may11a.ino:32:27: error: 'class String' has no member named 'contains'
Error compiling.

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.

Something bad is going on with the Ethernet.h library. I don't know. You need to test the sample ethernet server sketches to see if you have the same problem.

Here is the error code when compiled with SPI.h

Build options changed, rebuilding all
New_Sketch.ino:18:17: error: no matching function for call to 'Server::Server(int)'
New_Sketch.ino:18:17: note: candidates are:
In file included from /Applications/Arduino.app/Contents/Java/libraries/Ethernet/src/EthernetServer.h:4:0,
                from /Applications/Arduino.app/Contents/Java/libraries/Ethernet/src/Ethernet.h:8,
                from New_Sketch.ino:13:
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Server.h:25:7: note: Server::Server()
class Server : public Print {
      ^
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Server.h:25:7: note:   candidate expects 0 arguments, 1 provided
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Server.h:25:7: note: Server::Server(const Server&)
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Server.h:25:7: note:   no known conversion for argument 1 from 'int' to 'const Server&'
New_Sketch.ino:18:8: error: cannot declare variable 'server' to be of abstract type 'Server'
In file included from /Applications/Arduino.app/Contents/Java/libraries/Ethernet/src/EthernetServer.h:4:0,
                from /Applications/Arduino.app/Contents/Java/libraries/Ethernet/src/Ethernet.h:8,
                from New_Sketch.ino:13:
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Server.h:25:7: note:   because the following virtual functions are pure within 'Server':
class Server : public Print {
      ^
In file included from /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Stream.h:26:0,
                from /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/HardwareSerial.h:29,
                from /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Arduino.h:223,
                from /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SPI/SPI.h:17,
                from New_Sketch.ino:11:
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Print.h:48:20: note: virtual size_t Print::write(uint8_t)
    virtual size_t write(uint8_t) = 0;
                   ^
In file included from /Applications/Arduino.app/Contents/Java/libraries/Ethernet/src/EthernetServer.h:4:0,
                from /Applications/Arduino.app/Contents/Java/libraries/Ethernet/src/Ethernet.h:8,
                from New_Sketch.ino:13:
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Server.h:27:16: note: virtual void Server::begin()
  virtual void begin() =0;
               ^
New_Sketch.ino: In function 'void loop()':
New_Sketch.ino:39:25: error: 'class Server' has no member named 'available'
New_Sketch.ino:39:9: error: cannot declare variable 'client' to be of abstract type 'Client'
In file included from /Applications/Arduino.app/Contents/Java/libraries/Ethernet/src/EthernetClient.h:5:0,
                from /Applications/Arduino.app/Contents/Java/libraries/Ethernet/src/Ethernet.h:7,
                from New_Sketch.ino:13:
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Client.h:26:7: note:   because the following virtual functions are pure within 'Client':
class Client : public Stream {
      ^
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Client.h:31:18: note: virtual size_t Client::write(uint8_t)
  virtual size_t write(uint8_t) =0;
                 ^
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Client.h:32:18: note: virtual size_t Client::write(const uint8_t*, size_t)
  virtual size_t write(const uint8_t *buf, size_t size) =0;
                 ^
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Client.h:33:15: note: virtual int Client::available()
  virtual int available() = 0;
              ^
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Client.h:34:15: note: virtual int Client::read()
  virtual int read() = 0;
              ^
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Client.h:36:15: note: virtual int Client::peek()
  virtual int peek() = 0;
              ^
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Client.h:37:16: note: virtual void Client::flush()
  virtual void flush() = 0;
               ^
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Client.h:29:15: note: virtual int Client::connect(IPAddress, uint16_t)
  virtual int connect(IPAddress ip, uint16_t port) =0;
              ^
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Client.h:30:15: note: virtual int Client::connect(const char*, uint16_t)
  virtual int connect(const char *host, uint16_t port) =0;
              ^
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Client.h:35:15: note: virtual int Client::read(uint8_t*, size_t)
  virtual int read(uint8_t *buf, size_t size) = 0;
              ^
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Client.h:38:16: note: virtual void Client::stop()
  virtual void stop() = 0;
               ^
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Client.h:39:19: note: virtual uint8_t Client::connected()
  virtual uint8_t connected() = 0;
                  ^
/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Client.h:40:11: note: virtual Client::operator bool()
  virtual operator bool() = 0;
          ^
Error compiling.

Here is my actual written code:

#define RELAY1  1                        
#define RELAY2  2                        
#define RELAY3  3                        
#define RELAY4  4
#define RELAY5  5                        
#define RELAY6  6                        
#define RELAY7  7                        
#define RELAY8  8


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


byte mac[] = { 0x00, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 31 };
Server server(80);
String readString = String(30);

 
void setup()
{    
// Initialise the Arduino data pins for OUTPUT
 Serial.begin(9600);
 Ethernet.begin(mac, ip);
 pinMode(RELAY1, OUTPUT); digitalWrite(1,LOW);      
 pinMode(RELAY2, OUTPUT); digitalWrite(2,LOW);
 pinMode(RELAY3, OUTPUT); digitalWrite(3,LOW);
 pinMode(RELAY4, OUTPUT); digitalWrite(4,LOW);
 pinMode(RELAY5, OUTPUT); digitalWrite(5,LOW);       
 pinMode(RELAY6, OUTPUT); digitalWrite(6,LOW);
 pinMode(RELAY7, OUTPUT); digitalWrite(7,LOW);
 pinMode(RELAY8, OUTPUT); digitalWrite(8,LOW);
}


void loop(){
 Client client = server.available();
 if (client) {
   while (client.connected()) {
     if (client.available()) {
       char c = client.read();
       if (readString.length() < 100){
         readString.concat(c);
       }
       if (c == '\n') {
       
            if(readString.indexOf("led8")) {
              toggle(RELAY8);

            } else
            if(readString.indexOf("led3")) {            
              toggle(RELAY3);
            }
            client.println("<html><center>");
            client.println("Light 3
");
            if (digitalRead(3) == LOW){
              client.println("<img src='http://192.168.2.9/images/lightoff.png'>");
            } else if (digitalRead(3) == HIGH){
              client.println("<img src='http://192.168.2.9/images/lighton.png'>");
            }
            client.println("<form method='get'><input type=submit name=led3 value=toggle></form>");
            
            client.println("Light 8
");
            if (digitalRead(8) == LOW){
              client.println("<img src='http://192.168.2.9/images/lightoff.png'>");
            } else if (digitalRead(8) == HIGH){
              client.println("<img src='http://192.168.2.9/images/lighton.png'>");
            }
            client.println("<form method='get'><input type=submit name=led8 value=toggle></form>");
            client.println("</center></html>");
         readString="";
         client.stop();
       }
     }
   }
 }
}

int toggle(int pin){
 if(digitalRead(pin) == LOW){
   digitalWrite(pin, HIGH);
 } else {
   digitalWrite(pin, LOW);
 }
}
// EOF *******************************

The Ethernet library WAS changed. The Server and Client classes were renamed to EthernetServer and EthernetClient, to remove possible conflicts with other generic classes (uselessly) named Server and Client.

Thanks! This helps a lot! :slight_smile:

I believe this code was written in 2010 so I will try to compile in an older version of IDE.

Do you know where Arduino posts where they are changing their code? I have googled for a change log but nothing much comes up.

I am using Uno R3 with ethernet shield.

I think some years ago the "Server" class was renamed to "EthernetServer" and the "Client" class to "EthernetClient", so the two lines I quoted from your code should read:

Okay, just made those two changes and the code compiled! :slight_smile:

Thanks so much!

I am posting the code for future reference:

#define RELAY1  1                        
#define RELAY2  2                        
#define RELAY3  3                        
#define RELAY4  4
#define RELAY5  5                        
#define RELAY6  6                        
#define RELAY7  7                        
#define RELAY8  8


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


byte mac[] = { 0x00, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 31 };
EthernetServer server(80);
String readString = String(30);

 
void setup()
{    
// Initialise the Arduino data pins for OUTPUT
 Serial.begin(9600);
 Ethernet.begin(mac, ip);
 pinMode(RELAY1, OUTPUT); digitalWrite(1,HIGH);    
 pinMode(RELAY2, OUTPUT); digitalWrite(2,HIGH); 
 pinMode(RELAY3, OUTPUT); digitalWrite(3,HIGH); 
 pinMode(RELAY4, OUTPUT); digitalWrite(4,HIGH); 
 pinMode(RELAY5, OUTPUT); digitalWrite(5,HIGH);        
 pinMode(RELAY6, OUTPUT); digitalWrite(6,HIGH); 
 pinMode(RELAY7, OUTPUT); digitalWrite(7,HIGH); 
 pinMode(RELAY8, OUTPUT); digitalWrite(8,HIGH); 
}


void loop(){
 EthernetClient client = server.available();
 if (client) {
   while (client.connected()) {
     if (client.available()) {
       char c = client.read();
       if (readString.length() < 100){
         readString.concat(c);
       }
       if (c == '\n') {
       
            if(readString.indexOf("led8")) {
              toggle(RELAY8);

            } else
            if(readString.indexOf("led3")) {            
              toggle(RELAY3);
            }
            client.println("<html><center>");
            client.println("Light 3
");
            if (digitalRead(RELAY3) == LOW){
              client.println("<img src='http://192.168.2.9/images/lightoff.png'>");
            } else if (digitalRead(RELAY3) == HIGH){
              client.println("<img src='http://192.168.2.9/images/lighton.png'>");
            }
            client.println("<form method='get'><input type=submit name=led3 value=toggle></form>");
            
            client.println("Light 8
");
            if (digitalRead(RELAY8) == LOW){
              client.println("<img src='http://192.168.2.9/images/lightoff.png'>");
            } else if (digitalRead(RELAY8) == HIGH){
              client.println("<img src='http://192.168.2.9/images/lighton.png'>");
            }
            client.println("<form method='get'><input type=submit name=led8 value=toggle></form>");
            client.println("</center></html>");
         readString="";
         client.stop();
       }
     }
   }
 }
}

int toggle(int pin){
 if(digitalRead(pin) == LOW){
   digitalWrite(pin, HIGH);
 } else {
   digitalWrite(pin, LOW);
 }
}
// EOF *******************************

You STILL have a relay on the hardware serial port pin. Don't expect THAT to work.

Compiled and working are 2 different things.

Simple server code that sends a web page for control of an arduino pin.

//zoomkat 10-6-13
//simple button GET with iframe code
//open serial monitor to see what the arduino receives
//use the ' instead of " in html ilnes 
//address will look like http://192.168.1.102:84/ when submited
//for use with W5100 based ethernet shields

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

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //ethernet shield mac address
byte ip[] = { 192, 168, 1, 102 }; // arduino IP in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(84); //server port

String readString; 

//////////////////////

void setup(){

  pinMode(4, OUTPUT); //pin selected to control
  //start Ethernet
  Ethernet.begin(mac, ip, gateway, gateway, subnet);
  server.begin();

  //enable serial data print 
  Serial.begin(9600); 
  Serial.println("servertest1"); // so I can keep track of what is loaded
}

void loop(){
  // Create a client connection
  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();

        //read char by char HTTP request
        if (readString.length() < 100) {

          //store characters to string 
          readString += c; 
          //Serial.print(c);
        } 

        //if HTTP request has ended
        if (c == '\n') {

          ///////////////
          Serial.println(readString); //print to serial monitor for debuging 

          //now output HTML data header
             if(readString.indexOf('?') >=0) { //don't send new page
               client.println("HTTP/1.1 204 Zoomkat\r\n\r\n");
             }
             else {
          client.println("HTTP/1.1 200 OK"); //send new page
          client.println("Content-Type: text/html");
          client.println();

          client.println("<HTML>");
          client.println("<HEAD>");
          client.println("<TITLE>Arduino GET test page</TITLE>");
          client.println("</HEAD>");
          client.println("<BODY>");

          client.println("<H1>Zoomkat's simple Arduino button</H1>");
          
          client.println("<a href='/?on1' target='inlineframe'>ON</a>"); 
          client.println("<a href='/?off' target='inlineframe'>OFF</a>"); 

          client.println("<IFRAME name=inlineframe style='display:none'>");          
          client.println("</IFRAME>");

          client.println("</BODY>");
          client.println("</HTML>");
             }

          delay(1);
          //stopping client
          client.stop();

          ///////////////////// control arduino pin
          if(readString.indexOf("on1") >0)//checks for on
          {
            digitalWrite(4, HIGH);    // set pin 4 high
            Serial.println("Led On");
          }
          if(readString.indexOf("off") >0)//checks for off
          {
            digitalWrite(4, LOW);    // set pin 4 low
            Serial.println("Led Off");
          }
          //clearing string for next read
          readString="";

        }
      }
    }
  }
}

You STILL have a relay on the hardware serial port pin. Don't expect THAT to work.

What does that mean? sorry, like I said earlier I am new to this. How might I fix this?

Compiled and working are 2 different things.

Good Point. I am working on getting the website up server side. I will post an update when I get server side up.

west780:
What does that mean? sorry, like I said earlier I am new to this. How might I fix this?

It means you can't use certain pins like pin 1. You'll find later, you can't use other pins because it'll affect your ethernet shield & SD. You have to research that.

What does that mean? sorry, like I said earlier I am new to this. How might I fix this?

It means that the HardwareSerial class instance called Serial uses pins 0 and 1. While you are trying to use Serial to input or output data, you can not use those pins as input.

The Ethernet shield uses pins 10, 11, 12, and 13. They are not available to you, either.

If you need the SD card on the Ethernet shield, scratch pin 4, too.

You can use the analog pins as digital pins, if you don't have enough digital pins.

You might try the below in your setup section.

void setup()
{
   Serial.begin(9600);

   pinMode(10,OUTPUT);
   digitalWrite(10,HIGH);

   // you are failing here?
   if(SD.begin(4) == 0)
   {
      Serial.println("SD fail");
   }
   else
   {
      Serial.println("SD ok");
   }

   Ethernet.begin(mac, ip, gateway, gateway, subnet);
   digitalWrite(10,HIGH);

Update.

Thank you to all of the helpful posts. I have been super busy in the past week with unrelated tasks. I should have some time this week to work on this. I am still working server side however and do plan to get it working soon!

What if I'm not using the SD card? Than is it okay to use pin 4?

This is probably not the place to post this, but does anyone have experience with mister house?

Link: http://misterhouse.sourceforge.net/

If two or three people in this forum really were interested in an extended example for a web control server, I'd consider to create some code for it that could be easily adapted for different usage.

Jurs, I appreciate the help you have given so far and would love to see what you come up with. Add me to the list!

Ok, I just got everything (to my knowledge) up server side.

I have run into a problem (no big surprise) and I have realized that I have not thoroughly explained what we are working with.

I am currently running server 2012 r2 on a dell server that is hosting this local php site on IIS8.

Here is the main code for the website:

<html>
<head>
<title>Home Automation Control Panel</title>
<script type="text/JavaScript" src="scripts/jquery.js"></script>
<script type="text/JavaScript" src="scripts/js/jquery-ui-1.8.2.custom.min.js"></script>
<link type="text/css" href="scripts/css/start/jquery-ui-1.8.2.custom.css" rel="stylesheet" /> 
<script type="text/javascript"> 
	//makes pretty buttons from theme
	$(function() {
		$("input:submit").button();
	});
	</script>
<script type="text/JavaScript">
 $(document).ready(function(){
 //loads status on page ready
 $("#led8").load("middle.php", "a=get8");
 $("#led3").load("middle.php", "a=get3");
//refreshes the statuses
 var refreshId = setInterval(function() {
	$("#led8").load("middle.php", "a=get8");
	$("#led3").load("middle.php", "a=get3");
}, 2000);

   //led8 get and toggle when clicked
   $("#led8button").click(function(){
   $("#led8").load("middle.php", "a=get8&l=toggle8");
});
   //led3 get and toggle when clicked
   $("#led3button").click(function(){
   $("#led3").load("middle.php", "a=get3&l=toggle3");
});

//end
});
</script>

<script type="text/javascript"> 
	//accordion code set to mouseover and no autoheight
	$(function() {
		$("#accordion").accordion({
			event: "mouseover",
			autoHeight: false
		});
	});
	</script> 

</head>


<body>


<div id=accordion style="width:250px;">
<h3><a href="#">Lights</a></h3>
<div>
<div  style="text-align: center;" class="ui-widget-content">
LED8<div id="led8"><IMG SRC="images/ajax-loader.gif"></div>
<input type=submit id=led8button value=Toggle>
</div>


<div  style="text-align: center;" class="ui-widget-content">
LED3<div id="led3"><IMG SRC="images/ajax-loader.gif"></div>
<input type=submit id=led3button value=Toggle>
</div>
</div>

<h3><a href="#">Locks</a></h3>
<div>
<IMG SRC="images/ajax-loader.gif">
</div>

<h3><a href="#">A/C</a></h3>
<div>
<IMG SRC="images/ajax-loader.gif">
</div>


</div>


</body>
</html>

In this code it also references ‘middle.php’ that I will post here:

<?php


if($_GET[l] == "toggle8")
{
include("http://192.168.1.31/?l=toggle8");
}
if($_GET[l] == "toggle3")
{
include("http://192.168.1.31/?l=toggle3");
}


if($_GET[a] == "get8")
{
include("http://192.168.1.31/?a=get8");
}

if($_GET[a] == "get3")
{
include("http://192.168.1.31/?a=get3");
}





?>

These two pieces of html/php are supposed to send php to the arduino and relays.

Here is the code for the arduino:

#define RELAY1  2                       
#define RELAY2  3                        
#define RELAY3  4                        
#define RELAY4  5
#define RELAY5  6                        
#define RELAY6  7                        
#define RELAY7  8                        
#define RELAY8  9


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


byte mac[] = { 0x00, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 31 };
EthernetServer server(80);
String readString = String(30);

 
void setup()
{    
// Initialise the Arduino data pins for OUTPUT
 Serial.begin(9600);
 Ethernet.begin(mac, ip);
 pinMode(RELAY1, OUTPUT); digitalWrite(1,HIGH);    
 pinMode(RELAY2, OUTPUT); digitalWrite(2,HIGH); 
 pinMode(RELAY3, OUTPUT); digitalWrite(3,HIGH); 
 pinMode(RELAY4, OUTPUT); digitalWrite(4,HIGH); 
 pinMode(RELAY5, OUTPUT); digitalWrite(5,HIGH);        
 pinMode(RELAY6, OUTPUT); digitalWrite(6,HIGH); 
 pinMode(RELAY7, OUTPUT); digitalWrite(7,HIGH); 
 pinMode(RELAY8, OUTPUT); digitalWrite(8,HIGH); 
}


void loop(){
 EthernetClient client = server.available();
 if (client) {
   while (client.connected()) {
     if (client.available()) {
       char c = client.read();
       if (readString.length() < 100){
         readString.concat(c);
       }
       if (c == '\n') {
       
            if(readString.indexOf("led8")) {
              toggle(RELAY8);

            } else
            if(readString.indexOf("led3")) {            
              toggle(RELAY3);
            }
            client.println("<html><center>");
            client.println("Light 3
");
            if (digitalRead(RELAY3) == LOW){
              client.println("<img src='http://http://192.168.1.11/web/homeautomation/images/lightoff'>");
            } else if (digitalRead(RELAY3) == HIGH){
              client.println("<img src='http://http://192.168.1.11/web/homeautomation/images/lighton.png'>");
            }
            client.println("<form method='get'><input type=submit name=led3 value=toggle></form>");
            
            client.println("Light 8
");
            if (digitalRead(RELAY8) == LOW){
              client.println("<img src='http://http://192.168.1.11/web/homeautomation/images/lightoff.png'>");
            } else if (digitalRead(RELAY8) == HIGH){
              client.println("<img src='http://http://192.168.1.11/web/homeautomation/images/lighton.png'>");
            }
            client.println("<form method='get'><input type=submit name=led8 value=toggle></form>");
            client.println("</center></html>");
         readString="";
         client.stop();
       }
     }
   }
 }
}

int toggle(int pin){
 if(digitalRead(pin) == LOW){
   digitalWrite(pin, HIGH);
 } else {
   digitalWrite(pin, LOW);
 }
}
// EOF *******************************

As it stands right now I can connect to the arduino through the IP i have assigned it and adjust the lights from there. However, I do not want this. I want to have the server/website send the arduino some php to then turn on and off the relays. an end result may have 5-6 different relays that the website will help stream line with out me having to type 192.168.1.31 for one set of lights but than having to type 192.168.1.33 for another, etc.

sorry for the long rant but now for the problem. I do not know why I am having this connection issue. I have no prior experience with php, so if anyone can potentially take a quick look and see if I am just a total scrub or something? Thank you!

I am using 3 components here.

First is my laptop (or any internet device). This is used to access the web server.

Second is the Dell server. It is hosting the website.

Third is the arduino, it is interpreting the php the Dell server is sending it as well as toggling the relays.

The idea behind this is that I will be using multiple arduino boards on the network and I want to connect to a single, master website that controls all of the arduino boards.