Controlling my lights and fans through relay from the webserver

I connected my lights and fans to a eight channel relay board which is connected to my arduino and ethernet shield
the html page loads fine and all the relays work but after a few hours the html page stops loading until i press reset

Heres the code, would really appreciate some help

Thanks
Abhijeet

Check the attachment for the source code

simple.ino (13.1 KB)

If your code is too large to post using code tags, then the code may be so large that it has memory issues.

I've played with control across the web a couple of times. Not so long ago, I had a 2nd working server, but had to restrict what I did because, I think, of memory issues. (They were very tiresome, leading to weird crashes rather than decent error messages)

Recently, I revisited the topic, this time using a Teensy... very like an Arduino. You program it with the Arduino software plus an add-on...

And I was able to "go mad" with my server, adding all sorts of stuff, much more than I'd been able to include before.

Described at Arduserver.com

zoomkat:
If your code is too large to post using code tags, then the code may be so large that it has memory issues.

But the arduino software shows 16bytes out of 32 bytes.?

Thanks

tkbyd:
I've played with control across the web a couple of times. Not so long ago, I had a 2nd working server, but had to restrict what I did because, I think, of memory issues. (They were very tiresome, leading to weird crashes rather than decent error messages)

Recently, I revisited the topic, this time using a Teensy... very like an Arduino. You program it with the Arduino software plus an add-on...

And I was able to "go mad" with my server, adding all sorts of stuff, much more than I'd been able to include before.

Described at Arduserver.com

What site u suggested is great

Thanks!

But the arduino software shows that the code is only 16bytes.?

tkbyd:
I've played with control across the web a couple of times. Not so long ago, I had a 2nd working server, but had to restrict what I did because, I think, of memory issues. (They were very tiresome, leading to weird crashes rather than decent error messages)

Recently, I revisited the topic, this time using a Teensy... very like an Arduino. You program it with the Arduino software plus an add-on...

And I was able to "go mad" with my server, adding all sorts of stuff, much more than I'd been able to include before.

Described at Arduserver.com

Hey thanks for the suggestion, but the source code on that page is overly complicated

Can u give me a simplified code where all it does is control relays or direct me to a link which does

i would really appreciate your help

Thanks
Abhijeet

... code is overly complicated...

There are a number of bits which could be snipped out... the bit for reading the temperatures, for instance. That would slim the code down some, but the "bits" and their boundaries should be clear enough.

If anyone can show ME simpler code for turning something on and off, I too would be glad to see it!

tkbyd:
There are a number of bits which could be snipped out... the bit for reading the temperatures, for instance. That would slim the code down some, but the "bits" and their boundaries should be clear enough.

If anyone can show ME simpler code for turning something on and off, I too would be glad to see it!

I found a simpler code I'll put the link here tomo

It works great and toggles the relays very, but when I connect an a.c. load to the relay the page again stops loading

I guess its a problem with the relay, can u show me a relay which can handle a.c. loads without disturbing the arduino

I'll put the simpler code in a while

Thanks

Have you provided the relay with The Diode??

tkbyd:
Have you provided the relay with The Diode??

Relays- especially "the diode"- An introduction to using them with microprocessors- ec1relay.htm

Hey i directly purchased a eight channel relay board(optically isolated relay)

heres the link--http://www.simplelabs.co.in/content/8-channel-5v-relay-module

so back emf i dont think is the problem

what else do u think it is?

thanks

tkbyd:
Have you provided the relay with The Diode??

Relays- especially "the diode"- An introduction to using them with microprocessors- ec1relay.htm

Hey

the tube lights and bulbs work well

but when i switch on my fan through the relay the html page hangs

what can i do as im using a optically isolated relay

heres the link--http://www.simplelabs.co.in/content/8-channel-5v-relay-module

plz help

"This, along with the optical isolation, provides a total galvanic isolation between the input and output. The two grounds could be joined together if desired with the included jumper."

You don't have the jumper on, right? And you power the relays from a different power supply than your arduino?

Try using a multimeter to check if there is a connection between arduino ground and relay ground.

