Web controlled relays malfunction when carrying load


i have fitted arduino ethernet shield , 4 single relays, can control 240v.

i trying make web interface, control 240v devices in house. post code below.

when testing nothing connected relays, works charm. can press button in web browser, digital state shifts accordingly.

but whenever connect relay, arduino crashes, , web server stops.
i can control other relays flawlessly, when choose relay carrying load - crash!

hope can me?

code: [select]
#include <spi.h>
#include <ethernet.h>

string commandstring = string(30);
byte mac[] = {
  0xde, 0xad, 0xbe, 0xef, 0xfe, 0xed };
  string portnames[10] = {"","","","","","","port 6","port 7","airport express","forstaerker stuen"};

// initialize ethernet server library
ethernetserver server = ethernetserver(80);

void setup() {
  // set ports
  ( int port = 6; port <= 9; port++ ) {
            pinmode(port,output);
  }
  // start ethernet connection , server:
  ethernet.begin(mac);
  server.begin();
}


void loop() {
  // if incoming client connects, there bytes available read:
  ethernetclient client = server.available();
  if (client) {
          commandstring="";
          ( int = 0; < 10; i++) {
            char c = client.read();
            if( c != '\n' && c > 0 ) {
              commandstring.concat(c);
            }
          }
          turnportsonoff();
          delay(100);
          printwebpage(client);
          client.println(commandstring);
          client.stop();
        }
}

void printwebpage(ethernetclient client) {
  string color;
  client.println("http/1.1 200 ok");
          client.println("content-type: text/html");
          client.println("connection: close");
          client.println();
          client.println("");
          client.println("bendts arduino netkontakt");
          client.println("");
          client.println("");
          client.println("");
          client.println("</pre><h1>taend og sluk ting paa loftet</h1><pre>");
          ( int port = 6; port <= 9; port++ ) {
            if(!digitalread(port)) {
              color = "green";
            } else {
              color = "red";
            }
            client.println("<br>");
            client.print("<a href=\"http://");
            client.print(ethernet.localip());
            client.print("/port");
            client.print(port);
            client.print("\"><button style=\"background-color:");
            client.print(color);
            client.print("\">");
            client.print(portnames[port]);
            client.println("</button></a>");
          }
          client.println("");
}     

void turnportsonoff( ) {
          if (commandstring.indexof("port6") >= 0) {
              digitalwrite( 6, !digitalread(6));
              delay(100);
          }
          if (commandstring.indexof("port7") >= 0) {
              digitalwrite( 7, !digitalread(7));

          }
          if (commandstring.indexof("port8") >= 0) {
              digitalwrite( 8, !digitalread(8));
              delay(100);
          }
          if (commandstring.indexof("port9") >= 0) {
              digitalwrite( 9, !digitalread(9));
              delay(100);
          }
}

the load not carried in program, in electronic montage ... let's have on !


Arduino Forum > Topics > Home Automation and Networked Objects > Web controlled relays malfunction when carrying load


arduino

Comments

Popular posts from this blog

VIDIOC_S_FMT error 16, Device or resource busy - Raspberry Pi Forums

using a laptop skeleton to build a pi laptop - Raspberry Pi Forums

Forum for Joomla? - Joomla! Forum - community, help and support