-1

I have been developing a product that uses an atmega8a to turn on/off 5vdc relays. The layout is simple: 5v directly to relay coil, coil to npn 2n2222a transistor, transistor to ground, transistor base triggered by arduino pin. A reverse diode is connected on coil to protect from spikes. The atmega8a is working on its internal 8MHz oscillator.

The problem is when i connect a load to the relay's contacts, like a 220v fan or light, and turn on/off the relays, the atmega resets immediately which also obviously turns off the relay. This behavior is seen almost never when no load is connected to the relay. I also have an esp8266 in the same circuit and communicating with atmega through i2c and a third wire for slave (atmega) to start communication with esp. ESP receives it as interrupt and I can see that, only sometimes though, there are too many interrupts that even makes the ESP reset.

I have tried:

  • operating the atmega at 3.3v and 5v, both
  • i have tried many relays, different pieces and different models, sugar cube and g5nb mini relays
  • i have tried using an inductor in line with the load in hope to eliminate some spikes
  • i thought maybe the current requirements weren't being met. so instead of a 5v 1a smps, i used a 5v 2a smps
  • used capacitor and snubber across the relay contacts to limit spikes
  • used an external power adaptor instead of on board smps circuit. This adaptor had more filtering
  • tried using a resistor and even a diode between arduino pin and transistor base
  • switched transistor to a BS170 mosfet
  • thought the track carrying AC was maybe too close to atmega for comfort so i cut the track and used a long enough wire for testing just to make sure this wasn't it
  • added a 1000uF cap on power source

Then I ran out of ideas and came to this forum. I hope someone knows what to do and why my atmega just wont simply turn on relays with loads on it.

Ujjwal Syal
  • 202
  • 2
  • 8
  • 2
    Maybe you need better decoupling and/or layout on your Atmega. – John D Jul 17 '20 at 20:38
  • how much current does the relay coil use? an optocoupler should fix it if it's noise or spikes, but not undervoltage caused by current spikes. – dandavis Jul 17 '20 at 20:38
  • Have you tried powering the ATmega and esp8266 from a battery? Post a photo of your setup. – Bruce Abbott Jul 17 '20 at 20:42
  • Maybe [this answer](https://electronics.stackexchange.com/questions/510674/unstable-relay-when-using-single-power-source/510675#510675) might help. – Andy aka Jul 17 '20 at 21:12
  • @Andyaka tried that as well – Ujjwal Syal Jul 17 '20 at 21:31
  • is there a reason why I should try and external oscillator over an internal? is it worth it? – Ujjwal Syal Jul 17 '20 at 21:31
  • I'm afraid I'm too busy to digest your question but, for info, have a read of https://electronics.stackexchange.com/questions/308379/switching-hv-dc-relay-on-crashes-microcontroller/308416#308416 – TonyM Jul 17 '20 at 21:32
  • You have 3? microcontrollers + relay drive transistor...these modules all require power, and especially a *common ground connection*. The ground strapping between modules is susceptible to ground loops. Can you connect grounds in star fashion? Can you shorten ground connections to reduce loop area? – glen_geek Jul 17 '20 at 21:49
  • a photo of your setup may be informaytive. – Jasen Слава Україні Jul 18 '20 at 04:19

1 Answers1

-1

Given there is NO RESETTING without a load, I offer this.

the wiring to the load will have CONTACT BOUNCE as the relay contacts start to close, and the mechanical inertial results in close/open/close/open a number of times.

Each Opening results in huge changes in current.

Assume 10 amps in 100 nanoseconds.

And as this wire runs near your PCB, o rnear your VDD or near your Ground, you get this induced voltage:

V_induce = [MUo * MUr * LOOP_area/(2 * pi * distance)] * dI/dT

which has these param values:

  • MUo = 4 * PI 1e-7 henry/meter

  • MUr = 1 (for air, copper, aluminum, vacuum, FR-4)

  • Area = 4inches (10cm) by 4 inches

  • Distance = 1 centmeter

  • dI/dT = 10 amps/100 nanoseconds (limited by wiring inductance?)

Substituting MUo and MUr, we can simplify to

  • V_induce = [2e-7 * LOOP_AREA / Distance] * dI/dT

Now let us compute the induced UPSET, from the power_wire (relay controlled) onto the MCU or its VDD/GND"

  • V_induce = [2e-7 * (10cm * 10cm)/1cm] * 1e+8 amps/second

  • V_induce = 2e-7 * 0..01/0.01 * 1e+8

  • V_induce = 20 volts

analogsystemsrf
  • 33,703
  • 2
  • 18
  • 46