How to Control a 6V Solenoid using Arduino

Hi,

I'm fairly new to Arduino and was hoping for some advice about using a 6V micro 3-way solenoid by controlling it somehow with a Uno.

The specs are:

【Rated Voltage】 DC 6V
【Current】 220mA
【Suitable Voltage】 DC 5V-6V
【Power】 < 2W
【Pressure Range】 0-46.66KPa (0-350mmHg)
【Use Medium】 Gas
【Wire Length】 15CM
【Weight】 about 16g

Wiring Instructions:
When power off, 1 and 3 pass, 2 is blocked;
When power on, 1 and 2 pass, 3 is blocked.

I currently have some 2N2222 NPN Switching Transistors but that's about as far as I've got. I've done some reading and am cautious to try anything out in case I might damage something. I understand that, if using transistors, I will need to use diodes as well, however I'm not sure which the right ones would be.

I also read that an octocoupler might also be an option, however, again, I'm not sure which I would need. As I understand it, both octocouplers and transistors are designed to increase power (?), however, all I need is to switch the power to the valves on or off.

If someone could point me in the right direction, that would be very much appreciated.

Can you give us the actual Web page?

lozelise:
3-way solenoid

Wiring Instructions:
When power off, 1 and 3 pass, 2 is blocked;
When power on, 1 and 2 pass, 3 is blocked.

Forgive me going off topic, but is that really called a "3-way"? I get that it has 3 connectors (1, 2 and 3) but there are only 2 ways to pass the gas namely 1 to 3 and 1 to 2. So does "way" refer to the connectors? My logic tells me a "way" would be the "path"-way.

Just wondering....

Paul__B:
Can you give us the actual Web page?

I'm genuinely curious to know what you would need to know, or what else is likely to be in the web page, to say if a 2N2222 was ok or not, other than the 6V and 220mA already quoted?

But let's look at some numbers, and we can use this web based calculator to do the sums for the base resistor, and here's a datasheet for that transistor.

First the datasheet says max values of Vceo and Vcbo are 40 and 75 respectively so your 6V is ok. Vebo must be under 6, so 5V logic is ok. Ic max is 800mA, you have 220 which is good.

So let's put the 220mA into the calculator having chosen the right transistor in the drop down: gives us a base resistor of 1818. Calculator narrative says to halve that (double the current) to ensure saturation, so 900.

Even that doubled current of 440mA at a gain Hfe of 100 would give an Arduino pin current Ib = Ic/Hfe of 440/100 which is way less than the 20mA allowed.

So I'd say go for it, with a 1k base resistor.

(But I'm no expert; I do everything with logic level mosfets nowadays to save my brain doing all that gain and current calculation nonsense :wink: Use voltage, not current, to switch voltage I say!)

edit: I forgot the diode. At my local supplier, the 1N4007 is actually cheaper than the lower voltage 1N4001, so it's my diode of choice, but they're cheap as chips anyway as Jamie O would say. I think it needs to be 1N4xxxx style at least though, not a 1N4148 type.

final edit sorry:

lozelise:
As I understand it, both octocouplers and transistors are designed to increase power (?), however, all I need is to switch the power to the valves on or off.

That's what the transistor does, or let's rather say it switches the higher power. You Arduino digital pin is 5V and 20mA; your valve is 6V and 2-300mA. So you can't power the device from the pin.

And an optocoupler is just a transistor where the base is an led inside, so if there was any breakthrough from the load to the Arduino, it won't get across that "optical barrier".

Paul__B:
Can you give us the actual Web page?

Hi Paul__B,

My apologies for not including it - here it is on eBay: Mini 2-position 3-way Electric Control Solenoid Valve for Gas Air Pump Dc5v 6v for sale online | eBay

Thanks, neiklot, for your detailed answer. So, if I'm understanding correctly, you're saying that I'd be ok to try it with the transistors I have, a base resistor 1818, and a diode of type 1N4xxxx (not 1N4148) - and I can hook it up to the digital pin on the arduino?

also,

neiklot:
And an optocoupler is just a transistor where the base is an led inside, so if there was any breakthrough from the load to the Arduino, it won't get across that "optical barrier".

Does this mean that a diode wouldn't be needed for an optocoupler?

Are there any simpler methods you know of that can just switch something on and off based on input from the digital pins (but taking power from the 5v pin on the board or an external battery)? My main issue is that I've always been working with things that have at least a third wire to connect to the digital or analog pins for control but the valves I have only have power wires.

Apologies if these are really silly questions, I've still got a lot to learn.

Oh and - yes you're probably right - it should be called a 2-way valve!

It is a 3 way (3 ports), 2 position (ON or OFF) valve, you only need one transistor, one base resistor and one diode.
NPNMot-2.png
Replace M1 with your valve coil.

When using a transistor as a switch, the gain (hfe) is meaningless. Gain is only relevant when the device is being used in its linear regain as an amplifier.

To saturate the device, it is typical to use 1/10 of the desired collector current into the base and this exactly what the datasheet referenced shows. Look under the electrical characteristics, Collector Emitter saturation voltage and you’ll see they list the base current as 10% of collector current. Look at the two points given and watch what happens to the C-E voltage as current increases. The higher that voltage goes, the more power it dissipates. Not a very good switch, given what modern mosfets can do.

So, your base resistor should be more in the range of 200 ohms. Base voltage will be about 0.7 volts so 5-0.7=4.3 which gives 4.3/.022=195 ohms. The required 22 ma is at the high end of current out of an AVR pin so if you cannot get 200 ohms, which is a 1% value, 220 ohms would be the first choice, 180 ohms the second.

Edit: a diode across the coil is always needed. An optocoupler is not required and would only add components to this circuit, the simple transistor or its modern replacement (as a high current switch) the mosfet, are about as simple as you can achieve.

lozelise:
Thanks, neiklot, for your detailed answer. So, if I'm understanding correctly, you're saying that I'd be ok to try it with the transistors I have, a base resistor 1818, and a diode of type 1N4xxxx (not 1N4148) - and I can hook it up to the digital pin on the arduino?

No, I was wrong on the numbers, go with WhatsThat's ~200 ohms. That's why I use logic level mosfets...

WattsThat:
Typically, to saturate the device, it is commonly to use 1/10 of the desired collector current

lozelise:
Are there any simpler methods you know of that can just switch something on and off based on input from the digital pins (but taking power from the 5v pin on the board or an external battery)? My main issue is that I've always been working with things that have at least a third wire to connect to the digital or analog pins for control but the valves I have only have power wires.

The transistor becomes the "third wire"; the base of a bjt or the gate of a mosfet is like your finger on a switch.

JCA79B:
It is a 3 way (3 ports), 2 position (ON or OFF) valve, you only need one transistor, one base resistor and one diode.
NPNMot-2.png
Replace M1 with your valve coil.

Thanks JCA79B - and thanks for the diagram - that's really helpful!

WattsThat:
Edit: a diode across the coil is always needed. An optocoupler is not required and would only add components to this circuit, the simple transistor or its modern replacement (as a high current switch) the mosfet, are about as simple as you can achieve.

Thanks, WattsThat (and great name by the way!). Yourself and neiklot have convinced me about mosfets now - I've looked into them and all the ones I can find on eBay seem to have really high voltage and currents - like way more than I seem to need. Is there one type that you'd recommend?

" Is there one type that you'd recommend?" Yes, don't shop for electronics on ebay,

Look for logic level MOSFETs, they will turn on fully with 4.5 to 5V and very little current.

https://www.digikey.com/product-detail/en/taiwan-semiconductor-corporation/TSM900N06CH-X0G/TSM900N06CHX0G-ND/7360597

100mOhm (0.1 ohm) max on resistance with 4.5V turn on voltage at up to 3A of current. $0.52 USD.

CrossRoads:
" Is there one type that you'd recommend?" Yes, don't shop for electronics on eBay,

But they are so cheap! :astonished:

OK, the three week wait is a real pain - I don't know exactly where the 2½ week warehouse stop is; have a suspicion it is in Customs and maybe a deliberate anti-Chinese trade ploy.

Do remember that we outside of the US cannot sensibly afford the absurd postage charges.

CrossRoads:
100mOhm (0.1 ohm) max on resistance with 4.5V turn on voltage at up to 3A of current. $0.52 USD.

Thanks for this direction, CrossRoads. One last question (it is a super newbie one) do you have any advice on how to decide which resistor and diode to use with the Mosfet? I'm assuming some calculations are involved, but I'm not sure which.

With the N-channel MOSFET, you need two resistors.
One in series from the Arduino to the MOSFET get to limit inrush current, which is current that charges & discharges the gate capacitance: 5V/30mA = 167 ohm, so a 180 ohm resistor would be good. Add a 10K from Gate to Gnd to keep the MOSFET off during Arduino reset. (cap looks like a short to Gnd when discharged, and a short to 5V when charged, the 30mA charges or discharges it).
Diode, just need one that conducts at least as much as what flows thru the coil. 220mA, any 1A rated diode would work.

Not to be pedantic but best practice would have the 10K resistor on the AVR pin side of the 180 ohm resistor. It’s 2% of your gate drive thrown away.

.02*./03 = .6mA, I think it can be spared. Or swapped to 100K. Just need to bleed off any gate capacitance.

Huh? It’s 10000/10180=2%.

100K is fine if you insist on the gate side. Whatever. You do your way, I’ll do it mine.

Edit: just be clear, I’m referring to gate voltage loss.

CrossRoads:
With the N-channel MOSFET, you need two resistors.
One in series from the Arduino to the MOSFET get to limit inrush current, which is current that charges & discharges the gate capacitance: 5V/30mA = 167 ohm, so a 180 ohm resistor would be good. Add a 10K from Gate to Gnd to keep the MOSFET off during Arduino reset. (cap looks like a short to Gnd when discharged, and a short to 5V when charged, the 30mA charges or discharges it).
Diode, just need one that conducts at least as much as what flows thru the coil. 220mA, any 1A rated diode would work.

Thank you for walking me through that - it's making a lot more sense now. I'll try it out with those parts and look forward to seeing it in action!

WattsThat:
Edit: just be clear, I’m referring to gate voltage loss.

And as you may recall, this is my concern as well.

I view it this way: The resistor is not to compensate for any shortcoming in the FET; it is there to hold the voltage to the correct state when the Arduino is reset, initialising or has crashed. The "fault" belongs to the Arduino, so the pull-down should be across the Arduino output, not on the FET gate side.