Relay resets the atmega328p

I connected the digital pins of atmega328p to a decoder (74HC138D). This decoder I am using to drive 16 relays module.

It is working all good at zero load.

But when I connect a 12V 60W motor to the relays and operate. It gives the problem.

The problem is: When the relay is operated, during switching on or during switching off, makes the 5V supply go down and resets the atmega328p.

Please suggest me what can I do it avoid this. Thank you.

Inductive loads need switching spike snubbing.

Show us a good schematic of your circuit.

Show us a good image of your ‘actual’ wiring.

Give links to components.

Hi, @sgadi
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".

To add code please click this link;

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Please include pin labels and your power supplies.

Thanks.. Tom... :grinning: :+1: :coffee: :australia:

You haven’t said whether you have the mandatory free-wheel diodes across the motors, nor whether your 5V supply comes from the 12V supply, nor whether the 12V supply is dipping under load, etc etc.

Circuit please.


Thank you @LarryD , @TomGeorge, and @MarkT for your replies.

I am sorry for not providing the schematics. I thought it would be easy with explanation.

Here are the schematics of the digital electronics part. (290.4 KB)

The output of relays is connected to the 16-channel relay module. I am not having its schematics. I brough this from internet. Here are some photos of the 16-channel-relay module.

I don’t have its schematics, but it has the following components:
ULN2803APG, DP817C909F

The above works well when nothing is connected.
However, when I connect the following pump which are 12V 60W, the problem arises.

Some information

  1. 12V supply to pump and 5V supply to the ATMEGA328p are from different power sources. But share the same ground.
  2. I don’t have free-wheel diode across motors

Right now, I don’t have wiring photo of the pumps connected but I will hand draw to show here.

I don’t see why the Arduino needs ground from the 12V power supply.

In the powersupply configuration you have there, the pump powersupply gnd does not need to be connected to the Arduino gnd.

Can you post links to data/specs of your 12V and 5V power supplies.

Why do you need 12V to go to the “Board”, is that your controller?

Shouldn’t everything operate off the 5V you are supplying from the other powersupply?

Sorry but I find your CAD schematic very difficult to read with all its many pages.

Have you got many bypass capacitors on your board?
You really need to provide a CONNECTED diagram of your board so we can see signal and power flow.
These NET type schematics are easy for PCB design, but a nightmare for troubleshooting.
I see 5 sheets of circuit that could be put on ONE sheet.

Tom… :grinning: :coffee: :coffee: :australia:

Watch this:

Hi @wildbill , @TomGeorge ,

I am using 12V for multi-coin acceptor. The coin acceptor generates pulses of 5V when we connect a pull up resistance to 5V. However, I removed this 12V connector to the board, still the problem exists.

@TomGeorge , Yeah, I tried to keep the schematic easy to draw but it is difficult to troubleshoot.

However, I see it is working perfectly when no load is connected to the relays. So, the problem is with the relay side. I don’t have schematics of the 16-channel relay module.

For power supplies, I am using 12V, 10A and 5V, 1.8A.

@LarryD , This is an amazing video. I didn’t use the diode and it must be causing the inductive spiking. I will put a diode like this:

I have following questions:

  1. Will reducing or eliminating the inductive spiking causing from the pumps will solve resetting problem?
  2. Is it good like how I put the diode?
  3. Is a diode (1N4003) of 200 V, 1 A is sufficient?
  4. Is snubber circuit and the diode placed in the proposed diagram is the same? If they are not the same, do I need to use a Snubber circuit? Is Snubber circuit required for a DC system?

Thank you all of you for your time and help.

P.S. Sharing between motor and logic doesn’t usually work well. If you look at the design of a
commercial office printer you will find there are separate supplies for logic and motors. There
is some isolation between them. (couldn’t give you details but I am sure of it).
Simply adding more and more decoupling and filter caps may or may not work. It may be necessary o have two 12V supplies, one for logic, one for motors. The first step in troubleshooting is finding out the feedback is coming from the 110vac powering the 12V supply. Almost certainly this is the case. To verify this you need to obtain a 12V battery to power the logic temporarily
for the test and see if the problem exists when you use a separate battery power source for the
arduino , while powering the motors from the ac powered 12V supply. If the problem does not
exist under those conditions you have verified that the noise is feeding back through 12V P.S.
If you then power the logic from a separate AC powered 12V supply and the problem reappears
then the noise is feeding back through the AC. If the problem does not exist using separate AC
powered 12V power supplies then you have confirmed that the problem was feedback on the
12V DC P.S. rails, which, as I said , you could modify by adding caps , both 100nF decoupling and
large electrolytic filter caps. (large meaning at least 1000uF). It is difficult to predict if this will help.

In post #7 I asked about the links circled, what do they supply 12v to on the board?

Any spikes from the pump could easily end up on the 12V going to the board.

Thanks… Tom… :grinning: :+1: :coffee: :australia:

It will definitely help - but be aware there can be several routes for interference to get to circuitry, its important to use opto-isolation if your relay module provides it too.

Yes, cathode to +ve supply

The diode just needs to be rated for the voltage and current involved, so for a 60W 12V pump that’s 5A, not 1A.

RC-snubbers are for AC. Diodes are simpler for DC.

Can you please post a picture(s) of your project?
So we can see your component layout?

Thanks… Tom… :grinning: :+1: :coffee: :australia:

Thank you all of you. I finally able to solve the problem using a freewheel diode.

@raschemmel , In the future, I will keep in mind to keep power circuit completely isolated from the digital circuit.

@TomGeorge , I am using the 12v for the multi-coin acceptor.

How I had before:

How I have it now … This is working perfectly (as expected).

With those long wires, you are setting yourself up for inductive coupling :wink: .

Good to see you have solved your problem.

Just looking at your PCB, you need a bypass capacitor for each of the “encoder” and “decoder” ICs.
A 0.1uF across the Vcc and gnd of each IC as physically close to that IC as possible.

This is where a decent connected circuit diagram would help.
What are all those IC’s you don’t show in your “schematics”?
You only show 3 ICs, yet I count at least 10 on the PCB?

If the red and black wires are the 12V going in and out to the coin counter, get the two terminals together, side by side.
Running 12V across your PCB just for the counter is also courting problems with inductive noise.
Keep the 12V current trace as short as possible on your PCB.

Tom… :smiley: :+1: :australia:

1 Like

Thank you @LarryD for identifying the problem with the long wires.
Is there a way to nullify the inductance because of these long wires?

Thank you @TomGeorge for explaining the improvements.

This is the actual board for which the schematic I have put before.

How do I put the bypass capacitor? A capacitor very close to the chip with one terminal to VCC and another to ground?

I made 12V line shorter. Thank you.


Yes, keep the tracks as short as possible.

Tom… :smiley: :+1: :coffee: :australia:

1 Like