Hashma:
"This, along with the optical isolation, provides a total galvanic isolation between the input and output. The two grounds could be joined together if desired with the included jumper."

You don't have the jumper on, right? And you power the relays from a different power supply than your arduino?

Try using a multimeter to check if there is a connection between arduino ground and relay ground.

Hey thanks for the reply,

i dont have a jumper
And yes, i power the relays from a separate power source, and again yes i make a common ground between the relay and arduino though they have separate power supplies

I would really appreciate it if u could tell me how i can provide a total galvanic isolation between input and output to my existing eight channel optically isolated relay, here's the link of the relay--http://www.simplelabs.co.in/content/8-channel-5v-relay-module

plz help

thanks

Really not easy to say without a schematic.

If your relays and arduino share a common ground I would start by tracing the traces on the relay pcb to find out where the grounds are connected.

Your relay module should have 2 power and ground inputs, which should not be connected together at any point.

Some of the "optically isolated" relay modules sold aren't actually isolated, and just use the opto to turn on the relays (so they don't burn the output of the arduino). If both sides of the opto is connected to each other at one point or another, it ain't isolated.. :slight_smile:

Hashma:
Really not easy to say without a schematic.

If your relays and arduino share a common ground I would start by tracing the traces on the relay pcb to find out where the grounds are connected.

Your relay module should have 2 power and ground inputs, which should not be connected together at any point.

Some of the "optically isolated" relay modules sold aren't actually isolated, and just use the opto to turn on the relays (so they don't burn the output of the arduino). If both sides of the opto is connected to each other at one point or another, it ain't isolated.. :slight_smile:

Hey thanks for the reply!

I didnt understand much from your reply but when i make the arduino and relay ground common it dosent work, and when i keep the grounds separate it still dosent work

Here's links to some more technical information on the relays, plz do check them out and lemme know what u think--http://www.hobbytronics.co.uk/8-channel-relay-board
8-Channel Relay Module for Arduino

and one more thing i have just taken only one supply line(mains) from the switch board and divided it into four separate wires to supply to the relay, is that the appropriate way to get the main ac supply?

thanks a lot for your help

abhijeet

Hey,

I have a software problem, I'm controlling relays through ethernet shield and arduino. I got a code from the net which works great and i can control the relays perfectly.
But the problem I'm getting is when i add too many buttons on the HTML page, the HTML page just doesn't load. Only when I'm using max four buttons it works, but when i add more than four it doesn't work.
I have provided the code below, please if anyone can help me add more buttons without using too much memory i would have solved my problem.

#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 };
IPAddress ip(192,168,1,177);

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



String readString = String(100); //string for fetching data from address

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

  pinMode(6, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);

  // start the Ethernet connection and the server:

  Serial.println(F("Initiaizing ethernet..."));

  // this uses a fixed address
  Ethernet.begin(mac, ip);

  // get an address with DHCP
  //if (Ethernet.begin(mac) == 0)
  //  Serial.println("Failed to configure Ethernet using DHCP");

  // give the card a second to initialize 
  delay(1000);

  server.begin();

  Serial.print(F("Garage Door Opener Control Ready at IP address "));
  Serial.println(Ethernet.localIP());
}

