I want to control a solenoid valve using a digital output of an arduino uno pin. I thought of using an optocoupler (4n25), something like this but with a 12V power supply.
That circuit should work for 12V .
Yes do put a diode across the solenoid.
Check that the solenoid current does not exceed the TIP120 rating.
The TIP120 is used for its gain so the opto-output current does not need to be high.
You can use a N-CH MOSFET if you need more efficient switching.
Unless you need the electric isolation, you don't need the optocoupler. You can connect the 5V of the Arduino via the 1K resistor directly to the base of the TIP120. You must have the grounds connected as well to make this work.
You do need to add a flyback diode across the leads of the solenoid, to take care of the reverse current when switching off, otherwise it may destroy other components.
wvmarle:
You do need to add a flyback diode across the leads of the solenoid, to take care of the reverse current when switching off, otherwise it may destroy other components.
It wouldn't protect everything - the transistor still gets the full brunt. The Arduino may be affected as well: the other day I worked with someone on a project where a solenoid is switched through a relay. The Arduino, on a separate power supply (12V power supply to the solenoid; 5V step-down connected to that power supply for the Arduino), kept on resetting... until they added a flyback diode on the solenoid. Not sure if grounds are connected, though.
Well thank you guys for answering. As Tom said, that's why i want the optocoupler.
TomGeorge:
Check that the solenoid current does not exceed the TIP120 rating.
The TIP120 is used for its gain so the opto-output current does not need to be high.
And in any case should i just use a bigger resistor to reduce the base current and lower the gain?
DussanR:
And in any case should i just use a bigger resistor to reduce the base current and lower the gain?
No use. Maybe nothing happens, maybe it stops working (insufficient gain), or maybe it starts to overheat (due to less saturation). Just make sure the TIP120 can handle your current (maximum 5A according to the data sheet - with sufficient cooling).
Even with the optocoupler in between you must add this flyback diode. Otherwise you may kill the transistor, and power spikes are very good at finding ways to travel through power supplies and still mess with your Arduino. The voltage produced may be a multiple of the 24V supply, and it's a negative voltage spike to boot. That energy has to go somewhere.
DussanR:
Well thank you guys for answering. As Tom said, that's why i want the optocoupler.
And in any case should i just use a bigger resistor to reduce the base current and lower the gain?
We do not guess, we calculate.
what is the current used by the solenoid ?
From that you calculate the the current required for the transistor to be fully saturated. there is one correct value. end of story, no guesses.
go one way and you can drive the transistor in the analog range, overheat and cause problems with your devices.
you often go lower to offer some guarantee you are turning it on hard.
as a note, you do not show you are controlling the opto. connected to 5 and gnd ? what pin ? and are you driving it with 5v or completing the circuit with a pin ?
do you plan to use any pull-up or pull-down resistors to make certain your signals are not floating ?
DussanR:
Also if it's just fine using 12v on the collector, why use a TIP120? for the gain? or should i limit the voltage to something like 5v?
read up a bit on transistors.
gain is a multipler. if you put in 1mA, and it can pass 1 amp, you have a little signal and it can pass a larger value. the ratio is the the gain.
it is fixed, you do not get to change it.
[ you do get to USE it to your advantage ]
knowing the gain, you can control power by putting the transistor into the analog range and you can control the power it will pass, like a dimmer application.
as for your question, I beleve you are asking :
my solenoid has a current rating of _______________
the 4N25 has a current rating of______________
can I drive the power for the solenoid through the opto ?
the data sheet shows the TIP has a rating of ______________
since this much larger (smaller?) than my solenoid, is this the correct device ?
our answer would be either yes or no, and then with a comment that the TIP are so plentiful, they are really cheap and easy to get for possible replacement.
and that when you look at the cost, we would spend the extra 20 cents to have a rating that is more then twice (10 times?) more than the circuit requires.
the calculations would also show how hot the TIP will get and if you need a heat sink.
and if that is too high, we would recomend you use a FET.
as a note, we do recommend you take that pic into PAINT and correct it for your circuit. and list power and voltage for the solenoid.
unfortunately i don't have much concept for the calculations. It's a small project, and i just looked into google and tried understanding the concept. i'm not there yet in my uni courses, if you could point me in the right direction i would appreciate it
the solenoid pulls 1.1amp from exactly 12V
the 4n25 has a max collector current of of 50mA
So i't can't be used directly with the valve.
the tip120 has a max collector current of 5A, and a gain of 1000.
sorry but i dont understand how to calculate the base current.
And i found that pic online, i used it just as reference to know if something like this would work
fro what i searched, i have an Ic of 1.1Amp, a B of 1000. So mi Ib should be something like 1.1mA, and given 12V will be going to the base, the Rb has to be somewhere 10k?
If your collector current is 1.1A then your minimum base current, assuming a gain of 1000 will be for saturation of the TIP120.
Base Current = Collector Current / Gain.
Base Current = 1.1 / 1000 = 0.0011 Amps
or 1.1mA to saturate or fully turn ON the TIP120.
To make sure the TIP120 is fully saturated, and you have the current capacity of the output of the opto to do it( up to 50mA ), use 10 times the Base Current needed.
So opto output current = 1.1mA * 10 = 11mA.
The volt drops we have in the opto and TIP120 circuit are,
0.5V across the opto when it is ON
2.5V Vbe on the TIP120.
So the volt drop across the base series resistor will be
12 - 0.5 - 2.5 = 9V
So the base resistor has 9V across it and 11mA flowing through it.
R = V / I = 9 / 0.011 = 818 Ohms.
So 820 Ohms will do the trick.
680 Ohms will also be fine.
I would go with the 680 Ohms as the DC gain (1000) is not etched in stone for all TIP120.
If your collector current is 1.1A then your minimum base current, assuming a gain of 1000 will be for saturation of the TIP120.
Base Current = Collector Current / Gain.
Base Current = 1.1 / 1000 = 0.0011 Amps
or 1.1mA to saturate or fully turn ON the TIP120.
as a note here, the data sheet for a transistor will list hfe.
the TIP120 has an hfe of 1,000 = gain of 1,000
as shown in the line above.
I think Tom did a good job laying it out and I just wanted to point this bit out as every transistor has a different hfe so this calculation needs to be adjusted for other ones.
it has a gain. the TIP120 is listed as 1,000
a smaller switching transistor might be 150.
this is a ratio.
for the TIP120 you need to feed it power, you feed it 1 amp and it will allow 1000 amps to pass...
since your device is 1 amp, you need to feed it 1/1000 of one amp.
but..... since the opto consumes a tiny bit of power, you will not get 12.000 volts and the resistor will consume some, so you will not pass power without some changes. you might get 9 volts....
part of the calculations are to allow for the actual values at the pins.
the load will consume some power and the TIP120 has a resistance that will also have some effect.
the bottom line is that you have to feed the TIP120 some current and it will drain that to ground, and while it is draining to ground it opens the gate for the larger current from the collector.
in the TIP120 the ratio is 1000:1 you supply 1 and you allow 1,000 of the other to pass.
the calculations are to allow for all the voltage drops, resistance, etc.
Quick question guys, at what point does the amps on a power supply are too much? the power supply i was going to use seems to be malfunctioning and i wanted to know the max amps i can use, and why.
but what i mean is if my power supply is 12V at 2A. there's no chance of it damaging the circuit? it will only draw the 1.1 to work for the whole circuit?