Issues with 12v and 12v relay to power a pump

So I am doing a project where I make a drinks machine, and I am using pumps to control liquid flow. Everything was working well under 5v, then when powered with 12V the relay behaviour is strange. It sometimes follows the program for a bit, then will stop, sometimes the relay just turns on and off repeatedly.
I am using an ATMega328p with all the normal components for standard use, and the fritzing diagram shows how I have it wired up. The relays that I am using are rated for 12v dc, so I confused as to the issue. Any help with this would be very appreciated.
Thanks in advance.

void setup() {
// put your setup code here, to run once:
pinMode(2, OUTPUT);

void loop() {
// put your main code here, to run repeatedly:
digitalWrite(2, HIGH);
digitalWrite(2, LOW);

And this is the test code.

no resistor for the LED?
what are the specs of your voltage regulator?

do yourself a favour and please read How to get the best out of this forum and add code tags to your post.

The LED is just to simulate a pump so no current limiting resistor is needed, (cause there was no pump in fritzing).
And my voltage regulator is 12v to 5v, its an L7805CV.
Thank you.

do you know how much current the pump draws? could your Arduino be underpowered if the power supply is not able to answer the demand?

Im not sure what the current draw is, but if I remove the relays and just power it from 12v and ground. Then the pump does run at full power. So i dont think it would be an issue with power demand. Im just checking some voltages at the minute with a oscilloscope. Any other ideas or anything I can try?

the idea was that if the current draw is too high, then you might not have enough to drive the coil of your relay from the Arduino pin... may be far fetched..

I am not sure on the current draw of the pumps, however I can say that the power supply is 2A so I feel as though it should be enough. One thing I did just think about is that on the IN pin of the ATMega328p, that will send a 5V signal to the relay, but the relay is a 12v relay, so would that signal also need to be at 12v?

If it’s a small pump the 2A is indeed good enough probably

Can you confirm this is the L version, so aka 78L05? This is a low power part that cannot be expected to power a relay coil from 12V. You want a DC-DC buck converter for this, not a linear regulator. That's a dead end street with your project most likely.

Yes thats right it is the L version. Why does this not work as i expect, because I know that 12v is being stepped down to 5. The regulator is just to put 12v down to 5v for the atmega328p. The 12v supply for the pumps never passes through the regulator. Am I missing something obvious?

Sorry, you're right, I misread your fritzing artwork. Where are the decoupling capacitors on the 328p's power supply? Where is the reservoir cap at the input of the 7805? I'd start by putting e.g. 100uF at the input of the 7805 and e.g. 10uF at its output, and 100nF right next to the 328p's Vcc pins (both of them!). Also consider adding 470nF to the 328p's Reset pin (keep the 10k pullup in place).

Right thank you, do you think u could just add them onto the fritzing diagram, with paint ir something easy, cause im not sure I 100% know what your saying.
Thanks in advance.

@dean19, your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with your project :wink: See About the Installation & Troubleshooting category.

Sorry, no fritzing here. It's a waste of digital space.

It's really simple though:

  • 100uF electrolytic, + pin to 12V, - pin to GND. Mount close to 7805.
  • A 10uF electrolytic or whatever you fancy type of capacitor you have in your parts bin, one pin to the output of your 7805, the other to GND. Mount close to the 7805.
  • 100nF ceramic, one pin to pin 7 of the 328, the other to GND.
  • 100nF ceramic, one pin to pin 20 of the 328, the other to GND.
  • 470nF ceramic, one pin to pin 1 of the 328, the other to GND.

Right no problem. Thank you so much for your help

Can you please draw your circuit with pen(cil) and paper, your Fritzy tells us NOTHING about your power supply or where it is connected?

Firtzy is a picture, not a proper schematic for transferring signal and power supply information.

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:
PS Is there a reason why you are using a 328 IC when a Micro or a Nano would have be easier?

Hi Tom thanks for your reply, the circuit is the same its just connected to a barrel jack from a 12v plug, that is connected to mains supply, where the 12v goes into where the vin pin from arduino is and ground to ground rail.
I used a 328 as i have used nanos before and wanted to try and remove the arduino from the circuit as its sonething i havent done before.
Thanks in advance.

Okay so we are experimenting, good stuff.

But a proper schematic will help with getting us all in the same ballpark.
For example your regulator in Fritzy is a TO-220 cased variant, it has a very different characteristic to the 78L05 which is in a T0-92 case.
A proper schematic will also let you arrange your wiring better.
Pen(cil) and paper is fine.

As @koraks has advised, you need extra bypass caps and they will have to be added to the circuit.

What relay module are you using?
Again Fritzy has let you and us down.

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

Here is the diagram, thank you for your help.

Do you have 2x 22nF at the oscillator pins? That should be 22pF. The 328p most likely won't start like this.
Also it seems like you're holding reset to GND but it should be pulled up to Vcc in order for the microprocessor to start.