void loop()
{
  // command received (one character)  '1' - activate garage door button
  char cmd = 0;          // 1 - pulse button
  boolean done = false;  // set to indicate that response is complete

  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {

    Serial.println(F("new client"));
    readString = "";

    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        //int i = c;
        //Serial.print("(");
        //Serial.print(i);
        //Serial.print(")");

        // store character received in receive string
        if (readString.length() < 100) {
          readString += (c);
        }

        // check for end of line
        if (c == '\n') {
            //Serial.print("Receved line: ");
            //Serial.print(readString);  

            // process line if its the "GET" request
            // a request looks like "GET /?1" or "GET /?2"
            if (readString.indexOf("GET") != -1) {
                if (readString.indexOf("?1") != -1)
                   cmd = '1';
                // check for other commands here. ie turn on light, etc.
                if (readString.indexOf("?2") != -1)
                   cmd = '2';  
                                  if (readString.indexOf("?3") != -1)
                   cmd = '3'; 
                                  if (readString.indexOf("?4") != -1)
                   cmd = '4'; 
                                  if (readString.indexOf("?5") != -1)
                   cmd = '5'; 
                                  if (readString.indexOf("?6") != -1)
                   cmd = '6'; 
                                  if (readString.indexOf("?7") != -1)
                   cmd = '7';
                                 if (readString.indexOf("?8") != -1)
                   cmd = '8'; 
   
            }              

           // if a blank line was received (just cr lf, length of 2), then its the end of the request
           if (readString.length() == 2) {
             if (cmd == '1'){
                Serial.println(F("Activate Button"));
                digitalWrite(6, HIGH);

             }
                          if (cmd == '2'){
                Serial.println(F("Activate Button"));
                digitalWrite(6, LOW);

             }
                          if (cmd == '3'){
                Serial.println(F("Activate Button"));
                digitalWrite(5, HIGH);

             }
                          if (cmd == '4'){
                Serial.println(F("Activate Button"));
                digitalWrite(5, LOW);

             }
                          if (cmd == '5'){
                Serial.println(F("Activate Button"));
                digitalWrite(7, HIGH);

             }
                          if (cmd == '6'){
                Serial.println(F("Activate Button"));
                digitalWrite(7, LOW);

             }
                          if (cmd == '7'){
                Serial.println(F("Activate Button"));
                digitalWrite(8, HIGH);

             }
                          if (cmd == '8'){
                Serial.println(F("Activate Button"));
                digitalWrite(8, LOW);

             }

             // add other commands here

             // send web page back to client 
             Serial.println(F("sending web page"));
             SendWebPage(client); 
             Serial.println(F("web page sent"));

             cmd = 0;

             // break out and disconnect. This will tell the browser the request is complete without having to specify content-length
             break;

           }  // end of request reached

           // start line over            
           readString = "";
        }  // end of line reached
      }  // end data is available from client
    }  // end cient is connected
    // give the web browser time to receive the data
    Serial.println(F("delay before disconnect"));
    delay(100);
    // close the connection:
    client.stop();
    Serial.println(F("client disonnected")); 
  }  // end client has been created
}

// send web page
void SendWebPage(EthernetClient client)
{
   client.println(F("HTTP/1.1 200 OK")); 
   client.println(F("Content-Type: text/html")); 
   // to specify the length, wooul have to construct the entire string and then get its length
   //client.println("Content-Length: 1234"); 
   client.println(F("Connnection: close")); 
   client.println(); 

   client.println(F("<!DOCTYPE HTML>"));
   client.println(F("<html>"));
   client.println(F("<head>"));
   client.println(F("<title>Home Automation Control</title>"));

   client.println(F("<style type='text/css'>"));
   client.println(F(".label {font-size: 30px; text-align:center;}"));
   client.println(F("button {width: 160px; height: 70px; font-size: 30px; -webkit-appearance: none; background-color:#dfe3ee; }"));
   client.println(F("</style>"));

   client.println(F("<script type='text/javascript'>"));

   client.println(F("function OnButtonClicked(parm) { window.location.href=\"X?\" + parm; }"));

   client.println(F("</script>"));

   client.println(F("</head>"));

   client.println(F("<body style=\"background-color:#3b5998\">"));

   client.println(F("<div class=\"label\">"));

   client.println(F("Home Auotmation Control

"));

   // future idea: could read a limit switch on the garage door here and tell the user if the door is currently open or closed
   /*
   if (digitalRead(DOOR_OPEN_INPUT) == HIGH)
     client.println("Door is Open"); 
   else  
     client.println("Door is Closed"); 
   client.println("
");
   */

   // door open / close button
   if (digitalRead(6)==LOW)
   {
   client.println(F("<button onclick=\"OnButtonClicked('1');\">1ON</button>

"));
   }if (digitalRead(6)==HIGH){
   client.println(F("<button onclick=\"OnButtonClicked('2');\">1Off</button>

"));
   }   if (digitalRead(5)==LOW)
   {
   client.println(F("<button onclick=\"OnButtonClicked('3');\">2ON</button>

"));
   }if (digitalRead(5)==HIGH){
   client.println(F("<button onclick=\"OnButtonClicked('4');\">2Off</button>

"));
   }  if (digitalRead(7)==LOW)
   {
   client.println(F("<button onclick=\"OnButtonClicked('5');\">3ON</button>

"));
   }if (digitalRead(7)==HIGH){
   client.println(F("<button onclick=\"OnButtonClicked('6');\">3Off</button>

"));
     }   if (digitalRead(8)==LOW)
   { 
   client.println(F("<button onclick=\"OnButtonClicked('7');\">4ON</button>

"));
   }if (digitalRead(8)==HIGH){
     
   client.println(F("<button onclick=\"OnButtonClicked('8');\">4Off</button>

"));
   }


   // add more buttons here
   // button separator



   client.println(F("</div>"));

   client.println(F("</body>"));
   client.println(F("</html>"));

   client.println("");
}

I would really appreciate if someone could help me out

Thanks
Abhijeet

Hey,

I have a software problem, I'm controlling relays through ethernet shield and arduino. I got a code from the net which works great and i can control the relays perfectly.
But the problem I'm getting is when i add too many buttons on the HTML page, the HTML page just doesn't load. Only when I'm using max four buttons it works, but when i add more than four it doesn't work.
I have provided the code below, please if anyone can help me add more buttons without using too much memory i would have solved my problem.

#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 };
IPAddress ip(192,168,1,177);

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



String readString = String(100); //string for fetching data from address

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

  pinMode(6, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);

  // start the Ethernet connection and the server:

  Serial.println(F("Initiaizing ethernet..."));

  // this uses a fixed address
  Ethernet.begin(mac, ip);

  // get an address with DHCP
  //if (Ethernet.begin(mac) == 0)
  //  Serial.println("Failed to configure Ethernet using DHCP");

  // give the card a second to initialize 
  delay(1000);

  server.begin();

  Serial.print(F("Garage Door Opener Control Ready at IP address "));
  Serial.println(Ethernet.localIP());
}

void loop()
{
  // command received (one character)  '1' - activate garage door button
  char cmd = 0;          // 1 - pulse button
  boolean done = false;  // set to indicate that response is complete

  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {

    Serial.println(F("new client"));
    readString = "";

    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        //int i = c;
        //Serial.print("(");
        //Serial.print(i);
        //Serial.print(")");

        // store character received in receive string
        if (readString.length() < 100) {
          readString += (c);
        }

        // check for end of line
        if (c == '\n') {
            //Serial.print("Receved line: ");
            //Serial.print(readString);  

            // process line if its the "GET" request
            // a request looks like "GET /?1" or "GET /?2"
            if (readString.indexOf("GET") != -1) {
                if (readString.indexOf("?1") != -1)
                   cmd = '1';
                // check for other commands here. ie turn on light, etc.
                if (readString.indexOf("?2") != -1)
                   cmd = '2';  
                                  if (readString.indexOf("?3") != -1)
                   cmd = '3'; 
                                  if (readString.indexOf("?4") != -1)
                   cmd = '4'; 
                                  if (readString.indexOf("?5") != -1)
                   cmd = '5'; 
                                  if (readString.indexOf("?6") != -1)
                   cmd = '6'; 
                                  if (readString.indexOf("?7") != -1)
                   cmd = '7';
                                 if (readString.indexOf("?8") != -1)
                   cmd = '8'; 
   
            }              

           // if a blank line was received (just cr lf, length of 2), then its the end of the request
           if (readString.length() == 2) {
             if (cmd == '1'){
                Serial.println(F("Activate Button"));
                digitalWrite(6, HIGH);

             }
                          if (cmd == '2'){
                Serial.println(F("Activate Button"));
                digitalWrite(6, LOW);

             }
                          if (cmd == '3'){
                Serial.println(F("Activate Button"));
                digitalWrite(5, HIGH);

             }
                          if (cmd == '4'){
                Serial.println(F("Activate Button"));
                digitalWrite(5, LOW);

             }
                          if (cmd == '5'){
                Serial.println(F("Activate Button"));
                digitalWrite(7, HIGH);

             }
                          if (cmd == '6'){
                Serial.println(F("Activate Button"));
                digitalWrite(7, LOW);

             }
                          if (cmd == '7'){
                Serial.println(F("Activate Button"));
                digitalWrite(8, HIGH);

             }
                          if (cmd == '8'){
                Serial.println(F("Activate Button"));
                digitalWrite(8, LOW);

             }

             // add other commands here

             // send web page back to client 
             Serial.println(F("sending web page"));
             SendWebPage(client); 
             Serial.println(F("web page sent"));

             cmd = 0;

             // break out and disconnect. This will tell the browser the request is complete without having to specify content-length
             break;

           }  // end of request reached

           // start line over            
           readString = "";
        }  // end of line reached
      }  // end data is available from client
    }  // end cient is connected
    // give the web browser time to receive the data
    Serial.println(F("delay before disconnect"));
    delay(100);
    // close the connection:
    client.stop();
    Serial.println(F("client disonnected")); 
  }  // end client has been created
}

// send web page
void SendWebPage(EthernetClient client)
{
   client.println(F("HTTP/1.1 200 OK")); 
   client.println(F("Content-Type: text/html")); 
   // to specify the length, wooul have to construct the entire string and then get its length
   //client.println("Content-Length: 1234"); 
   client.println(F("Connnection: close")); 
   client.println(); 

   client.println(F("<!DOCTYPE HTML>"));
   client.println(F("<html>"));
   client.println(F("<head>"));
   client.println(F("<title>Home Automation Control</title>"));

   client.println(F("<style type='text/css'>"));
   client.println(F(".label {font-size: 30px; text-align:center;}"));
   client.println(F("button {width: 160px; height: 70px; font-size: 30px; -webkit-appearance: none; background-color:#dfe3ee; }"));
   client.println(F("</style>"));

   client.println(F("<script type='text/javascript'>"));

   client.println(F("function OnButtonClicked(parm) { window.location.href=\"X?\" + parm; }"));

   client.println(F("</script>"));

   client.println(F("</head>"));

   client.println(F("<body style=\"background-color:#3b5998\">"));

   client.println(F("<div class=\"label\">"));

   client.println(F("Home Auotmation Control

"));

   // future idea: could read a limit switch on the garage door here and tell the user if the door is currently open or closed
   /*
   if (digitalRead(DOOR_OPEN_INPUT) == HIGH)
     client.println("Door is Open"); 
   else  
     client.println("Door is Closed"); 
   client.println("
");
   */

   // door open / close button
   if (digitalRead(6)==LOW)
   {
   client.println(F("<button onclick=\"OnButtonClicked('1');\">1ON</button>

"));
   }if (digitalRead(6)==HIGH){
   client.println(F("<button onclick=\"OnButtonClicked('2');\">1Off</button>

"));
   }   if (digitalRead(5)==LOW)
   {
   client.println(F("<button onclick=\"OnButtonClicked('3');\">2ON</button>

"));
   }if (digitalRead(5)==HIGH){
   client.println(F("<button onclick=\"OnButtonClicked('4');\">2Off</button>

"));
   }  if (digitalRead(7)==LOW)
   {
   client.println(F("<button onclick=\"OnButtonClicked('5');\">3ON</button>

"));
   }if (digitalRead(7)==HIGH){
   client.println(F("<button onclick=\"OnButtonClicked('6');\">3Off</button>

"));
     }   if (digitalRead(8)==LOW)
   { 
   client.println(F("<button onclick=\"OnButtonClicked('7');\">4ON</button>

"));
   }if (digitalRead(8)==HIGH){
     
   client.println(F("<button onclick=\"OnButtonClicked('8');\">4Off</button>

"));
   }


   // add more buttons here
   // button separator



   client.println(F("</div>"));

   client.println(F("</body>"));
   client.println(F("</html>"));

   client.println("");
}

I would really appreciate if someone could help me out

Thanks
Abhijeet

briankTHISISITF__.ino (7.76 KB)