Using Diodes in circuits with Solenoids

I am using an Arduino Mega 2650 to activate a 5V solenoid valve powered by an external power supply. The activation will be based on the results sent by a Hall Effect sensor. I have created the circuit with diodes as a precaution for when the power supply is shut off. I am fairly new to creating circuits, here are my questions:

  1. Are my diodes placed in the circuit correctly?

  2. Do I need a diode protecting the output of pin 13 from the board?

  3. Are any other precautionary measures needed at this low of voltage?

Solenoid Valve: http://www.smcpneumatics.com/SYJ3120-SMO-M3-F.html

You’ve really placed anyone here trying to help out at a disadvantage by using the wrong parts from Fritzing… since I think most of us are pretty pedantic about being clear and correct when discussing a design.

Right away to me… no relay coil should be driven directly by a pin when a transistor driver could easily be used. Even if it’s just a 5V 40mA coil. Better to blow out a 2 cent transistor than your microcontroller pins.

I realize that these are designed for PLC usage, but even if the part is rated for a current draw: 21 mA at 24VDC, as stated in the technical sheet, you are still best served by using a “sacrificial transistor” because the arduino pins are not open collector. Technically, you could drive this solenoid’s coils from a legacy TTL IC 7405 or 7407 but it seems that the 24V part is pretty much standard… so an open collector solution is rather mandatory. I can’t tell, did you select the 5V coil?

Secondly, your diodes will only control directional current flow… meaning they only protect against plugging the battery in backwards and from the PIN, it only really creates a 0.7 drop in voltage and serve no other purpose.

See my drawing for where the diode goes… (across the solenoid coil pins, in reverse, so no voltage/current will flow under normal conditions)

@pwillard- If one wanted to stick an optoisolater in the driver circuit you provided, would one place it 1) before R1, 2) as a replacement to R1, 3) between R1 and Q1, or 4) after Q1?

Well, first off, using an opto-isolator to drive a relay here is sort of rube goldberg’ing it. http://www.rubegoldberg.com/ Overkill and a waste of good opto.

A transistor does the job of just fine. Especially in this case where the current load is not really that big.

Okay. I thought opto isolation was standard stuff in a relay set up.

Like this as an example:

http://www.ebay.com/itm/4-Channel-5V-Relay-Module-With-Optocoupler-For-Arduino-DSP-AVR-PIC-ARM-/321151394531?pt=LH_DefaultDomain_0&hash=item4ac61d62e3

The schematic for that seems to put the optoisolator before R1.

@bigred1212

I thought opto isolation was standard stuff in a relay set up.

The relay already supplies you with electrical isolation for the driver(arduino) to load(relay o/p), so the OPTO is not really adding much.
If you then connect ID-VCC to VCC to Arduino +5V there is no purpose at all for having the OPTO.
R1 here simply limits the current thru the OPTO LED and the L1 LED to a safe value.

It is interesting the LED L1 in the circuit is shown incorrect.

Okay. So an opto as a break when using just a transistor, but not so much with a relay?

It is not a good idea to drive the solenoid coil directly from Arduino as it does not have enough current supplying capabilites. Use can use a transistor for driving the solenoid or even use ULN series of driver ICs.

sreedevk:
It is not a good idea to drive the solenoid coil directly from Arduino as it does not have enough current supplying capabilites. Use can use a transistor for driving the solenoid or even use ULN series of driver ICs.

Also, and more importantly, when relay coils shut off. The EMF from the coil collapses, this generates a rathre high voltage (albeit super short in duration) pulse. Over time this will damage any sensitive IC's that are subjected to it. You can limit this pulse to a large degree by incorporating a reverse biased diode but still its better to drive the line with a transistor than directly from the arduino.

pwillard:
Right away to me... no relay coil should be driven directly by a pin when a transistor driver could easily be used. Even if it's just a 5V 40mA coil. Better to blow out a 2 cent transistor than your microcontroller pins.

But.... although you're 100% right, pin 13 is used for a reason here, the LED/resistor is used to suppress the voltage spikes induced by the coil.... (and yes, where is the resistor from pin 13)

Thank you all for the response. I apologize for the inaccurate representation of the circuit in the former Fritzing diagram. A few follow up questions:

  1. How do I choose the correct transistor? I know pwillard gave some recommendations but how do I go about making the decision (now and in the future)?

  2. How do I choose the proper size resistor and diode? If I use a 1kOhm resistor can I approximate the current by Ohm’ law and make sure I select a diode that is rated above that current?

  3. I understand the schematic view of the circuit provided by pwillard. I am trying to get the breadboard view now, I know it is component dependent but does it make sense? I tried compiling what I found on the web and the schematic to make it.

  4. Is it ok to power the hall sensor from the 5V pin of the Arduino Mega or a 3.3V pin from the Arduino Uno? The board’s supply and current appears to be within in the requirements of the hall sensor.

Solenoid: see original post
Hall Sensor: Honeywell SS49E http://octopart.com/datasheet/ss49e-l-honeywell-1516492-13038981

AerE:
Thank you all for the response. I apologize for the inaccurate representation of the circuit in the former Fritzing diagram. A few follow up questions:

  1. How do I choose the correct transistor? I know pwillard gave some recommendations but how do I go about making the decision (now and in the future)?

Check the transistor's datasheet to see if the transistor can handle the current needed by the load (the solenoid).

  1. How do I choose the proper size resistor and diode? If I use a 1kOhm resistor can I approximate the current by Ohm' law and make sure I select a diode that is rated above that current?

The diode is reverse biased, so will only conduct when the power goes off and the magnetic field around the coil of the solenoid colapses (imagine a balloon bursting). The current will be quite small but the voltage from the colapsing magnetic field could be in the order of a couple of hundred volts for a very short time. Chose a diode (again from the data sheet) that will carry this voltage. Current carrying capacity is not important.
Edit: Forgot to add that the diode in your drawing is the wrong way round.

  1. I understand the schematic view of the circuit provided by pwillard. I am trying to get the breadboard view now, I know it is component dependent but does it make sense? I tried compiling what I found on the web and the schematic to make it.

You appear to have connected the transistor-- base, collector, emitter. The usual configuration is-- collector, base, emitter, although not all transistors follow this convention. Again, the datasheet will give you the neccessary data.

  1. Is it ok to power the hall sensor from the 5V pin of the Arduino Mega or a 3.3V pin from the Arduino Uno? The board's supply and current appears to be within in the requirements of the hall sensor.

Then it should be o.k.

Henry_Best:

AerE:
2. How do I choose the proper size resistor and diode? If I use a 1kOhm resistor can I approximate the current by Ohm' law and make sure I select a diode that is rated above that current?

The diode is reverse biased, so will only conduct when the power goes off and the magnetic field around the coil of the solenoid colapses (imagine a balloon bursting). The current will be quite small but the voltage from the colapsing magnetic field could be in the order of a couple of hundred volts for a very short time. Chose a diode (again from the data sheet) that will carry this voltage. Current carrying capacity is not important.
Edit: Forgot to add that the diode in your drawing is the wrong way round.

A minor correction/clarification:
Looking at the Fritzing image in Reply #10, the diode appears the correct way round. It should be reverse biased when the relay is activated.

Also, the current in the diode at the moment the transistor turns off will be exactly the same as the relay energized current. No more and no less, but then decay to zero. The voltage across the relay coil will reverse until it forward biases the diode, at which point the voltage drop will be the diode forward bias drop.

The greatest reverse voltage the diode must withstand is 5V.

There is one thing which will probably not affect what you are doing here, but you may keep in mind for the future when using a relay to switch high currents and/or high voltages: A diode used in this way will slow the relay release time. In circuits where this may be important, you can add a resistor in series with the diode such that the voltage rises and so the current decays more quickly. In that case, the diode never has more than Vcc and the forward bias voltage across it. It is the -transistor- which must withstand a higher Vce voltage when first switched off.

Henry_Best:
You appear to have connected the transistor-- base, collector, emitter. The usual configuration is-- collector, base, emitter, although not all transistors follow this convention. Again, the datasheet will give you the neccessary data.

