# Relay for 12volt solenoid

**URL:** <https://forum.arduino.cc/t/relay-for-12volt-solenoid/993656>\
**Category:** Motors, Mechanics, Power and CNC\
**Created:** [May 19, 2022, 9:49pm UTC](https://forum.arduino.cc/t/relay-for-12volt-solenoid/993656 "2022-05-19T21:49:46Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![guywhobuilds](https://avatars.discourse-cdn.com/v4/letter/g/a698b9/32.png) [@guywhobuilds](https://forum.arduino.cc/u/guywhobuilds)\
**Post date:** [May 19, 2022, 9:49pm UTC](https://forum.arduino.cc/t/relay-for-12volt-solenoid/993656/1 "2022-05-19T21:49:46Z")

</div>

Hey all. I’m fairly new to this. I’m using an arduino to control a relay that activates a 12v solenoid valve. I will include my circuits below. The circuit works fine when the relay turns on, but as soon as it shuts off the code crashes. I’ve read about voltage spikes and snubber circuits. Can someone give me advice or a diagram on how to build one and where to put it in? Thanks in advance.

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/1/a/1/1a14c60986481aa2e16b317ff1726987d00de6eb.jpeg)

---

<div class="post-metadata">

**Author:** ![Koepel](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/koepel/32/637546_2.png) [@Koepel](https://forum.arduino.cc/u/Koepel)\
**Post date:** [May 19, 2022, 9:58pm UTC](https://forum.arduino.cc/t/relay-for-12volt-solenoid/993656/2 "2022-05-19T21:58:25Z")

</div>

Welcome to the forum.

Can you give more information ?  
Which Arduino board do you use, which relay module (with a link to where you bought it). Which solenoid is it ? Does it run at 120V AC ? What kind of separate power supply ? How is the Arduino powered ? and so on, and so on.

The picture rotated:  
 ![rotated](https://europe1.discourse-cdn.com/arduino/original/4X/2/c/0/2c0784c878e35a65f3fbccd61bf84eee16e3c359.jpeg)

---

<div class="post-metadata">

**Author:** ![cncnotes](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/cncnotes/32/1098836_2.png) [@cncnotes](https://forum.arduino.cc/u/cncnotes)\
**Post date:** [May 19, 2022, 9:58pm UTC](https://forum.arduino.cc/t/relay-for-12volt-solenoid/993656/3 "2022-05-19T21:58:39Z")

</div>

Typically, a diode is placed across the relay coil contacts.

---

<div class="post-metadata">

**Author:** ![guywhobuilds](https://avatars.discourse-cdn.com/v4/letter/g/a698b9/32.png) [@guywhobuilds](https://forum.arduino.cc/u/guywhobuilds)\
**Post date:** [May 19, 2022, 10:13pm UTC](https://forum.arduino.cc/t/relay-for-12volt-solenoid/993656/4 "2022-05-19T22:13:31Z")

</div>

Here is the link to the solenoid. It’s a 12V DC. I currently have an adapter plugged into a 120AC outlet that converts to 12vDC. [Amazon.com](https://www.amazon.com/4inch-Normally-Closed-Electric-Solenoid/dp/B074Z5SDG3/ref=asc_df_B074Z5SDG3/?tag=hyprod-20&linkCode=df0&hvadid=198072472254&hvpos=&hvnetw=g&hvrand=17822565350125019731&hvpone=&hvptwo=&hvqmt=&hvdev=m&hvdvcmdl=&hvlocint=&hvlocphy=9029596&hvtargid=pla-360267761983&psc=1)

I’m using an arduino uno. The relay is [https://www.amazon.com/SunFounder-Channel-Shield-Arduino-Raspberry/dp/B00E0NSORY/ref=mp\_s\_a\_1\_12?crid=TB52N0WUEMUT&keywords=relay+for+arduino&qid=1652998208&sprefix=relay+for+%2Caps%2C174&sr=8-12](https://www.amazon.com/SunFounder-Channel-Shield-Arduino-Raspberry/dp/B00E0NSORY/ref=mp_s_a_1_12?crid=TB52N0WUEMUT&keywords=relay+for+arduino&qid=1652998208&sprefix=relay+for+%2Caps%2C174&sr=8-12)

The arduino is powered by a 9v dc power supply. However, it is also plugged into my computer via usb because I need it to relay information to my screen. The 5v power supply powering the relay is a seperate 5v dc power supply

---

<div class="post-metadata">

**Author:** ![guywhobuilds](https://avatars.discourse-cdn.com/v4/letter/g/a698b9/32.png) [@guywhobuilds](https://forum.arduino.cc/u/guywhobuilds)\
**Post date:** [May 19, 2022, 10:14pm UTC](https://forum.arduino.cc/t/relay-for-12volt-solenoid/993656/5 "2022-05-19T22:14:07Z")

</div>

What kind of diode would you use?

---

<div class="post-metadata">

**Author:** ![madmark2150](https://avatars.discourse-cdn.com/v4/letter/m/b487fb/32.png) [@madmark2150](https://forum.arduino.cc/u/madmark2150)\
**Post date:** [May 19, 2022, 10:15pm UTC](https://forum.arduino.cc/t/relay-for-12volt-solenoid/993656/6 "2022-05-19T22:15:07Z")

</div>

1n400x

---

<div class="post-metadata">

**Author:** ![guywhobuilds](https://avatars.discourse-cdn.com/v4/letter/g/a698b9/32.png) [@guywhobuilds](https://forum.arduino.cc/u/guywhobuilds)\
**Post date:** [May 19, 2022, 10:20pm UTC](https://forum.arduino.cc/t/relay-for-12volt-solenoid/993656/7 "2022-05-19T22:20:12Z")

</div>

So to be clear… the bottom right of my picture would be my updated circuit?

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/e/c/a/eca56057b7dfdc4f785389a012c47dc1254fc792.jpeg)

---

<div class="post-metadata">

**Author:** ![madmark2150](https://avatars.discourse-cdn.com/v4/letter/m/b487fb/32.png) [@madmark2150](https://forum.arduino.cc/u/madmark2150)\
**Post date:** [May 19, 2022, 11:24pm UTC](https://forum.arduino.cc/t/relay-for-12volt-solenoid/993656/8 "2022-05-19T23:24:28Z")

</div>

The diode goes in BACKWARDS with the cathode connected to the high side. This is a shunt diode that will short out the inductive kick when the field collapses as the relay/solenoid turns OFF. This is the same principle that a car ignition operates off, the field collapses when the points OPEN, causing the spark to form. The diode prevents this.

---

<div class="post-metadata">

**Author:** ![guywhobuilds](https://avatars.discourse-cdn.com/v4/letter/g/a698b9/32.png) [@guywhobuilds](https://forum.arduino.cc/u/guywhobuilds)\
**Post date:** [May 20, 2022, 12:12am UTC](https://forum.arduino.cc/t/relay-for-12volt-solenoid/993656/10 "2022-05-20T00:12:16Z")

</div>

Interesting. Is it possible for you to add to my diagram so I can be certain? How do I know if I’m connecting the cathode to the high side?

---

<div class="post-metadata">

**Author:** ![Ron\_Blain](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ron_blain/32/1126393_2.png) [@Ron\_Blain](https://forum.arduino.cc/u/Ron_Blain)\
**Post date:** [May 20, 2022, 12:55am UTC](https://forum.arduino.cc/t/relay-for-12volt-solenoid/993656/11 "2022-05-20T00:55:39Z")

</div>

The relay you linked to is a 4 channel relay module. I am seeing a diode at the base of each relay labeled D1, D2, D3 and D4 so I am guessing those are flyback diodes. I would also guess the 4 pin chips are Opto Isolators. The relay module board is designed so it should not be a problem. You may want to consider diodes across your solenoids like a 1N4002.

Ron

---

<div class="post-metadata">

**Author:** ![madmark2150](https://avatars.discourse-cdn.com/v4/letter/m/b487fb/32.png) [@madmark2150](https://forum.arduino.cc/u/madmark2150)\
**Post date:** [May 20, 2022, 1:42am UTC](https://forum.arduino.cc/t/relay-for-12volt-solenoid/993656/12 "2022-05-20T01:42:43Z")

</div>

If he's using a board then there shouldn't be a kickback issue. If it's a naked relay, then diodes are REQUIRED.

The band on the diode is the negative (cathode) end. On the schematic the band is the line and the positive (anode) is the Arrow shape (A for Anode) It should be connected across the relay coil like this schematic shows:

 ![coffee](https://europe1.discourse-cdn.com/arduino/original/4X/b/8/d/b8d10c4e50d24c1417606315dfe48b80135b465b.png)  
_Schematic shows unmarked diode internal to module_

This next type of relay card is a quad, others are very similar, has opto drivers and anti-kickback diodes (seen at lower edge of blue relay cube). If the relay is on a card it most likely HAS a diode. If its a "loose" relay, it NEEDS a diode.

 ![gadget3](https://europe1.discourse-cdn.com/arduino/original/4X/2/3/0/2305904b8d236c2f2d9b184134c082b4ffed909c.png)

---

<div class="post-metadata">

**Author:** ![sterretje](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sterretje/32/391294_2.png) [@sterretje](https://forum.arduino.cc/u/sterretje)\
**Post date:** [May 20, 2022, 3:30am UTC](https://forum.arduino.cc/t/relay-for-12volt-solenoid/993656/13 "2022-05-20T03:30:15Z")

</div>

@guywhobuilds, your topic has been moved to a more suitable location on the forum. _Installation and Troubleshooting_ is not for problems with (nor for advise on) your project 😉 See [About the Installation & Troubleshooting category](https://forum.arduino.cc/t/about-the-installation-troubleshooting-category/847458).

---

<div class="post-metadata">

**Author:** ![JCA34F](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jca34f/32/340148_2.png) [@JCA34F](https://forum.arduino.cc/u/JCA34F)\
**Post date:** [May 20, 2022, 4:36am UTC](https://forum.arduino.cc/t/relay-for-12volt-solenoid/993656/14 "2022-05-20T04:36:32Z")

</div>

[https://www.onsemi.com/pdf/datasheet/1n4001-d.pdf](https://www.onsemi.com/pdf/datasheet/1n4001-d.pdf)  
Relay connections:  
 ![6m95zlV](https://europe1.discourse-cdn.com/arduino/original/4X/a/3/4/a34d6b0cb82bd1e90e91cf0af1918a783dce6404.png)

---

<div class="post-metadata">

**Author:** ![IoT\_hobbyist](https://avatars.discourse-cdn.com/v4/letter/i/e5b9ba/32.png) [@IoT\_hobbyist](https://forum.arduino.cc/u/IoT_hobbyist)\
**Post date:** [May 20, 2022, 4:36am UTC](https://forum.arduino.cc/t/relay-for-12volt-solenoid/993656/15 "2022-05-20T04:36:34Z")

</div>

In the image you drew, you do not connect the GND of Arduino to the GND of the "separate power supply" for relay. Connecting two GNDs together.

---

<div class="post-metadata">

**Author:** ![sterretje](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sterretje/32/391294_2.png) [@sterretje](https://forum.arduino.cc/u/sterretje)\
**Post date:** [May 20, 2022, 7:36am UTC](https://forum.arduino.cc/t/relay-for-12volt-solenoid/993656/16 "2022-05-20T07:36:19Z")

</div>

It's not clear to who you are replying. But in the image of @JCA34F, the grounds should not be connected if one wants isolation. If @guywhobuilds uses the same modules, the GNDs should not be connected.

> [@IoT\_hobbyist](#):
>
> In the image you drew, you do not connect the GND of Arduino to the GND of the "separate power supply" for relay. Connecting two GNDs together.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [November 16, 2022, 7:37am UTC](https://forum.arduino.cc/t/relay-for-12volt-solenoid/993656/17 "2022-11-16T07:37:12Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
