Ethernet Shield Disconnecting and Relay Buzzing

I want to Control my Room Lights with My Arduino… Reading some Online Tutorials… I Bought an Arduino, Ethernet Shield and a 4 in 1 Relay Board (12V).

I noticed that when I connect Ethernet Shield and Relay Board and Run the Program…
I face 2 problems

  1. My Ethernet Shield Gets Connected to my router for 10 Seconds and then gets Disconnects for 30 Seconds and then Gets back on for 10 seconds

  2. When I Turn ON My relay using Sketch it makes a Buzzing Sound.

My Code :

#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[]  = { 192, 168, 1, 25 };                  
byte gateway[] = { 192, 168, 1, 1 };                
byte 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);

int temp = 0;
int Pin3 = 3;
boolean flag = true;

String Notification = String("");      // string for fetching data from address
boolean Pin3ON = false;                  // Status flag

void setup() {
  pinMode(Pin3, OUTPUT);
  
 // Open serial communications and wait for port to open:
  Serial.begin(115200);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip, gateway, subnet);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
}


void loop() {
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
//--------------------------------------------------------------------------------------
                                                                //read char by char HTTP request
                                                                if (Notification.length() < 12) {
                                                                  //store characters to string
                                                                  //Notification.append(c);  //removed by Katsu
                                                                  Notification = Notification + c; // insert by Katsu
                                                                  // very simple but it works...
                                                                }
//-----------------------------------------------------------------------------------------*/        
        // 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) {
//--------------------------------------------------------------------------------------------
                                                                 if(Notification.indexOf("3=lig") > -1) {  
                                                                    digitalWrite(Pin3, HIGH);
                                                                    Serial.println("Pin 3 ligado!");
                                                                    Pin3ON = true;
                                                                    flag = true;
                                                                  }
                                                                  if(Notification.indexOf("3=des") > -1){  
                                                                    digitalWrite(Pin3, LOW);
                                                                    Serial.println("Pin 3 desligado!");
                                                                    Pin3ON = false;
                                                                    flag = true;
                                                                  }
                                                                  
                                                                  if(Notification.indexOf("all=To") > -1){  
                                                                    digitalWrite(Pin3, LOW);
                                                                    Serial.println("Todos Desligados!");
                                                                    Pin3ON = false;
                                                                    flag = true;
                                                                  }
//-----------------------------------------------------------------------------------------------*/          
                                                              Notification="";
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connnection: close");
          client.println();
          
//HTML----------------------------------------------------------------------------------------*/          
          client.print("<!DOCTYPE HTML>");
          client.print("<html>");
          client.print("<head>");
          client.print("<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>");
          // client.print("<meta http-equiv=\"refresh\" content=\"5\">"); if you want to refresh browser but DONT RECOMEND
          client.print("<title>WebLightSwitch</title>");
          client.print("</head>");
          client.print("<body bgcolor='#303030'>");
          client.print("<style type='text/css'> .submit{width:230px; height:230px; text-indent: -99999px; text-align: center; background-color: Transparent; border:none;}</style>");
          client.print("<style type='text/css'> #switch{width:539px; height:248px;}</style>");
          client.print("<style type='text/css'> *{margin:auto; text-align:center;}</style>");
          
if (flag) {
  client.print("<body>





");
  client.print("<div id='title'> <img src='https://dl.dropboxusercontent.com/u/155411/test/name_title.jpg' width='539' height='112' alt='Web Light Switch' /> </div> 
");
  client.print("<div id='switch'>");
  client.print("<table width='539' height='248' border='0'> <tr>");
  client.print("<td width='265'><form method=get><input type=submit class='submit' name=3 value='desliga'></form></td>");
  client.print("<td width='264'><form method=get><input type=submit class='submit' name=3 value='liga'></form></td></tr>");
  client.print("</table> </div>");
  client.print("</body>");
  client.print("</html>");
                                                                       
  if (Pin3ON) {
    client.print("<style type='text/css'>#switch{ background-image:url(https://dl.dropboxusercontent.com/u/155411/test/switch_on.jpg);}</style>");
    } else {
      client.print("<style type='text/css'>#switch{ background-image:url(https://dl.dropboxusercontent.com/u/155411/test/switch_off.jpg);}</style>");
    }     
  }  // Ende von: if (flag)
  
  break;  //wozu?
        }
        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();
    Serial.println("client disonnected");
  }
}

After Some Internet Research… I came to know, Both these Problems are because of More Voltage Consumption/Drop on Ethernet shield. My Laptop isn’t enough to Power all this circuit.

Connection => this is all Basic… Arduino To Ethernet Shield and 1 Wire from DIGITAL PIN 3 (of Ethernet Shield) to Relay Pin. Relay Board is getting its power Externally with a 12V Power Adapter. And Arduino + Ethernet Shield is getting power from my Laptop using USB Cable. and a Standard RJ45 Cable is used to connect Ethernet Shield to my Router (NETGEAR N150).

My Questions are =>
Sir,
Am I Going in right Direction ?
Is this Really the Problem of Voltage Drop ? If Yes, How can I Solve it ?
If Not What it could be ?
(I am a Newbie in all this)

Until others reply with more ideas/suggestions/solutions, why not get a 9V DC regulated power supply @ around 800 to 1000mA (to cater for the extra shields) then at least you can eliminate one possibility of your problems (i.e. too little current).

Actually I am unable to power my board Externally...
I've been discussing this on the Forum
http://forum.arduino.cc/index.php?topic=205728.0

Can you suggest other ways to answer my question ?

Does the Arduino/ethernet shield work ok without the relay board?

Can you post a link to the relay board? How are you providing power to it? Normally, a buzzing relay means not enough power to activate it fully.

I Bought My Relay Board and Ethernet Shield of Ebay
The Relay Board the Buyer has removed that product. So I’ll Upload its photo and here is the link where I bought my Ethernet Shield.

http://www.ebay.in/itm/200946432597?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649

My Ethernet Shield behaves same without the Relay Board too.
It still connects and disconnects to my router on random basis.

I am using a separate 12V Power adapter to power my Relay Board

IMG_1374.JPG

How about the relay board? Have you tried it by itself without the ethernet shield? Does it still buzz?

Relay Board Works Fine.
If I Upload a normal "Blink" program on my board and connect PIN 13 with the Relay Pin. Relay works Just fine.
It gets ON and OFF in a second as programmed.

Anyone ?

Bad ethernet shield? Sounds like a power problem on the ethernet shield.

Problem Solved!
I could now Power my Ethernet Shield and my circuit is running fine.
But Now I have another issue.

When I turn ON/OFF just the relay with the program uploaded above. Relay Board works fine. But when I connect a Light Bulb running at 220V and try to control it with my Relay Board. It just turns ON once or twice. then my Arduino Hangs or Resets.

I have to turn off and restart my arduino to make it run back again.

Why is this Happening ?

My Connection -
Arduino is connected to ethernet shield as usual. Arduino is powerred with my Desktop PC. Relay Board is powerred with a 12V External supply and it's ground is connected to the GND Pin of Ethernet Shield.
Light Bulb is connected to 220V supply and Relay 1 (of relay board) is connected as a Switch of Light Bulb (Using NO and COM Pins)

Please Help

Thanks!

You could try the below test code to see if you have the same issues. You can disregard the servo part of the code as it should have no effect on operating the relay.

//zoomkat 7-6-13
//simple button GET for servo and pin 5
//for use with IDE 1.0 or later
//open serial monitor to see what the arduino receives
//use the \ slash to escape the " in the html, or use ' instead of " 
//address will look like http://192.168.1.102:84 when submited
//for use with W5100 based ethernet shields
//includes F() macro to save memory space

#include <SPI.h>
#include <Ethernet.h>
#include <Servo.h> 
Servo myservo;  // create servo object to control a servo 

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 102 }; // 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(5, OUTPUT); //pin selected to control
  //start Ethernet
  Ethernet.begin(mac, ip, gateway, gateway, subnet);
  server.begin();

  myservo.write(90); //set initial servo position if desired
  myservo.attach(7);  //the pin for the servo control
  //enable serial data print 
  Serial.begin(9600); 
  Serial.println(F("server servo/pin 5 test 1.0")); // 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 

          client.println(F("HTTP/1.1 200 OK")); //send new page
          client.println(F("Content-Type: text/html"));
          client.println();

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

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

          client.println(F("</BODY>"));
          client.println(F("</HTML>"));
 
          delay(1);
          //stopping client
          client.stop();

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

        }
      }
    }
  }
}

@ZOOMKAT there is a problem in your sketch.
When I Click on OFF.... Relay just Blink and then Stays ON.

It never turns OFF
Please check it

Does zoomkat's code show it is turning the relay on again on the serial monitor? Like this?

Led off
Led on

Or does it show just "Led off" and the relay stays on?

This is what Serial Monitors Shows :-

server servo/pin 5 test 1.0
GET / HTTP/1.1

GET /favicon.ico HTTP/1.1

Led On
GET /?off HTTP/1.1

Led Off
GET /favicon.ico HTTP/1.1

Led On
GET /?off HTTP/1.1

Led Off
GET /favicon.ico HTTP/1.1

Led On

When click on OFF it gets of half a second and gets back ON automatically.

This is why:

GET /?off HTTP/1.1

Led Off
GET /favicon.ico HTTP/1.1

Led On

the file favicon.ico has "on" in it. Add the question mark to the search.

          if(readString.indexOf("?on") >0)//checks for on
          {
            myservo.write(40);
            digitalWrite(5, HIGH);    // set pin 5 high
            Serial.println(F("Led On"));
          }
          if(readString.indexOf("?off") >0)//checks for off
          {
            myservo.write(140);
            digitalWrite(5, LOW);    // set pin 5 low
            Serial.println(F("Led Off"));
          }

Deja vu! Try the below which uses “on1” instead of “on” to avoid the “icon” issue.

//zoomkat 7-6-13
//simple button GET for servo and pin 5
//for use with IDE 1.0 or later
//open serial monitor to see what the arduino receives
//use the \ slash to escape the " in the html, or use ' instead of " 
//address will look like http://192.168.1.102:84 when submited
//for use with W5100 based ethernet shields
//includes F() macro to save memory space

#include <SPI.h>
#include <Ethernet.h>
#include <Servo.h> 
Servo myservo;  // create servo object to control a servo 

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 102 }; // 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(5, OUTPUT); //pin selected to control
  //start Ethernet
  Ethernet.begin(mac, ip, gateway, gateway, subnet);
  server.begin();

  myservo.write(90); //set initial servo position if desired
  myservo.attach(7);  //the pin for the servo control
  //enable serial data print 
  Serial.begin(9600); 
  Serial.println(F("server servo/pin 5 test 1.0")); // 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 

          client.println(F("HTTP/1.1 200 OK")); //send new page
          client.println(F("Content-Type: text/html"));
          client.println();

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

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

          client.println(F("</BODY>"));
          client.println(F("</HTML>"));
 
          delay(1);
          //stopping client
          client.stop();

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

        }
      }
    }
  }
}

Stll Hangin! :frowning: :frowning:

Akshaysarraf:
Stll Hangin! :frowning: :frowning:

Still hanging the same way?

GET /?off HTTP/1.1

Led Off
GET /favicon.ico HTTP/1.1

Led On

Or is the serial monitor showing a different pattern now? Does it show it is supposed to be off and is still on?

No, the program works fine but My Board still hangs… when I connect my relay board to 220V volts.

What to do, to make it stop hanging ?

Have you tried the sketch without the 220v and light connected? Does it hang then?
Have you tried another voltage and device on the relay?