240V causing trouble

I build a simple project: An RTC module to keep time, An 16x2 LCD screen, and 2 relays. All it does is switch lights on and off in my chicken house every morning. It works perfectly when I test it with the USB cable, or when it is powered by a 12V supply.

The moment the relay switches on, and 240v flow through it, everything goes haywire. The lights go on (as expected), but then the LCD screen starts fading. 10 seconds later it's not readable anymore. Then suddenly it shows garbage, relay switches off, and my code does not run anymore.

I have no idea why this happens, the relay should be able to handle 10A, the lights are less than 250w.

Any help will be greatly appreciated

Without seeing a schematic of exactly how things are wired, I am only guessing here, but it sounds like your power supply is not able to drive the relay coil and the board at the same time. The "fading out" and going to garbage sound like the supply is dropping. Put a voltmeter on the supply you are using and see what happens when it turns on.

How are you powering the relay and what is it's amp draw to activate?

DO NOT power a relay directly off of a pin. You have to use a transistor to switch the relay as the draw is usually more than a pin can handle.

Thanks for the replies.

gpsmikey:
it sounds like your power supply is not able to drive the relay coil and the board at the same time.

What I find strange is that it works when there is no load connected to the relay? I'll try to measure supply this weekend.

pekasus:
How are you powering the relay and what is it's amp draw to activate?

I'm not using a transistor; what kind of transistor do I need? This is all new to me.

gpsmikey:
Without seeing a schematic of exactly how things are wired

You'll get better help if you heed gpsmikey's suggestion to give us a schematic.....

Noise generated by the relay coil?? Make sure it has an RC snubber if it is ac or a diode if it is dc. The snubber is just a capacitor, say .1mfd in series with a resistor, say 100 ohms connected in parallel with the relay coil and works on ac or dc. The mfd and ohms are not very critical, say 2 or 3 to 1 variation from the above values but make sure the capacitor is substantial voltage (I use 600v) and the resistor is several ohms. The diode works on dc only and must be connected so that normally no current flows through it.

gpsmikey's words re overloading the cpu bus sounds more likely.

Sounds like relay contact arcing that's causing the interference because if you remove the 240V load, the problem goes away.

To (hopefully) resolve this, you could use an RC snubber across the contacts. However, I've had good results just using an MOV (make sure its rated for at least 300VAC). Another thing that will help (or resolve this) is using a ferrite core. Just wrap the load line 3 to 5 turns through the hole.

Other solutions (or improvements):

  • Increasing the distance from the Arduino to the relay and load circuit
  • Separate isolated supply for relay coil (very important)
  • Use a zener (rated at the coil voltage) in series with a diode across the relay coil. This will still clamp the flyback voltage, but more importantly it will speed up the movement when the contacts break, thereby reducing contact arc and increase relay life.
  • Opto-isolation of the control circuit

Hi,
Agree it sounds like a EMI (Electromotive Interference) problem.

See: http://arduino-info.wikispaces.com/RelayIsolation

phoxx:
a capacitor, say .1mfd in series with a resistor, say 100 ohms

I see 100 ohms resistors available, but from 0.125W up to 100W. I have no idea what to get. Please help.

dlloyd:
Use a zener (rated at the coil voltage)

Please explain: do I use this in parallel with the RC snubber? What specifications do I need?

Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
In particular, how you are powering the arduino and the associated circuitry.

Can you please post a copy of your sketch, using code tags?
They are made with the </> icon in the reply Menu.
See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

Can you please post a picture of your project?

Thanks.. Tom..... :slight_smile:

if you run an extension cord to the coup and get 220 with the lights off and it dips to 160 when they come on due to power loss in the cord, then your power supply could be dipping.

your description seems to indicate a power issue.
are you grounding to your AC line?

photos of your installation are requested and required.
a sketch of your power distribution with cord size and distance is needed.
detail how you have the grounds.
measure voltage before and after you turn on the lights.

if it is a emf problem then put your relay into a metal box, like an electrical junction box or some such.
put your Arduino and all of that into a second metal box.

Ok, so I've drawn the whole thing. Please see the attachment. The resistor is 100ohm.

I am powering the arduino with one of these: 12V supply

I've tried all morning to clean up and shorten the code, but I keep getting a message that says the message is too long. So for now I'm not posting the code.

But I don't think the problem lies with the code. It works perfectly, until the relay switches on the 240V circuit. The 240V definitely does not drop, I have heaters and incubators that use a lot more power than the lights, and they all work fine.

I increased the distance between the arduino and the relays by about 20cm, made no difference.

I would like to implement the RC snubber as suggested, but I don't know what wattage resistor to buy. I would also like to use the zener as suggested by dlloyd, but I'm not sure how to do that, and what to buy.

I would also like to do the opto-isolation thing, but I have no idea how.

Here's the code:

// 
   
#include <Wire.h>    // I2C-Biblioteek 
#include "RTClib.h"  // RTC-Biblioteek 
RTC_DS1307 RTC;      // RTC Module
#include <OneWire.h>            // OneWire-Biblioteek 
#include <DallasTemperature.h>  // DS18B20-Biblioteek 
#include <LiquidCrystal.h>
LiquidCrystal lcd (7, 8, 9, 10, 11, 12);   //I2C word nie gebruik nie, dws baie drade.
#define DS18B20_PIN 2   // Pin vir die DS18B20 
#define CH1 4           // Relay 1: Hoofligte
#define CH2 14          // Relay 2: LEDs in die kuikenkamer
//variables to keep track of the timing of recent interrupts
unsigned long button_time = 0;  
unsigned long last_button_time = 0; 
int x = 0; // variable to be updated by the interrupt
OneWire oneWire(DS18B20_PIN);          // OneWire verwysing gestel
DallasTemperature sensors(&oneWire);   // DS18B20 initialisering
int ledPin = 13;
volatile byte LigteOverride=0;
void setup(void) {
  // Initialisiere I2C  
  Wire.begin();
    // Initialisiere RTC
  RTC.begin();
  lcd.begin(16, 2);
  Serial.begin(9600);
  // Teks op die rekenaarskerm
  Serial.println("... hier begin ons...");

  pinMode(CH1, OUTPUT); 
  digitalWrite(CH1,LOW);
  
  pinMode(CH2, OUTPUT); 
  digitalWrite(CH2,LOW);
  
  pinMode(ledPin, OUTPUT);

  //attachInterrupt(1, increment, FALLING);
  attachInterrupt(1, increment, CHANGE);
  
  digitalWrite(3, HIGH); // Enable pullup on digital pin 3, interrupt pin 1
  
  // check die RTC 
  if (! RTC.isrunning()) {
    // As hy nie aktief is nie, gee hom die huidige datum en tyd
    RTC.adjust(DateTime(__DATE__, __TIME__));
    Serial.println("RTC has been started and is set to system time.");  
  }
  else Serial.println("RTC is already running.");   

  sensors.begin();  // DS18B20 starten
  
}





void loop()
  {
  
    DateTime now=RTC.now();   // Retrieving current time 
    show_time_and_date(now);  // Output date and time
  
    sensors.requestTemperatures();                 // Temperatuursensor gelees
    show_temperature(sensors.getTempCByIndex(0));  // Temperatuur gegee

    delay(9153); // +-10 Sekondes
  }



// Datum en tyd gegee
void show_time_and_date(DateTime nou){
  
  // Jaar-Maand-dag, weeksdag
  
  
  Serial.print(nou.year(),DEC);
  Serial.print("-");
  if(nou.month()<10)Serial.print(0);
  Serial.print(nou.month(),DEC);
  Serial.print("-");
  if(nou.day()<10)Serial.print(0);
  Serial.print(nou.day(),DEC);
  Serial.print(", ");
 
  Serial.print("   ");
  
  if(nou.hour()<10)Serial.print(0);
  Serial.print(nou.hour(),DEC);
  Serial.print(":");
  if(nou.minute()<10)Serial.print(0);
  Serial.print(nou.minute(),DEC);
  Serial.print(":");
  if(nou.second()<10)Serial.print(0);
  Serial.print(nou.second(),DEC);
  
  bool Ligte=0;
  bool LEDs=0;
  
  word Jaar=nou.year();
  byte Maand=nou.month();
  byte Dag=nou.day();
  byte Uur=nou.hour();
  byte Min=nou.minute();
  
  short AansitMin=180;
  short AfsitMin=414;
  short AfsitMinLED=1000;
  short NouMin= (Uur*60)+Min;

  // Hoe laat moet ligte aangeskakel word?
//14 uur dag								
							

if (Maand== 	2	 && Dag== 	16	) AansitMin=(	4	*60)+	0	;
if (Maand== 	2	 && Dag== 	17	) AansitMin=(	4	*60)+	0	;
if (Maand== 	2	 && Dag== 	18	) AansitMin=(	4	*60)+	0	;
//etc.... I took out the rest, as the message became too long



  // Hoe laat moet ligte afgeskakel word?

//Afgeskakel met sonsopkoms								

if (Maand== 	2	 && Dag== 	16	) AfsitMin=(	05	*60)+	51	;
if (Maand== 	2	 && Dag== 	17	) AfsitMin=(	05	*60)+	52	;
if (Maand== 	2	 && Dag== 	18	) AfsitMin=(	05	*60)+	53	;
//etc.... I took out the rest, as the message became too long


  // Hoe laat moet LEDs in B1 afgeskakel word?
  
//Afgeskakel 1 uur voor Sonondergang								

if (Maand== 	2	 && Dag== 	16	) AfsitMinLED=(	17	*60)+	48	;
if (Maand== 	2	 && Dag== 	17	) AfsitMinLED=(	17	*60)+	47	;
if (Maand== 	2	 && Dag== 	18	) AfsitMinLED=(	17	*60)+	47	;
//etc.... I took out the rest, as the message became too long

// for testing only:
if (Jaar==2016 && Maand==2 && (Dag==14 || Dag==12) && Uur==15)
  {
    AansitMin=((60*15)+45);
    AfsitMin=((60*15)+47);
    AfsitMinLED=((60*15)+48);

  }



  if (NouMin >= AansitMin and NouMin < AfsitMin)
  {
    digitalWrite(ledPin, HIGH);
    digitalWrite(CH1, LOW);
    digitalWrite(CH2, LOW);
    Ligte = 1;
    LEDs = 1;
  }
  else   
  {
    if (LigteOverride)
    {
      digitalWrite(ledPin, HIGH);
      digitalWrite(CH1, LOW);
      digitalWrite(CH2, LOW);
      Ligte = 1;
      LEDs = 1;
    }
    else
    {
      digitalWrite(ledPin, LOW);
      digitalWrite(CH1, HIGH);
      Ligte = 0;
      if (NouMin >= AansitMin and NouMin < AfsitMinLED)
        {
          digitalWrite(CH2, LOW);
          LEDs = 1;
        }
      else
        {
          digitalWrite(CH2, HIGH);
          LEDs = 0;
        }
    }
  }

  short AansitUur=3;
  short AfsitUur=7;
  short AfsitUurLED=17;
  short AansitFraksie=0;
  short AfsitFraksie=0;
  short AfsitFraksieLED=0;
  
  
  AansitUur=int(AansitMin/60);
  AfsitUur=int(AfsitMin/60);
  AfsitUurLED=int(AfsitMinLED/60);
  AansitFraksie=AansitMin-(AansitUur*60);
  AfsitFraksie=AfsitMin-(AfsitUur*60);
  AfsitFraksieLED=AfsitMinLED-(AfsitUurLED*60);
  
  Serial.print("    Ligte=");
  Serial.print(Ligte);
  Serial.print(" LEDs=");
  Serial.print(LEDs);
  Serial.print("  ");
  
  //Serial.print("Aansit Tyd=");
  Serial.print(AansitUur);
  Serial.print(":");
  if (AansitFraksie < 10) Serial.print("0");
  Serial.print(AansitFraksie);
  Serial.print("-");
  
  //Serial.print("  Afsit Tyd=");
  Serial.print(AfsitUur);
  Serial.print(":");
  if (AfsitFraksie < 10) Serial.print("0");
  Serial.print(AfsitFraksie);
  Serial.print("  -");
  
  //Serial.print(" Afsit Tyd LEDs=");
  Serial.print(AfsitUurLED);
  Serial.print(":");
  if (AfsitFraksieLED < 10) Serial.print("0");
  Serial.print(AfsitFraksieLED);
  
  
  Serial.print("   LigteOverride=");
  Serial.print(LigteOverride);
  
  lcd.setCursor(8,0);
  lcd.print("    ");
  
  
  lcd.setCursor(0,0);
  //lcd.print("DATUM: ");
  lcd.print(nou.year(), DEC);
  lcd.print("-");
  lcd.print(nou.month(), DEC);
  lcd.print("-");
  lcd.print(nou.day(), DEC);
  
  if (Uur < 10)
  {
    lcd.setCursor(12,0);
    lcd.print(nou.hour(), DEC);
  }
  else
  {
    lcd.setCursor(11,0);
    lcd.print(nou.hour(), DEC);
  }
  
  lcd.setCursor(13,0);
  lcd.print(":");
  
  lcd.setCursor(14,0);
  if (Min < 10)
   {
     lcd.print("0");
     lcd.print(nou.minute(), DEC);
   }
  else
   {
     lcd.print(nou.minute(), DEC);
   }
  
  int DieTemp=0;
  DieTemp = int(sensors.getTempCByIndex(0));
  
  lcd.setCursor(0,1);
  if (DieTemp<10 && DieTemp>0) lcd.print(" ");
  
  lcd.print(DieTemp);
  //lcd.print(temp(), DEC);
  //lcd.print(" ");
  lcd.print((char)223); //degree sign 
  lcd.print("C");
  lcd.print(" ");
  
  lcd.print(AansitUur);
  lcd.print(":");
  if (AansitFraksie < 10) lcd.print("0");
  lcd.print(AansitFraksie);
  
  lcd.print("-");
  
  lcd.print(AfsitUur);
  lcd.print(":");
  if (AfsitFraksie < 10) lcd.print("0");
  lcd.print(AfsitFraksie);
  
  
  
}

// Temperatuur gegee
void show_temperature(float temp){
  
  Serial.print("   Temperatuur: ");
  Serial.print(temp);
  Serial.print(" ");  // 
  Serial.write(176);  // om die °-teken te wys
  Serial.println("C  ");
  
}

void increment()
{
  
  button_time = millis();
  //check to see if increment() was called in the last 250 milliseconds
  if (button_time - last_button_time < 500)
  {
    x++;
    
  }
  else
  {
    LigteOverride=!LigteOverride;
    if (LigteOverride)
    {
      digitalWrite(ledPin, HIGH);
      digitalWrite(CH1, LOW);
      digitalWrite(CH2, LOW);
    }
    else
    {
      digitalWrite(ledPin, LOW);
      digitalWrite(CH1, HIGH);
      //digitalWrite(CH2, HIGH);
    }
    last_button_time = button_time;
  }
}

I'm pretty sure this is nothing to do with the 240V supply dipping! As you say, you have other items connected to that supply and they all keep working just fine.

Looking at your layout you still don't have a protection diode on the relay side of the arduino unless this is already built into the relay module you're using. If it's not then this will surely damage your Arduino eventually as the high voltage spikes generated as the relay opens are not to be ignored.

What current is required to operate the relay? Measure it. If it's near or exceeds 40mA then your Arduino will die. Just power the relay module board separately (although I do see a separate supply line going to it so maybe you have already covered this? But the voltage regulator on your Arduino is still supplying the power.)

This notwithstanding, you indicate that the setup works fine UNTIL you actually switch some 240V via the relay? And those relay contacts are totally isolated from anything in your setup (I'm assuming this as it's a relay module). Try switching a lower AC voltage temporarily from another transformer to a bulb and see what happens (eg 12V AC and a car bulb).

From what I can see on the diagram looks pretty well set up, perhaps a real life picture would help further analysis.

What you can do also is remove all the stuff for the LCD display, and the code (strip it back to bare essentials which is just reading the temp sensor) and only keeping the relay and see what happens then. Use a sideways copy of your code for your experiments, of course!

Keep at it and posting back here, someone will figure it out (probably you at the end of the day).

Checked your image. The most critical thing at this point is that you're not using a separate power supply for the relay board and you're not using its opto-isolation feature. This is relatively easy to resolve, here's how:
http://forum.arduino.cc/index.php?topic=379303.msg2616349#msg2616349

Additionaly, I've had much success with these. They really make a difference and are very easy to install. Just connect across the COM and NO terminals of your relay. Digi-Key Stock: 22,720

Thanx for the info dlloyd.
I think I will get this: Varistor
I assume this is used in stead of an RC snubber?

And I'm definitely going to get the separate power supply. I tried it earlier, but after seeing your diagram, I know I did it wrong.

I would also like to add the zener diode. I see Rabtron has 95 different ones. Would you please indicate which one I should use?

This 300VAC varistor will probably be a better choice as it will clamp the peak voltage to 385VDC
http://shop.rabtron.co.za/catalog/14mm-varistor-300vac-385vdc-p-2633.html
Yes, these are usually used instead of an RC snubber.

The zener would be this
http://shop.rabtron.co.za/catalog/zener-diode-p-1896.html
However, this would require installation on the relay board.
Note that you may not need to do this, because the separate power supply, opto-isolation and MOV would probably resolve the issue.

Hi Jaz,
Just read through and thought I would add this for you and everyone.
I believe the relay module you are using (goung by your diagram) is this one or one like it.

Relay Module
(sorry if this is not a link, still new at this posting)

if this is so then the board comes with all isolation you should need on the DC side so I am thinking that as said the problem could be a 240v arc. As specialy as your unit works ok when there is no 240.

One thing that bothers me is that you are running all this off the onboard regulator which is not that powerful.
This does not mean that its a problem but I would be carefull.

I notice that the relay board has the ability to isolate the relay power and run it from another 5v source which may be an option but will not fix this problem I think.

Note the above link shows the cct diagram as well as pictures of the actual board but does not give a power consumption.

I would continue allong the lines of interference.
Good luck.

That's the relay I'm using yes.
I just noticed 2 small components that look like the zener diodes dlloyd was talking about...

Hi,

Just to make things clear, does the Display fading etc, occur when you have USB power or 12V power?
If it is only when you use the 12V suppy, then you are overloading the internal arduino 5V regulator.

On USB power, all the 5V current is supplied by the computer.

When you use the power socket you use the 5V regulator on the UNO board, it has to drop 12V to 5V and can only do this at limited currents.
The switching ON of the relays, being suppied by the UNO 5V, will cause an overload, and the regulator will go into thermal shutdown.

I suggest you use a 9V supply and see if that helps, as the volt drop will be lower across the regulator, and so it will dissipate less heat.

Keeping your AC wiring away from the lower voltage DC will minimise AC interference.

Tom..... :slight_smile:
A picture of your project would help a well, thanks.
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png? (Not a fritzy)