SOLVED: Solenoid woes - causing arduino to freeze up when used via relay (Help!)

[u]SEE UPDATE TOWARDS THE BOTTOM OF THE PAGE[/u]

So I've got a solenoid that I'm trying to control via a relay module. The mega 2560 board & sketch simply turn the solenoid on/off a target number of times per minute (approx 1 Hz). Without the solenoid attached, my board and relay work great and will run for 12hr+ without a hiccup, and I'm sure would run longer if I let it.

When I add my solenoid as the load on my relay module, it only cycles 2-5 times before the arduino hangs/freezes and I have to pull the power to it in order to reset it. I've googled around and found a couple other similar cases, but they just suggest adding a flyback diode (which hasn't fixed the problem). I've tried 2 different relay modules, one "regular" and one with opto-isolation; both producing the same hung arduino after only a few solenoid on/off cycles.

I've got 2 separate power supplies for now (wanted to isolate coil interference, but obviously that's not working. Eventually I want a single power supply if possible). One powers the Arduino, and the other is supplying power to the selonoid which is switched by the relay.

Circuit Diagram:

I've tried a number of things on the load side of the relay (solenoid side) to fix things, none of which have worked:

Any help on what my issue is? I need this working ASAP, and I've been tearing my hair out trying to fix for more than a week.

[u]Parts:[/u] Arduino: Mega 2560 Solenoid: 12v DC solenoid (no good spec sheet) LCD: SainSmart I2C 20x4 LCD Relay Modules tried:

Power supplies: 12v @ 2A wall wart power supply

Hi, it looks like you have tried all the tried and true methods, I'd keep a snubber fitted, but place it across the relay contacts, even though it doesn't fix the problem it will help to minimize arcing and wear and tear of the relay contacts. Have you tried getting the solenoid as far away physically from the arduino and running the solenoid wires from it away from the arduino, it looks like you have an induced spike problem. What are the specifications of the solenoid? I assume its a 12V device, do you have a resistance spec and any inductance specifications? Tom..

  1. What are the specs of the solenoid?

  2. How exactly did you connect the flyback diode?

  3. Keep the area enclosed by the solenoid circuit small, especially in the vicinity of the Arduino. For example, use twisted pair wires to the relay contacts.

  4. 0.047uf is far too small a snubber capacitor. But a flyback diode connected correctly will be more effective than a snubber.

TomGeorge: Hi, it looks like you have tried all the tried and true methods, I'd keep a snubber fitted, but place it across the relay contacts, even though it doesn't fix the problem it will help to minimize arcing and wear and tear of the relay contacts. Have you tried getting the solenoid as far away physically from the arduino and running the solenoid wires from it away from the arduino, it looks like you have an induced spike problem. What are the specifications of the solenoid? I assume its a 12V device, do you have a resistance spec and any inductance specifications? Tom..

@TomGeorge - I wish I could find better specs, but the link I provided up above for the solenoid details is as good as I can get. Is there any way I can test/measure myself to determine better specs beyond the known voltage?

dc42: 1. What are the specs of the solenoid?

  1. How exactly did you connect the flyback diode?

  2. Keep the area enclosed by the solenoid circuit small, especially in the vicinity of the Arduino. For example, use twisted pair wires to the relay contacts.

  3. 0.047uf is far too small a snubber capacitor. But a flyback diode connected correctly will be more effective than a snubber.

@author: 1. See above comment reply 2. The diode is an N4002 that I simply jumped across the relay load screw terminals for prototyping/testing. (cathode to +V side) The same was done with the zener & diode when I tried that method. 3. It has to run out of my enclosure to a semi-remote location (approx 24 inches away). I'll try twisting the solenoid load wires the entire length instead of the first 4 inches or so that currently is twisted and resides inside my enclosure. 4. Any good suggestions for the size I should be using?

Your wiring diagram shows that the relay coil is being powered directly from an output pin. Are you sure the relay's coil current requirement is within the safe ratings of an arduino output pin?

Lefty

The flyback diode needs to be connected across the solenoid, not the relay contacts. Also take note of lefty's comment.

retrolefty: Your wiring diagram shows that the relay coil is being powered directly from an output pin. Are you sure the relay's coil current requirement is within the safe ratings of an arduino output pin?

Lefty

Both modules I've tried claim to be "arduino-ready" (for control directly from IO pins).

The relay works flawlessly for hours without the solenoid attached, so I that leads me to believe there isn't any issues with the relay control.

Do you have access to an oscilloscope? If you want to know what's really going on instead of just guessing, it might help.

TanHadron: Do you have access to an oscilloscope? If you want to know what's really going on instead of just guessing, it might help.

Yes, I have one, but I'm not very good at using it...

That said - here are some images of what's going on. They seem to suggest the flyback diode is working to limit the voltage correctly.

Without the flyback diode in place, voltage is spiking up to 39V or greater from the looks of it (see the cursor line at the top).

Here's a side-by-side showing the flyback diode in use on the right and the voltage peaking at 12V instead of huge spike without diode on the left.

Just for kicks this morning, I disconnected the I2C LCD and it seems to run longer (1 to 3 minutes) before it hangs instead of 5 to 10 seconds with the LDC attached.

I'm going to try rewiring to put the diode as close to the solenoid as possible and twist solenoid wires to to limit EMI.

Those oscilloscope readings were across the solenoid circuit, right? Are the grounds connected? Do you get any spikes on the Digital IO pin or Vcc?

TanHadron: Those oscilloscope readings were across the solenoid circuit, right? Are the grounds connected? Do you get any spikes on the Digital IO pin or Vcc?

Yes, measurements above were taken across the solenoid.

I haven't connected the grounds but I can try that and will post my results.

Haven't monitored the digital IO pins, but I was reading up on using capacitors to help filter noise from the solenoid that I'm guessing is causing the issues. I'm by no means an EE, (I'm a software/computer guy who dabbles into electronics) so my circuits tend to a bit brutish and lacking the polish a proper EE would add.

nullRequest:

TanHadron: Do you have access to an oscilloscope? If you want to know what's really going on instead of just guessing, it might help.

Yes, I have one, but I'm not very good at using it...

That said - here are some images of what's going on. They seem to suggest the flyback diode is working to limit the voltage correctly.

You realise you risked destroying your oscilloscope by looking at inductive spikes like this?

Never switch an inductor without protection if any semiconductor devices are connected to it. The voltage can rise to thousands (usually only limited by the winding insulation or any semiconductor devices).

  1. The diode is an N4002 that I simply jumped across the relay load screw terminals for prototyping/testing. (cathode to +V side) The same was done with the zener & diode when I tried that method.

Do you mean 1N4002? Accuracy is important.

There must be a diode connected across the relay coils as you show in your circuit. Absolutely must. I don't know what your wiring looks like. Big loops of wire may cause problems.

  1. It has to run out of my enclosure to a semi-remote location (approx 24 inches away). I'll try twisting the solenoid load wires the entire length instead of the first 4 inches or so that currently is twisted and resides inside my enclosure.

There should be a diode connected across the solenoid coil, NOT the relay contacts. The first helps, the second does nothing.

Yes, twisted pair should help. A 10nF capacitor across the solenoid along with the diode might be a good idea.

Is that an actual battery, or a power supply of some sort running the solenoid? If batteries, leave the grounds separate. If a power supply, well, it depends on how well the power supply is isolated from AC line voltage. No sense creating ground loops.

  1. Any good suggestions for the size I should be using?

Size of what? The diode across the relay coil only needs to withstand the relay's rated coil current, and voltage. So triple the current and double the voltage for the diode ratings or better and you are good to go.

For the solenoid... How much current is the solenoid rated at? Voltage?

If you mean size of the RC snubber components, I can't speak for this except to say that I found it on the internet:

If I were forced to come up with numbers myself, I'd need to know the current and voltage of the solenoid and so calculate the resistance. I'd perhaps make the R of the RC snubber equal that or perhaps no more than 3x that. Then, finding out the inductance of the solenoid, find the frequency at which the solenoid inductive reactance equals the chosen resistor value, then calculate the capacitor that matches that reactance at the calculated frequency.

The idea being to create a series tuned circuit consisting of the solenoid inductance L and the RC snubber to create a series RLC circuit with a Q of 1 or thereabouts. Thereby limiting the voltage rise when the relay contacts open. Said RC circuit connected across the solenoid, not the relay contacts.

[u]*UPDATE: *[/u]

Well, I thought I had posted a followup to this thread but I'm not sure what happened. Apparently I never submitted it.

Just for anyone in a similar situation, I eventually got things working and cleared up the freezing issue. I simply soldered in the diode closer to the solenoid coil instead of having it essentially right on the relay contacts. There was enough wire between the solenoid and diode (prob 24 inches or better) that I was probably getting some wicked EMF and voltage spike (just guessing).

I know this may have seen like like a noob move, but I'm quite a novice so there you go. After doing a lot more reading, and trying everything else, I resorted to moving the diode closer to the coil and it fixed the issue.

I still think you need to solve the power supply voltage problem. It may work OK now, but what if you put in a fresh 9V battery? Or a more powerful 9V power source?

Hi, NullRequest, please do not go back and edit an earlier posting like you have done your first post.
It has completely disjointed the the flow of q and a in the thread.
Placing SOLVED in the header is good, but if you edit old posts, anyone trying to use this thread as reference will find it difficult to follow.

Glad to see you have solved the problem, pity it took so long.

Tom… :slight_smile:

I soldered a diode between the solenoid terminals, much better but still some occasional interference.

Then added the snubber (0.1 uF +47 ohm) across the relay contacts, no interference at all.

Thanks everyone for the postings, this issue was bothering me a lot and found the solution here.