Mains power supply for ATMEGA328P-PU problem

I´m a beginner so bare with me! My project is to use an ATMEGA328P-PU as an interrupt on a mains power line with a 5v relay controlled by pin 13 through a transistor. I have programmed the processor on an Arduino board so that pin 13 goes on after a random time between 1 and 5 seconds and then goes off after a random time between 5 and 10 minutes. This programmed processor has then been used in a simple circuit where the mains line in powers a 12v transformer, rectifier, 1000µf capacitor and 5v voltage regulator. Unfortunately this setup doesn't work with the output on pin 13 either failing to go on, going very briefly on or going on and failing to go off. Everything works fine when I use a battery or the USB power supply from a PC so it must be something with the power supply although it appears to give the correct 5v. I'm guessing there's something I need to do to counter a power surge when switching on the mains despite the capacitor. I did try with a bigger one but it didn't help. What is it?

I would be greatful for any suggestions.

Schematic of your setup would be very helpful.

The 1000uF capacitor might cause a problem. When it starts at zero volts and charges up to its final voltage, it draws a large current. Try the circuit without the capacitor being connected, and then connect the capacitor through a 2200 ohm resistor to slowly charge it, then after two seconds throw a switch to give full power, leaving the resistor shorted by the switch.

Hi,DO NOT turn on your power supply with the 1000uF disconnected.
It will apply unfiltered DC, that is pulsed DC (100 or 120Hz) on the DC line, not desirable.
Do you have 10uF capacitors on the 5V regulator, one from input to gnd and the other output to gnd, connect them physically as close as possible to regulator, this helps to stabilize the regulator and will help regulation enormously. Especially to relay type loads.
If this does not help it sounds like your transformer may not be able to supply enough current, check the 5V output of regulator when it is trying to operate.
Your 1000uF might be a bit low, try 2000uF, or parallel up another 1000uF with the one you have in circuit now.
Is it possible for you to put up a circuit diagram thanks.

Tom

OK that was quite a challenge - I've been working on it since you responded!

AmbiLobe:
The 1000uF capacitor might cause a problem. When it starts at zero volts and charges up to its final voltage, it draws a large current. Try the circuit without the capacitor being connected, and then connect the capacitor through a 2200 ohm resistor to slowly charge it, then after two seconds throw a switch to give full power, leaving the resistor shorted by the switch.

Thanks for replying.

I experimented a bit with different size capacitors bur it didn't seem to make much difference.

Did you forget to put decoupling capacitors for the 328 in your schematic or in your circuit?

You should have something like a 1.0uF and 0.1uF cap decoupling VCC and GND as close to the chip as possible.

TomGeorge:
Hi,DO NOT turn on your power supply with the 1000uF disconnected.
It will apply unfiltered DC, that is pulsed DC (100 or 120Hz) on the DC line, not desirable.
Do you have 10uF capacitors on the 5V regulator, one from input to gnd and the other output to gnd, connect them physically as close as possible to regulator, this helps to stabilize the regulator and will help regulation enormously. Especially to relay type loads.
If this does not help it sounds like your transformer may not be able to supply enough current, check the 5V output of regulator when it is trying to operate.
Your 1000uF might be a bit low, try 2000uF, or parallel up another 1000uF with the one you have in circuit now.
Is it possible for you to put up a circuit diagram thanks.

Tom

Thanks for the response. I'll try your suggestion with the 10 uF capacitors tomorrow, have to turn in now! The output seemed fine at 5v and I did try with the relay disconnected. I also tried with an additional 1000uF capacitor but no help there either.

Thanks.

Didn't forget, didn't know! Which ones go where exactly? 1.0uF between VCC and ground and the other?

Frit:
Didn't forget, didn't know! Which ones go where exactly? 1.0uF between VCC and ground and the other?

Same place. You want them in parallel.

Thanks. Just out of interest is the extra 0.1uF critical? Just seems s bit odd that's all.

Frit:
Thanks. Just out of interest is the extra 0.1uF critical? Just seems s bit odd that's all.

It's more critical than the 1.0uF.

Lower capacitance values decouple higher frequency noise.

On the output of the 7805, there should also be a 100nF ceramic and an electrolytic, value not critical, 10µF-100µF. Put a 100nF ceramic on the input side too. The 1000µF should be fine.

An SCR is going to turn on and stay on, is that what you intended? There also needs to be a diode in parallel with the relay coil, anode to the grounded side (ie, reverse biased when the relay is activated).

There should be several capacitors across the 5V line. A tantalum capacitor of between 1uF and 10uF right at the output of the 7805, and right at the 328 there should be as James says a 0.1uF ceramic and a 1uF electrolytic.

I'd also put a larger capacitor across the rectifier. It will probably be OK at 1000uF, but why run close to the limit? At 1A draw, the max the 7805 will put out, you'll have a lot of ripple going into the 7805. I'd go 2200uF or 3300uF. Well, I don't like a lot of ripple, so I'd likely find a 4700uF 25V cap for the input of the 7805, and put a 0.1uF also across the input side of the 7805.

And forget charging resistors and extra relays and switches. Just design it so the rectifier diodes/bridge rectifier can handle the peak charging current when this is turned on. The transformer itself will limit the peak current at turn on, so just don't use a transformer that is rated for much more than the max current that you need.

Thanks a lot for all the responses. All it took was the first step of adding a 10uF capacitor on the 5v output of the voltage regulator. Other improvements will have to wait for ebay orders to come.

Polymorph, yes that was intentional using a SCR as I thought it might help with the instability and not least I happened to have one. Thanks for the diode tip. I'll stick with the 1000uF capacitor as I don't have bigger values that will fit in the space.

I've learnt something about capacitors. I thought capacitors in parallel could just be added up and a single capacitor was identical to two or more connected in parallel if the sum of their values was the same. I also thought I could place components where they fitted best physically without considering distances. All of these components are on a board 5 x 5 cm.