• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

turning off Relay hangs my uC

Status
Not open for further replies.

skmdmasud

Member
Hi..
i made a timer using an ATMEGA8 uC and RTC DS1307. it works fine for days without anything connected to the relay. the moment i connect something to the relay for example a transformer which runs my high power led's my uC hangs almost 30% of the time. Most of the times this happens when my relay is turning off which i find very strange.

I have connected a diode 1N4148 (which protects the uC) and a 1KΩ resistor in parallel to the relay. do i need to connect capacitors or something. I believe this should be easy, :confused: just cant figure it out.

Regards.
 

large_ghostman

Well-Known Member
Most Helpful Member
i had something like this happen with a pic i got round it with plenty caps on the rails and good decoupling on the pic power pins
 

alec_t

Well-Known Member
Most Helpful Member
Do you have a snubber across the relay contacts?
 
It sounds like, and bear with me on this one, his relay is being held on by the load.

I'm guessing that if he is able to cut out the relay coil's fly back with a small signal diode, that it is most likely not a very large relay. I'm assuming something like a reed relay. I've seen reed relays where the contacts are simply two very small magnets with similar poles pointing to each other.

It is possible (in theory at least) that if he has a large load connected, that the magnetic field created by the current flowing through the contacts could be keeping it on for a few seconds.
 

Mosaic

Well-Known Member
I presume the 1k Ω is NOT in series with the diode? Also the 1n4148 may be faulty?
Also possible is your diode is not connected closely to the relay but is some distance away which can cause an elevation of your ground if u don't have a good ground plane. If that ground bounce can reach the MCu u could have a prob there.
Anyway you can always use an opto isolator and a TRIAC switch if the prob. hard to find....Could be some kind of ground loop or induced power transient (due to relay arcing) if your circuit is off the same 120V supply as the LED transformer.
 

ronv

Well-Known Member
Most Helpful Member
I think as Alec stated you need a snubber to reduce the short arc when the relay opens. You could try 220 ohms in series with .1Ufd, @ 450 volts across the relay contacts.
 

skmdmasud

Member
Hi..
The circuit is very very simple. I made this drawing. I used a 28pin uC and named it Atmega8 since i did not find it in expressSCH.
timer.png

I also tried 2 different power supply's one of them was a switching power supply.

After yesterdays chat with some forum member i decided to build a optoisolator which will give me the opportunity to learn something new as well.

An optoisolator with a triac is almost bullet proof instead of filtering...hit me if i am wrong:rolleyes:.
 

Mr RB

Well-Known Member
Your PSU looks fine, and I don't think an optoisolator will help any more than the relay already does.

I think it might be the wiring from the mains (contact) side of the relay is inducing noise into your micro's wiring, especially the reset pin circuit (that you did not show).

You could make sure the mains contact wiring is not near the other low voltage wiring, and use a low value resistor to tie the reset pin to Vdd or just connect it to Vdd if you don't have areset button.

Other general rules are to use a 22uF tantalum right on the bottom of the PCB between the micro's Vdd and Vss pins. And a RC snubber on the relay contacts can help but you need to use a large expensive X2 mains rated cap, and a fairly large resistor, so i would leave that as a last resort.
 

skmdmasud

Member
Your PSU looks fine, and I don't think an optoisolator will help any more than the relay already does.

I think it might be the wiring from the mains (contact) side of the relay is inducing noise into your micro's wiring, especially the reset pin circuit (that you did not show).

You could make sure the mains contact wiring is not near the other low voltage wiring, and use a low value resistor to tie the reset pin to Vdd or just connect it to Vdd if you don't have areset button.

Other general rules are to use a 22uF tantalum right on the bottom of the PCB between the micro's Vdd and Vss pins. And a RC snubber on the relay contacts can help but you need to use a large expensive X2 mains rated cap, and a fairly large resistor, so i would leave that as a last resort.
i forgot to show the 1k in the reset pin. I made 2 of this timers, in one of them i have a ceramic 0.1uf at the bottom of the uC VCC and ground. But nothing helps.
 

panic mode

Well-Known Member
your 2n2222 has emitter and collector swapped around.

what is the part number of your relay and what is the load side circuit (voltage, AC or DC, current, inductive or resistive load).
 

bchris

Member
I don't know the specifics of the atmel chips, however there are some generic rules you should follow:

* All unused pins should be tied to the ground via a suitable resistor, configured as outputs and set to logic 0.
* The $RESET$ pin should not be left floating. Use a proper pull up resistor. If you don't use it, disable it.
* Use good quality, low ESR, bypass capacitors on all Vdd pins. I'd go with a 100nF & 10uF pair.
* The Vdd traces should be as thick as possible.
* Utilize a ground power plane.
 

ronv

Well-Known Member
Most Helpful Member
The triac will probably fix it as it turns off when the current goes thru zero.
 

dr pepper

Well-Known Member
Most Helpful Member
Put a 100nf ceramic cap accross the micro supply, and maybe a 47uf electrolytic in parallel with it.
And try another 1n4148 in series with the collector of the tranny and the relay, cathode to the collector, in fact you may be better replacing these diodes with uf4001 ultra fast diodes with 1a rating, esp if its a bigger relay.
 
Last edited:

Mr RB

Well-Known Member
The triac will probably fix it as it turns off when the current goes thru zero.
Agreed, but relays are also fine for switching smallish mains loads and I have a heap of projects using a PIC micro to switch mains loads with a relay, and never had issues, due to good construction.

The OP should be able to use that relay with little problem, if it is wired right. Going to a TRIAC or other option is a fair bit of work and could introduce more things to go wrong.

To the OP; can you show a photo of your layout?
 

dr pepper

Well-Known Member
Most Helpful Member
I missed the fact that the relay is switching a mains load.
The issue could be caused by inductive spikes at the relay contacs, this will probably cause visible flashes at the contacts.
A snubber ought to relieve this, an x rated cap and resistor.
 

panic mode

Well-Known Member
the very first reply was asking just that but OP is not following through
 

skmdmasud

Member
I missed the fact that the relay is switching a mains load.
The issue could be caused by inductive spikes at the relay contacs, this will probably cause visible flashes at the contacts.
A snubber ought to relieve this, an x rated cap and resistor.
I had a relay with transparent body and i did see sparks at the contacts.

I finally made optoisolator circuit following this


I used BTA12 instead of BTA06 (turned out their price was same ;) )

My timer is like a NINJA now its so silent i love it.

I did noticed something, when the MOC3021 is off i can measure 700VAC at my BTA12 pins but the Ampere is almost zero, does not even light up a cell phone charger....wondering why:confused:

Regards.


i guess its due to 0.01uf cap...
 
Last edited:
Status
Not open for further replies.

EE World Online Articles

Loading
Top