Control a few 12v circuits with an Arduino

Hi there!

I want to create a device which can control a few 12v devices / circuits.

See attached my circuit design.

  • The IR LEDs are rated 4v so 3 in series should do the trick without a resistor right?
  • For the transistors: I tried a BC639 but it was always “ON” so I replaced it with an 2N2222A and it works. A BC639 would deliver more current especially this could be relevant for the motors. Why does the BC639 doesnt work in this design?
  • The last “motor” is a heater sticker. It draws approx. 2A so I replaced the 2N2222A with an IRLZ34N Mosfet.

Are there any design flaws or better ways to do this? Prevent damage etc?

Thanks for your input!

asuryan:
The IR LEDs are rated 4v so 3 in series should do the trick without a resistor right?

Wrong. LEDs always need some form of current limiting.
LEDs are rated for a certain current (not voltage), and at that current (and temperature) they have an estimated working voltage.

What kind of IR LEDs. The 5mm IR LEDs I know are about 100mA max.

asuryan:
For the transistors: I tried a BC639 but it was always “ON” so I replaced it with an 2N2222A and it works.

You probably connected them wrong. A BC639 has AFAIK the collector connected to the center pin.

asuryan:
The last “motor” is a heater sticker. It draws approx. 2A so I replaced the 2N2222A with an IRLZ34N Mosfet.

A bjt transistor used as a switch needs a base current of 5-10% of the collector current (Hfe is irrelevant here).
An Arduino pin can’t/shouldn’t provide more than 20mA, making switching currents of more than 400mA with a common bjt trasistor impossible. So anything more than that needs a mosfet or darlington
Not fully saturated bjt transistors switching hundreds of mA will overheat and pop their tops.

A 10k base resistor only provides (5-0.7)/10k= 430uA…
Leo…

The IR LEDs are rated 4v so 3 in series should do the trick without a resistor right?

No, not right. You still need to limit the current.

The motors need flyback diodes to protect the transistors from the reverse voltage created when the motors shut off.

The 10K resistors on the bases are way to high value. They will not allow enough base current to turn the transistors fully on.

Same for the MOSFET gate resistor, but the resistor is to limit the gate capacitance charging current. recommend 180 Ohms.

You might want a pull down resistor (10K) on the MOCFET gate to keep the MODFET off during processor startup or reset.

Hi,
Ops diagram.


Thanks.. Tom.. :slight_smile:
PS the BC339 has a different pinout to the 2N2222.

Thanks so much for your input! Allways in learining mode... :slight_smile:

I changed a few things according to your suggestions. Have a look.

What kind of IR LEDs. The 5mm IR LEDs I know are about 100mA max.

Sorry mixed it up. They are actually UV leds with 405nm.

Thanks.. Tom.. :slight_smile:

Yes Thanks! :slight_smile: You just copied the url to embedd the image right? Good point! :slight_smile:

groundFungus:
The 10K resistors on the bases are way to high value. They will not allow enough base current to turn the transistors fully on.

Same for the MOSFET gate resistor, but the resistor is to limit the gate capacitance charging current. recommend 180 Ohms.

A bjt transistor used as a switch needs a base current of 5-10% of the collector current (Hfe is irrelevant here).
An Arduino pin can't/shouldn't provide more than 20mA, making switching currents of more than 400mA with a common bjt trasistor impossible. So anything more than that needs a mosfet or darlington
Not fully saturated bjt transistors switching hundreds of mA will overheat and pop their tops.

A 10k base resistor only provides (5-0.7)/10k= 430uA...

How can I calculate the right resistor for a certain MOSFET or transistor? What kind of parameters I need to know to calculate it? Is there a formula or somthing like that?

No, not right. You still need to limit the current.

A very small one is sufficient then?

Thanks in advance!

The UV LEDs could have a working voltage of 3.75volt@20mA.
Then a 10ohm resistor could want to push (12 - (3*3.75) - 0.2 (transistor)) / 10 = 55mA through the LEDs.
If your supply happens to be 12.25volt, then LED current could be 80mA.
See how a too small voltage headroom between LEDs and supply won't work?
You might have to put two UV LEDs in series, and use a larger value resistor.

Volt drop across the base resistor is 5volt - BE diode (~0.7volt) = 4.3volt.
If you know collector current, then you can calculate base resistance with ohms's law (5-10% of that CE current).
Example: 120mA collector current needs 6-12mA base current.
Rmin = 4.3/0.012 = 358ohm. Rmax = 4.3/0.006 = 716ohm. A 470ohm resistor would do.
In practice, a 1k resistor would still be ok, but full saturation gets more important with larger currents.

A mosfet just needs to switch fast. Just use a 150-220ohm gate resistor.
The 10k bleed resistor to ground should be on the Arduino side of the ~180ohm resistor.
Leo..

asuryan:
The IR LEDs are rated 4v so 3 in series should do the trick without a resistor right?

If having the same brightness for each LED is critical to you, this setup won't work since since there are slight difference in the PD that each LED takes due to manufacturing tolerances, and this creates large differences in current and therefore brightness. You could hookup a simple current regulator using an LM317 or similar feedback voltage regulator, but watch out for the dropout voltage.

If brightness isn't critical, you could just wing it and put them in series, but you risk blowing one of them if it happens to draw excessive current.

Resistors can indeed be pretty small value; just today I was working with some 12V white LED strips which use 4 LEDs in series and then a 6R9 or 15R resistor (depending on the strip).

Changing the voltage from 12V to 12.5V (we pushed it to 13.5V) has really drastic effects on the brightness. A larger resistor makes it much less sensitive.

To find a good value for the base resistor of a BJT transistor: you want saturation, so 10x, no more than 20x amplification. Know the collector current (that's what you want to switch), then size the base resistor to get 1/10th that current through the base. Or at the very least 1/20th.

Thank you all so much for your input!

So basically I can calculate the base resistor like this:

18x UV LED (Current 20mA each):
18x20mA = 360mA Needed Collector Current
Needed Base Current (5-10% from Collector Current) = 18mA - 36mA
Base Resistor:
Rmin = 4.3/0.018 = 238 Ohm
Rmax = 4.3/0.036 = 130 Ohm

12x WHITE LED (Current 20mA each):
12x20mA = 240mA Needed Collector Current
Needed Base Current (5-10% from Collector Current) = 12mA - 24mA
Base Resistor:
Rmin = 4.3/0.012 = 358 Ohm
Rmax = 4.3/0.024 = 179 Ohm

  • And that applys for the load I expect in the branch of the transitor (so I wnat to switch a motor rated with 300mA and therefore the needed collector current needs to be 300mA. So its the sum of all loads that are in this branch). Right?
  • This is transistor dependend right? So how to get the transistor into the equation?

Thanks!

asuryan:
18x UV LED (Current 20mA each):
18x20mA = 360mA Needed Collector Current

You have your LEDs in series of three, the 20 mA current flows through the whole series, so your total collector current would be 6x20mA. Likewise for the white LEDs: that’s 6 series of 2 LEDs, so also 6x20 mA. For the rest your calculations look correct.

This value is somewhat transistor dependent: that 10-20x is a typical figure. You have to check the datasheet of the individual transistors for details. For perfect calculations you should also look at the BE voltage drop and take that into account when calculating the base current.

Next consideration: the current supply of your Arduino pin. That’s 20 mA (absolute maximum 40 mA) so your transistor should not be less than 250 Ohm (125 Ohm bare minimum). The absolute max you can use for a quick test; the lower limits are for more permanent installations.

If you need a higher gain, look for a darlington (basically two transistors in one), which can be in saturation at a couple hundred times gain. Note that the voltage drop over a darlington is about 1.2V, compared to 0.3V for a regular NPN or PNP transistor.

Now if the current you switch is more than about 500 mA (or even less) you’re usually much better off with a MOSFET transistor rather than the older BJT type. The gate of a MOSFET also needs a resistor but that’s to limit the inrush current as the gate acts as capacitor.

wvmarle:
This value is somewhat transistor dependent: that 10-20x is a typical figure. You have to check the datasheet of the individual transistors for details. For perfect calculations you should also look at the BE voltage drop and take that into account when calculating the base current.

For what values I have to look? For example is there a BE value in the datasheet?

nc = needed current (mA)
lv = logicVoltage (eg. 5v)
tVd = transistor Voltage drop (what abbrevation has this in a datasheet?)
cPerc = Current Percentage (eg. 0.05-0.1) (Where can I find this value in a transistor datasheet?)

So its basically: (lv - tVd) / ((nc*cPerc) / 1000) = BaseResistor

Any other parameters?

Values and names vary a bit per datasheet.

At this level the exact numbers don’t matter much anyway. Good enough is good enough, and if you’re 10-20% or even more off ideal, you normally won’t notice the difference.

I have this schematic now:

Hope its better than the previous ones...

Why not placing two LEDs in series?

Three in series gives you a bit too little headroom indeed; two in series with 220Ω resistor for current limiting will do great - 20.5 mA current. At 12.5V that increases to 22.7 mA, nothing to worry about. It does save half the total current.

Finally, I hope this is good :slight_smile:

Best and thanks all of you! :slight_smile:

Your base resistors are pretty small - and all marked as R3 making it hard to designate one.

I wouldn't draw more than 20 mA from an Arduino pin, so 250 Ohm or larger resistor. That'll do just fine for switching a 300-400 mA load. For greater loads use a Darlington or MOSFET.

Secondly you have to keep the total amount the Arduino can deliver in mind, I remember some 200 mA (check datasheet). If you have all those transistors switched on you're drawing over 100 mA already with the resistor values you pick.

Thanks so much for your help!
I will change the base resistors accordingly.
Noted all your suggestions down!
Thanks! :slight_smile: