Strage Problem with power supply

Hi all,

Here is a really strange problem that i have with my arduino setup. I have created a sketch that sends GET messages to a php page and it has a PIR sensor, a temperature sensor, a relay and an ethernet shield connected. Here is the problem now:

I use the Relay in order to control my garden's lights and works perfectly when testing it inside my house. When i try to install it on an outdoor box and connect the power supply to the relays, the arduino hangs after a couple of minutes (i can ping it but i cannot control it).

Has anyone experienced a similar issue? I use the exact same setup, the only difference is the power supply line and the fact that the relay has 220v input while inside the house hasn't

Thank you!!

Must be "relay season" lol

A few recent posts also with relay issues.
In most cases it is simply not enough current supplied to the whole set up or trying to drive them directly from an Arduino pin which has a limit of 40 mA when most relays need 70 or more (unless its an SSR).

You should do a full mock up and make sure you have enough voltage and current to run the whole thing reliably before deploying it.

Try not to supply more than 10 volts to the Arduino itself and that will make the board last longer.
In some cases it may be better to give the relays thier own supply with just a common ground back to the Arduino.

So why does the set up work when there is no 220v input on the relay? If there is a power supply issue the problem would appear in both cases!!

When 220v are connected to the relay it only works for 20 minutes or less

Maybe "cross-talk" from the AC supply is injecting undesired voltages into the arduino via the coil supply leads. Suggest you try a transient suppressor across the relay coil, say 100ohms in series with a 0.1uF capacitor.

Have no idea what you just said!:slight_smile:

That's OK.

Let's have a circuit diagram of your setup, and a picture, taken in full outdoor daylight but not sun with a decent camera. That is, not in the dingy shadows of your workroom.

And the specifications (web links) of each of your parts, especially the relay board.

Today i used a different power line, and did some additional testing without the 220v connected on the relay and had the same issue.

So i`m thinking the issue might not be the power supply. It could be the code, and the fact that the wifi connection (using a repeater )might be a bit slow. I have been "playing" with the sketch for the past day, with no result. I have tried differnt arduino devices, relays, sensors, power supplies, repeaters and so on. I have increased free memory on the sketch (a different version of the code was using a character buffer, millis, etc).

So... i will upload the sketch and wait for your help:

#include <avr/wdt.h>
#include "DHT.h"
#include <Ethernet.h>
#include <SPI.h>

byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x01 }; // RESERVED MAC ADDRESS

int aisthKinPin = 10; //Aisthitiras Kinisis
int valKin = 0;

byte ip[] = { 192, 168, 42, 59 };                      // ip in lan (that's what you need to use in your browser. ("192.168.1.178")
byte gw[] = {192,168,42,5};
byte subnet[] = { 255, 255, 255, 0 };                  //subnet mask
byte server[] = { 192, 168, 42, 21  }; // Server IP

const char comp[] PROGMEM = {"!01"}; //Tha xrisimopoihthei apo ton parser
boolean pars = false; //Otan ginei true tote arxizei na katagrafei tous xaraktires sto readString
boolean enableAlarm = false;

#define REAP 2 //Repeater
#define RELAY2 3 //Seirina
#define DHTPIN 5 // SENSOR PIN
#define RELAY3 6 //Sintribani 
#define RELAY4 7 //Fwta 1,2
#define Led 8
#define RELAY5 9 //Fwta 3

EthernetClient client;

#define DHTTYPE DHT22 // SENSOR TYPE - THE ADAFRUIT LIBRARY OFFERS SUPPORT FOR MORE MODELS
DHT dht(DHTPIN, DHTTYPE);

unsigned long count = 100000000;

float t = 0;	// TEMPERATURE VAR
float h = 0;	// HUMIDITY VAR
int alarmBol=0;

void setup() { 

  pinMode (REAP, OUTPUT);
  pinMode (RELAY2, OUTPUT);
  pinMode (RELAY3, OUTPUT);
  pinMode (RELAY4, OUTPUT);
  pinMode (RELAY5, OUTPUT);
  pinMode (Led, OUTPUT);
  pinMode(4, OUTPUT);            // SD select pin
    
  Serial.begin(9600);
  wdt_enable(WDTO_8S);
  wdt_reset();
  Serial.println(MCUSR);
  Serial.println(WDTCSR);
  Serial.flush();
  //wdt_reset();
  
  Ethernet.begin(mac, ip, gw, gw, subnet);

  dht.begin(); 
  delay(500); // GIVE THE SENSOR SOME TIME TO START
 //  wdt_reset();
  h = dht.readHumidity(); 
  t = dht.readTemperature(); 

}


void loop(){
  boolean notPostTemp=true;
  alarmBol=0;
  wdt_reset();
  Serial.println(t);
 
 int serialByte = Serial.read();
 
  if(serialByte=='A')
  {
    Serial.println("Reset WDT");
    wdt_reset();
  }
  else if(serialByte=='Z')
  {
    wdt_enable(WDTO_15MS);
  }

  valKin = digitalRead(aisthKinPin);
       
 //char charBuf[7];

 digitalWrite (Led, HIGH);
  wdt_reset();
 
    wdt_reset();

delay(100);

  if(count> 7200) { // READ ONLY ONCE PER INTERVAL

    h = dht.readHumidity();
    t = dht.readTemperature();
    //Serial.println("Arxizei to connect:");
     wdt_reset();
  if (client.connect(server,80)) { // REPLACE WITH YOUR SERVER ADDRESS
    //Serial.println("Connected");
    client.print("GET /writeSql2.php?"); 
    delay(20);
    //Serial.print("GET /writeSql2.php?");
    client.print("temp2=");
    delay(20);    
    //Serial.print("temp2=");
    client.print(t);
    delay(20);
    //Serial.print(t);
    client.print("&hum2=");
    delay(20);
    //Serial.print("&hum2=");
    client.print(h);
    delay(20);
    //Serial.print(h);
    client.println(" HTTP/1.1");
    delay(20);
    //Serial.println(" HTTP/1.1");
    client.println("Host: 192.168.42.21" );
    delay(20);
     wdt_reset();
    //Serial.println("Host: 192.168.42.21" );
    client.println("Content-Type: application/x-www-form-urlencoded" );
    delay(20);
    //Serial.println("Content-Type: application/x-www-form-urlencoded" );
    client.println( "Connection: close" );
    delay(20);
    //Serial.println( "Connection: close" );
    client.println();
    delay(20);
    //Serial.println();
    delay(20);
    client.println();
    //Serial.println();
    
  } 
    delay(20);
    client.stop();  // DISCONNECT FROM THE SERVER
    //Serial.println("Client Stop");
  //      resetFunc(); 
  count=0;
  notPostTemp=false; 
}

if (notPostTemp){
if (client.connect(server,80)) { // REPLACE WITH YOUR SERVER ADDRESS

  if(valKin==1) {
    alarmBol=1;
      }

    //alarmBol=1;
    //Serial.println("Connected");
    client.print("GET /alarmSqlAuli.php?"); 
    delay(20);
    //Serial.print("GET /alarmSqlAuli.php?");
    delay(20);
    client.print("alarm1=");
    delay(20);
    //Serial.print("alarm1=");
    client.print(alarmBol);
    delay(20);
    wdt_reset();
    //Serial.print(alarmBol);
    client.println(" HTTP/1.1");
    delay(20);
    //Serial.println(" HTTP/1.1");
    delay(20);
    client.println("Host: 192.168.42.21" );
    delay(20);
    //Serial.println("Host: 192.168.42.21" );
    client.println("Content-Type: application/x-www-form-urlencoded" );
    delay(20);
    //Serial.println("Content-Type: application/x-www-form-urlencoded" );
    client.println( "Connection: close" );
    delay(20);
    //Serial.println( "Connection: close" );
    client.println();
    delay(20);
    //Serial.println();
    client.println();
    delay(20);
    //Serial.println();
    }


wdt_reset();

delay(300);
// wdt_reset();
 int countClient=0;
while(client.connected()) {
  if (client.available()) {
    char c = client.read();
      
         if (c==comp[0]) {
          pars=true;
          
         // Serial.println(pars);
               }
       if(pars) {
          
          if((c==comp[1])&&(countClient==1)){
        digitalWrite(RELAY4, HIGH);
        digitalWrite(RELAY5, HIGH);
                }
            if((c==comp[2])&&(countClient==1)){
    //  Serial.print("Anoixto Fws");
        digitalWrite(RELAY4, LOW);
        digitalWrite(RELAY5, LOW);
        }

            if((c==comp[2])&&(countClient==1)&&(enableAlarm)){
    //  Serial.print("Xtipise sunagermosfwta");
        digitalWrite(RELAY4, LOW);
        digitalWrite(RELAY5, LOW);
        digitalWrite(RELAY2, LOW);
             }
            if((c==comp[2])&&(countClient==3)) {
      enableAlarm=true;
    //  Serial.println("Sunagermos Energos");
     }
      if((c==comp[1])&&(countClient==3)) {
      enableAlarm=false;
   //   Serial.println("Sunagermos Anenergos");
     }
           if((c==comp[2])&&(countClient==4)){
 //     Serial.print("Anapse Sirina");
        digitalWrite(RELAY2, LOW);
                 }
                 
    if((c==comp[1])&&(countClient==4)){
 //     Serial.print("Esbise Sirina");
        digitalWrite(RELAY2, HIGH);
                 }
                 
           if((c==comp[2])&&(countClient==5)){
    //  Serial.print("Anoixto Syntribani");
        digitalWrite(RELAY3, LOW);
//        wdt_reset();
        }
  if((c==comp[1])&&(countClient==5)){
    //  Serial.print("Anoixto Syntribani");
        digitalWrite(RELAY3, HIGH);
        wdt_reset();
        }
        countClient++;
 
       
              }
       }
}
 pars=false;
client.stop();
//Serial.println(readString); 
Serial.println("EDW");

// wdt_reset();

digitalWrite (Led, LOW);

//  wdt_reset();
  
  delay(300);  

//    wdt_reset();
 //Serial.print(charBuf[i]);

    pars=false;
    client.stop();  // DISCONNECT FROM THE SERVER
    //Serial.println("Client Stop");
   
//    wdt_reset();
}

 digitalWrite (Led, LOW);

delay(300);
//  wdt_reset();

//client.flush();
//client.stop();

//readString.remove(7);

client.flush();

count++;

    
}

//	delay(300000); // WAIT FIVE MINUTES BEFORE SENDING AGAIN

I have made a lot of changes and lost track. As you can see i use an Ethernet Shield, a DHT sensor, PIR sensor and a relay. The code crashes after a while (if watchdog is not activated) or keeps reseting (wathdog) which in a way allows the code to work...but keeps reseting the relay too...creating issues to the device connected to the relay (power off and on every minute).

So the arduino connects to a php page and posts temperature data, pir sensor data and reads the values of that page regarding the status of the relays (reads the web page and waits for the "!" character. Once found it parses the rest of the characters and depending on the values it handles the relays. So the webpage looks like this !10000 which means that RELAY4 and 5 should be switched on (Relay4 and 5 = lights, Relay2=siren, Relay3=water pump.

A similar version of the code is used on different arduinos across my house and work ok, however they are connected the network using a lan cable and not a repeater.

Do you have any suggestions with the code? Thank you!!

Hi again,

as i said before the watchdog keeps reseting the arduino and the relays. I could leave the sketch like this if there was only a way of not changing the status of the relay whent the arduino resets (e.g while relay 1 is on and reset occures it instantly goes off and on again).

Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Can you please post a picture of your project?

manolisk:
So why does the set up work when there is no 220v input on the relay? If there is a power supply issue the problem would appear in both cases!!

When 220v are connected to the relay it only works for 20 minutes or less

This basically proves you have a 220Vac switching problem.

  • What are you switching with the relays?
  • Have you got the 220Vac wires WELL away from any of the Arduino?
  • What model Arduino are you using?
  • How do you power the Arduino in the garden?
  • Does the problem appear to occur when one of the relays is being activated or de-activated?

Thanks.. Tom.. :slight_smile:

TomGeorge:
Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Can you please post a picture of your project?This basically proves you have a 220Vac switching problem.

  • What are you switching with the relays?
  • Have you got the 220Vac wires WELL away from any of the Arduino?
  • What model Arduino are you using?
  • How do you power the Arduino in the garden?
  • Does the problem appear to occur when one of the relays is being activated or de-activated?

Thanks.. Tom.. :slight_smile:

I`m switching 2led lights (400w total) Relay 4and Relay 5, 1 led light (200w) Relay 2, a Siren (12v) Relay 2 and a water pump Relay 3(50w)

The 220w wires are not very far away from the arduino (20cm away)

Have tried various power supplies for the arduino: 5v usb supply cable (1amp, 2amp, 2.5 amp) and 12v ones from 0,750amp to 1amp, same behaviour.

Arduino hangs even when the relay is not activated! It happened while I was testing the setup, having all the 220v removed, away from any 220v noise.

I dont have a picture of the final setup because i have uninstalled everything, but i will try to create a cat diagram.

Is it possible that due to the low speed of the wifi connection in the garden connection sockets stay open while the loop tries to make a new one, and in the end the system crashes? Can someone please first of all check to see the code, in case there is a problem there? Memory drain, sockets or anything that could cause a problem?

Not to be treated as a cure for your problem , but with this sort of project it’s worth considering using the watchdog timer to reset your board should it hang for any reason .

Hopefully you are not driving these relays direct from your board , which will overload the power supply . Also the relays should have flyback diodes and be switched via transistors from your digital outputs.
If you are using those Chinese relay ouput modules for EBay etc , be aware that the track spacing is too tight for 220v

If you power the Arduino with a 12volt supply, then the 5volt pin can only power ONE relay at the time.
TWO relays at the time will definately shut down the onboard 5volt regulator (reboot).

A 5volt cellphone supply on the USB socket SHOULD be able to sustain four or five relays, if nothing else is powered from the Arduino.
A much larger than 500mA phone charger is not going to help, because of a 500mA inline USB fuse on the Arduino.
If you use an 8-channel relay board, then you could (should) power that separately.
The JD-VCC jumper must be removed, and relay power connected to JD-VCC (not VCC) and relay ground.
The Arduino must connect to VCC (5volt) and the inputs, but NOT to relay ground.
The relay contact side likely needs snubber circuits (AC) or diodes across the loads (DC).
You have been asked to provide a circuit diagram.
I would suggest you do so if you want to solve this.
Leo..

Hi,
What is the RSSI reading for your WiFi link?

Tom.. :slight_smile:

hammy:
Not to be treated as a cure for your problem , but with this sort of project it’s worth considering using the watchdog timer to reset your board should it hang for any reason .

Hopefully you are not driving these relays direct from your board , which will overload the power supply . Also the relays should have flyback diodes and be switched via transistors from your digital outputs.
If you are using those Chinese relay ouput modules for EBay etc , be aware that the track spacing is too tight for 220v

Yup ... i am (driving those relays directly from my 5v arduino output)! I just used an external power source to see if it is better. Will let you know! Thank you all for your suggestions....will answer your questions soon!

So still no CAD to post. I added exernal power and also changed the relay. Im still having the same problem. Completly removed 220v from relay and all relay wiring to the arduino....same problem. Im guessing if everything is ok with the code then there must be a problem with the arduino or the shield. So i ordered a new set...

Hi,

Don't worry about CAD, use a pen and paper and photograph your schematic.

Tom.... :slight_smile:

Dear all, here is an image of my circuit created on fritzing:

Instead of a 9v battery i have a 5v power supply (JD-VCC) for the relay and the temperature sensor is an AM2302. I hope it will help you understand my project!

I power up the arduino board using the usb cable (2amp)

TomGeorge:
Hi,
What is the RSSI reading for your WiFi link?

Tom.. :slight_smile:

No dBm value is shown on the repeater used. It is described in %: between 75% and 90% most of the time!

Hi,
OPs circuit.


I'm sorry but Fritzy pictures are not circuit diagrams, there are no pin labels or power supply details and the "symbols" are compromises of actual hardware.
Do you really have that relay assembly, are you really trying to power everything off a 9V smoke detector battery?
Where is the gnd or Vcc refrence for the signals controlling the relays?
Do you have a series current limit resistor with your LED?

Please use a pen and paper and draw a schematic, also can you post a picture of your project so you we can see your layout?

Can you post a link to info/specs on the relays you are using?

Thanks.. Tom.. :slight_smile:

You said that you are using a repeater! I think that the problem might be this:

while(client.connected()) {

.....

}

The wifi connection might be unstable so there is chance that sometimes the loop will continue nonstop. Test it using println statements and fix it by adding smt like that:

int countLoop=0;
while((client.connected()&&countLoop<100)){

countLoop++;

.....
}

(depending on the max looping time required).