Good advice, as I find that many of the TO-92 transistors I have in my junkbox are BCE. Which goes back to what someone else said earlier, that it is important to choose the correct parts in Fritzing that match what you are actually using.

Right, that is why MY drawing included a pin out. Reading pins left to right...Many US JAN series transistors have BASE as the middle pin or EBC layout. Many Japanese series resistors use BCE layout and EU style (Philips) use CBE. So always consult your datasheets.

Base resistor is not super critical. You want to limit the current to the base pin to be enough to turn the device on... but not overdrive it (IE kill it). A few mA is enough and the 1K is a pretty nominal resistor to grab from your junkbox as a starting point. Sure you can do all the correct math to get just the right value... but chances are, you are just fine with that value.

Some quick Ohms Law calculation... how much current is at the base pin if fed 5V via a 1K resistor?

pwillard:
......

Base resistor is not super critical. You want to limit the current to the base pin to be enough to turn the device on... but not overdrive it (IE kill it). A few mA is enough and the 1K is a pretty nominal resistor to grab from your junkbox as a starting point. Sure you can do all the correct math to get just the right value... but chances are, you are just fine with that value.

Some quick Ohms Law calculation... how much current is at the base pin if fed 5V via a 1K resistor?

not very complicated math though :wink:
you know the current that goes threw the relay , you look at the transistor datasheet which gives you the minimum value of the gain (hFe) .If you want the transistor to saturate, you need Ib > Ic/hFe .
Just to be sure, multiply this minimum value by 2 --> Ib = Ibmin x 2
The resistor will be about (Voutput-Vbesat)/Ib -> you chose the closer normalized resistor value below the result.

Edit : for the 2N222, all the values (hFe, Vbesat....) are here : http://www.eng.yale.edu/ee-labs/morse/compo/datasheets/2N2222.pdf

alnath:
Edit : for the 2N222, all the values (hFe, Vbesat....) are here : http://www.eng.yale.edu/ee-labs/morse/compo/datasheets/2N2222.pdf

I presume you meant the 2N2222. The hfe values on that datasheet are quoted at Vce=10V. So if you drive it with the minimum base current calculated according to the quoted hfe and switched Ic, then it could have a voltage drop of up to 10V. This can in no way be described as saturated.

In practice, it's likely to be much less than 10V. But if you want to guarantee saturation, you must base your calculations on the values at which Vce(sat) is quoted.

The 2N2222 is not a good switching transistor because its Vce(sat) is far too high. I suggest using a more modern transistor such as BC337, or at least the 2N2222A (not as good as the BC337, but better than the 2N2222).

yes, I meant 2N2222 , and took this one just because it had been quoted before in the thread.
You are right, it is not a very good switching transistor .
I just applied the rule of thumb I learned long time ago, when I was a student,to calculate Ib , but yes, the
multiplicator factor should be more than 2 (which is a widely used value :wink: )

anyway, you are right again, it is better to use the Collector-Emitter Saturation Voltage(1) line that says

Ic = 150mA, Ib = 15mA - Vce(Sat) = 0.3V
Ic = 500mA, Ib = 50mA - Vce(Sat) = 1V !

Ok thanks again for sharing your wisdom. I think I am going to use the following, just checking to make sure I am not setting up a bad circuit with my inexperience.

1k Ohm resistor
s9013 transistor http://pdf1.alldatasheet.com/datasheet-pdf/view/78068/AUK/S9013.html
IN5392 diode http://pdf1.alldatasheet.com/datasheet-pdf/view/329383/CHENG-YI/IN5392.html

Question: Is this diode rated high enough? I was debating the diode below, is it overkill or not? The solenoid is 5V.

FR15 diode http://pdf1.alldatasheet.com/datasheet-pdf/view/151327/GOOD-ARK/FR15.html

polymorph:
The greatest reverse voltage the diode must withstand is 5V.

So the speed of colapse of the magnetic field makes no difference to the back EMF?
That's not how I understand it.