Problem with ATMega328P when using 5v relay for piezo buzzer activation

Hi everyone, I am having some trouble with my a project I'm prototyping using an ATMega328P on a thru-hole protoboard in junction with a 4-channel relay board.

I'm testing with a really basic program (similar to the blink program.... I'm just using digital pin 7 for the output) to trigger the relay on and off every 1000 ms. The board that the ATMega is on is regulated to 5v from a 12v battery, and the relays are 5v models, with 12v passing into the common pins. Whenever I attach a small 12v piezo buzzer to the normally open or normally closed pins the ATMega seems to hiccup, and I'm not sure why. I've confirmed that voltage going into the ATMega is NOT dropping below 5.0 volts when the buzzer is running off the 12v battery.

I have a somewhat lengthy video outlining the problem, and was hoping someone wouldn't mind taking a look and offering me some pointers. I'm very new to microcontrollers in general, so I apologize if I'm doing something obviously wrong, but in my experience with 12v relays in the past, there's no reason this shouldn't work. Perhaps I need a diode between digital pin 7 and the trigger on the relay? Here is the video:

Any help would be greatly appreciated!! Thanks everyone! :slight_smile:

Hi,
Can you post your schematic please.
It looks like you have no bypassing on the linear regulator, the electros are okay.
But fit 0.1uF caps at the regulator and at the 5v and gnd pins of the 328.
It looks like the beeper is creating power supply noise that is getting back to the 328.

Also put a 0.1uF on the PCB you have all your 12V connections.

Have you monitored the 5V supply to the 328 while your project is faulting?

Tom... :slight_smile:

Hi Tom! Thanks for the reply! How can I produce a schematic for you? I have never created one before :slight_smile:

I apologize, but I'm not certain what you are saying about the capacitors. I only have a 10uF capacitor between - and + on the rails, and a 100uF capacitor one the 7805 regulator's power in and ground. Since I already have the 10uF capacitor on - and +, where would I install the .1uF capacitor, exactly?

I have made sure that the voltage between the regulator output and the Arduino maintains a solid 5.00 volts when the relay and the buzzer are triggered. I am using a UPS (uninterruptable power supply) battery, used for power backup for computers. It has a 12.4 - 12.5v output at full charge, which is what it has right now. Thanks again Tom!

Hi,
Put a 0.1uF capacitor in parallel with the two you have either side of the 5V reguator.
Put a 0.1uF capacitor across the 5V and gnd pins at the 328.
Put a 0.1uF capacitor across the 12V and gnd on the separate PCB you have to distribute the 12V supply.

Tom.. :slight_smile:

The power wires from the battery can have two star connections on that bare red board (one for + and one for -),
but power and ground between the two boards should co directly to the diode/input cap of the regulator.

Now ground is making a detour past the MCU, and spikes on the supply (from the buzzer) could upset it.

Your regulator needs a small heatsink if you're going to activate more than one relay.
Four relays and the MCU will draw ~350mA, and with a 7-8volt drop from that battery will generate 8*0.35= 2.8watt.
Enough to raise it's temp by 120-150C.
Leo..

Hi,
I have done a basic schematic for you, I haven’t shown what pins you are using for the relay inputs just left open wires.
Note the 0.1uF caps and as @Wawa has suggested about putting the relay output switching power wires direct to the battery.
Bareduino_4Relays.jpg

Tom… :slight_smile:

Thanks again Tom, and thanks Leo!!!

I appreciate the help from both of you, and big thanks to Tom for taking the time to do that schematic for me! I did end up moving my ground coming from my battery to the ground going to the 7805 regulator. I also added a heatsink to the 7805 (I had to install it upside down due to a lack of real estate on my breadboard) as well. I'm testing out the arrangement on my solderless breadboard before I solder everything on my protoboard.

I have a lot to learn and apparently reading schematics, let alone drawing a schematic, is one! I'm hoping I understood the capacitors surrounding the regulator correctly. Tom, would you mind confirming from the pics below if I have things in the proper order, based on your schematic?

Might have to open each picture in a new window to see it larger. I apologize for not being able to see the entire set of rows from A thru J on my breadboard.... I only have my macro lens for my camera handy, so I tried taking a shot from each corner to hopefully show what I have clearly enough.

Here is what I have:

A3: - from 12v battery
A4: - from 12v battery
C3: + of 100uF capacitor (C1)
C4: - of 100uF capacitor (C1)
D3: leg of .1uF capacitor (C2)
D4: other leg of .1uF capacitor (C2)
E3: + jumper to F3
E4: - jumper to F4
F3: + jumper from E3
F4: - jumper from E4
G3: + input to 7805 (U1)
G4: - to 7805 (U1)
G5: + output from 7805 (U1)
H4: leg of .1uF capacitor (C3)
H5: other leg of .1uF capacitor (C3)
I4: - of 10uF capacitor (C4)
I5: + of 10uF capacitor (C4)
J4: jumper to - rail
J5: jumper to + rail

Sorry I had to break it down that way versus simply understanding the schematic, but I hope that's legible enough. The placement of C5 is luckily a no-brainer for me, so no questions there :slight_smile:

Do you mind if I ask what you used to draw the schematic? Would definitely be helpful for me to learn to draw them for future troubleshooting requests, and I'm sure I'll understand better once I draw one or two. I'm trying to learn on the fly so I can build something in time here, so I certainly appreciate the patience you all have with me :slight_smile:

Thanks again,
Andrew

Would anyone pretty please mind confirming if what I have above is correct, per Tom's schematic? Thanks again!! :slight_smile:

AGrayson84:
Would anyone pretty please mind confirming if what I have above is correct, per Tom's schematic? Thanks again!! :slight_smile:

Hi,
Its hard to tell from pictures, but I can't see anything out of place.
Tom... :slight_smile:

Thanks so much, once again Tom! Just wanted to make sure I'm not misunderstanding something and setting myself up for something to burn up :slight_smile: Thanks again, I'll let you know how it does for me!

Hi folks! Just wanted to update everyone that Tom's suggestions with the capacitors, and Wawa's suggestions with the regulator heatsink and re-routing my ground seemed to completely take care of the problem! :slight_smile:

Unfortunately I'm learn that the rapid rate I wanted to pulse 2 of these relays at (75ms duty cycle, for a duration of 5000 ms) is too frequent.... so now I'm exploring perhaps using a set of opto-couplers for passing the incoming 12 volts to the external 12v LED and the 12v buzzer. Back to the drawing board, somewhat, for me, but wanted to thank you both again for you help! I appreciate it an awful lot!

AGrayson84:
Hi folks! Just wanted to update everyone that Tom's suggestions with the capacitors, and Wawa's suggestions with the regulator heatsink and re-routing my ground seemed to completely take care of the problem! :slight_smile:

Unfortunately I'm learn that the rapid rate I wanted to pulse 2 of these relays at (75ms duty cycle, for a duration of 5000 ms) is too frequent.... so now I'm exploring perhaps using a set of opto-couplers for passing the incoming 12 volts to the external 12v LED and the 12v buzzer. Back to the drawing board, somewhat, for me, but wanted to thank you both again for you help! I appreciate it an awful lot!

Physically not possible, but good to hear the major problems are fixed.
Tom.. :slight_smile: