Arduino "getting stuck" when using the 12V power jack for power

Hi all,

First of all, thank you for reading this.

Background
I have a setup in which an Arduino Mega is "interacting" with the following components:

  • 1 12V DC power brick, rated to 3A
  • 2 non-latching relays (max current per = 50mA)
  • 2 non-contact solenoids (max current per = 1.08A)
  • 1 rotary encoder (max current = 10mA)
  • 1 SD card reader (max current = 100mA)
  • 1 character LCD (max current = 10mA)
  • 1 touch IC [MPR121 breakout] (max current = negligible)
  • 3 5mm color LEDs, each connected to a 220Ω resistor (max current per = 10mA)
  • 3 5mm IR LEDs, each connected to a 470Ω resistor (max current per = 5mA)
  • 3 IR receivers [TSOP38238] (max current per = 1mA)

With the exception of the 12V DC power brick and the solenoids, each of the components draw their power from the Arduino—I'm fully aware that this is bad practice, and have designed a PCB to 'offload' some of the power draw to the power brick. However, there's an issue that I feel I need to figure out before proceeding with that plan.

Situation
The setup runs perfectly when the solenoids are powered by the power brick (via the relays) and the Arduino (and subsequently the rest of the components) are powered by my laptop (of course via USB). I decided to run a parallel line from the power brick to Arduino's 12V power-in so that the setup can only be powered via a single power line.

Expectation
I expected the setup to run as it did before I made that change.

Reality/ Issue
The Arduino ran through roughly 10 loops or so of the script before 'getting stuck'—that is, stopping at a part of the script that it's not 'supposed' to stop. I'm at my wit's end, and do not know why this would happen. Please let me know if I need to provide anything else. I've attached a schematic of the setup as well as my scripts.

Thank you again.

Schematic.pdf (416 KB)

V3.4.ino (29.3 KB)

variables.h (2.18 KB)

2 non-latching relays

It is not recommended to connect a relay directly to the Arduino port, unless the current is much lower than the port can offer. The relay is built with a coil, which means that the current has a reactive behavior. Try to use at least a driver.

What is the voltage of the relay coil?

(Power brick = Power Supply?)

I gave you a karma point for a proper schematic and NOT using Fritzing pictures.
Then I wanted to take it away for not reading the sticky post at the top:
When you post code please use code tags as described in Read this before posting a programming question.

Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Most users here will not download your code. Post it as explained above.

But, I don't think the code is your problem since you said that "The setup runs perfectly when the solenoids are powered [separately]".

Did you also run a parallel ground?

rtek1000:
It is not recommended to connect a relay directly to the Arduino port, unless the current is much lower than the port can offer. The relay is built with a coil, which means that the current has a reactive behavior. Try to use at least a driver.

What is the voltage of the relay coil?

(Power brick = Power Supply?)

Thank you for your reply; the coil voltage is 3V.

SteveMann:
I gave you a karma point for a proper schematic and NOT using Fritzing pictures.
Then I wanted to take it away for not reading the sticky post at the top:
When you post code please use code tags as described in Read this before posting a programming question.

Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Most users here will not download your code. Post it as explained above.

But, I don't think the code is your problem since you said that "The setup runs perfectly when the solenoids are powered [separately]".

Did you also run a parallel ground?

Thank you for your response; my code was too long to post as a block sadly.

And, sorry for now knowing this, what's a 'parallel ground'?

ArianKS:
The Arduino ran through roughly 10 loops or so of the script before 'getting stuck'—that is, stopping at a part of the script that it's not 'supposed' to stop. I'm at my wit's end, and do not know why this would happen.

To my mind you have too much hardware and far too much code for effective debugging.

I presume there is an earlier version of the project and code that does work properly - you could not possibly have created all that hardware and 29k of code without a huge amount of step-by-step testing.

What was the most recent version that worked?
What did you then change that caused it to stop working?

...R

Hi,
Ops diagram.

Can you please post a circuit diagram please, showing wire connections, pin and component names and how you have connected the power supplies.

Posting a jpg file is easier for all to read.
Thanks.. Tom.. :slight_smile:

Hi,
Can you post, links to spec/data of your solenoids and relays please?

Thanks.. Tom...

Robin2:
To my mind you have too much hardware and far too much code for effective debugging.

I presume there is an earlier version of the project and code that does work properly - you could not possibly have created all that hardware and 29k of code without a huge amount of step-by-step testing.

What was the most recent version that worked?
What did you then change that caused it to stop working?

...R

Thank you for your response, and my apologies for not clarifying the issue better in the original question.

Situation 1: I have the Arduino powered via USB, and the solenoids powered via the 12V DC power brick. The codes run as expected.

Situation 2: I draw a parallel power (and of course ground) wire from the power brick to the Arduino. This way, the power brick powers both the Arduino (and the connected periphery) in addition to the solenoids. Now, this is where the issue happens, where the Arduino only goes through, let's say, 10 iterations of the loop before 'getting stuck'—that is, not doing anything when it's not 'supposed' to do that.

TomGeorge:
Hi,
Ops diagram.

Can you please post a circuit diagram please, showing wire connections, pin and component names and how you have connected the power supplies.

Posting a jpg file is easier for all to read.
Thanks.. Tom.. :slight_smile:

Thank you for the response! To keep things clean, I've added the pin numbers to the end of the wire connections. Please let me know if that explanation was inadequate.

TomGeorge:
Hi,
Can you post, links to spec/data of your solenoids and relays please?

Thanks.. Tom...

No problem—here's the only link that I currently have:

If that's not adequate, please let me know and I'll try to see what else I can find.

SteveMann:
....
Then I wanted to take it away for not reading the sticky post at the top:
...

Next time, check the file size first :wink: One post can be 9000 characters max.

ArianKS:
Situation 2: I draw a parallel power (and of course ground) wire from the power brick to the Arduino. This way, the power brick powers both the Arduino (and the connected periphery) in addition to the solenoids. Now, this is where the issue happens, where the Arduino only goes through, let's say, 10 iterations of the loop before 'getting stuck'—that is, not doing anything when it's not 'supposed' to do that.

What happens if you power the Arduino from a separate external power supply?

If that works properly (and I expect it will) the problem is probably due to power spikes (or valleys) in the power from the "power brick".

...R

Robin2:
What happens if you power the Arduino from a separate external power supply?

If that works properly (and I expect it will) the problem is probably due to power spikes (or valleys) in the power from the "power brick".

...R

It does work. Which, like you mentioned, could mean that the power brick is not supplying a steady voltage.

But here's the issue: doesn't the Mega have a voltage regulator on board? Does this mean that the voltage spikes (or valleys) could be exceeding the "stabilizing" capacity of the on-board voltage regulator?

If so, would a dedicated bench power supply be a good option?

ArianKS:
It does work. Which, like you mentioned, could mean that the power brick is not supplying a steady voltage.

But here's the issue: doesn't the Mega have a voltage regulator on board? Does this mean that the voltage spikes (or valleys) could be exceeding the "stabilizing" capacity of the on-board voltage regulator?

Taking those two things together the answer to the second part seems to be "YES". But I have no idea why that might be the case. A very wild guess is that there are negative spikes. Maybe a diode would help?

This is a problem beyond my pay grade :slight_smile:

If so, would a dedicated bench power supply be a good option?

I have no idea.

...R

Hmmm...

Almost guarantee this is back emf noise from the relay and solenoid coils.

First step would be to put fly-back diodes across all the relay and solenoid coils. Connect something like a 1N4001 diode with the cathode connected to the positive side of the coil and the anode to the negative side.

If that doesn't fix it try placing another 1N4001 in the supply to the relays and solenoids. The Arduino should be supplied from the 12V supply which then feeds the anode on the 1N4001 and the feed to the relays and solenoids should be taken from the cathode of the 1N4001.

If you still get intermittent glitches add a 2200uF 25V capacitor between the supply to the relays and solenoids and ground.

Hope this helps

Ian

Hi,
What relays are you using?
Part number, link to spec/data would help.

A proper wire connected circuit will help a lot too.
Playing "search a word' can be fun but not here. :slight_smile:

Have you got all your gnds connected AT the power unit and NOT daisy chained from one part to the next?

Thanks... Tom... :slight_smile:

IanCrowe:
Hmmm...

Almost guarantee this is back emf noise from the relay and solenoid coils.

First step would be to put fly-back diodes across all the relay and solenoid coils. Connect something like a 1N4001 diode with the cathode connected to the positive side of the coil and the anode to the negative side.

If that doesn't fix it try placing another 1N4001 in the supply to the relays and solenoids. The Arduino should be supplied from the 12V supply which then feeds the anode on the 1N4001 and the feed to the relays and solenoids should be taken from the cathode of the 1N4001.

If you still get intermittent glitches add a 2200uF 25V capacitor between the supply to the relays and solenoids and ground.

Hope this helps

Ian

Got it, thank you.

I will implement the suggestions and will report back.

TomGeorge:
Hi,
What relays are you using?
Part number, link to spec/data would help.

A proper wire connected circuit will help a lot too.
Playing "search a word' can be fun but not here. :slight_smile:

Have you got all your gnds connected AT the power unit and NOT daisy chained from one part to the next?

Thanks... Tom... :slight_smile:

Got it. I will use EAGLE to create proper schematic—though that might take a little bit of time, my apologies.

In the meantime, here's the data sheet (and a general link) to the relays that I have:

General link: EC2-3NU KEMET | Relays | DigiKey

Data sheet: https://content.kemet.com/datasheets/KEM_R7002_EC2_EE2.pdf

Hi,
Thanks for the relay link.

I hope you are not driving the relay coil directly from the Mega output pin.
That relay is specified as 3V coil 64.3Ohms.
Why use a 3V coil relay in a 5V circuit?
Use DMM to measure coil resistance.

You are using a Mega so 5V output.
Pin Output Current = V / R = 5 / 64.3 = 77mA...
The Mega output pin should not be loaded over 40mA.

Hows about you "draw" a schematic, forget Eagle for the moment and let us see how you have connected everything.

Tom... :slight_smile: