Are these components OK for this relay?

I know the theory of using a relay from a microcontroller, but I don't know if I'm using the right components.

Relay: The coil is 5V 200mA. (T9AS1D12-5)

Transistor: I have some 2N3904 which should be able to handle 200mA. Can I use that one? I also have some BC517 darlingtons, they should be able to handle 500mA. Would that be better?

Resistor (For the transistors collector): After hours and hours of reading about transistors I still have no idea how to find out which resistor to use here. I'm guessing 1-2k should be okay?

Diode: I need to put a diode on the coil. I have some 1N4001, they should be able to block up to 50V 1A. Is that enough?

Caps: I'm going to power this with a cheap USB charger. I assume the coil will make a lot of noise and that I should add a capacitor near the AVR chip, and possibly on the power supply. I suppose I don't need any near the coil. I don't even know what to suggest here. I haven't even bought any, but I have some salvaged ones.

myplacedk:
I know the theory of using a relay from a microcontroller, but I don't know if I'm using the right components.

Relay: The coil is 5V 200mA. (T9AS1D12-5)

Transistor: I have some 2N3904 which should be able to handle 200mA. Can I use that one? I also have some BC517 darlingtons, they should be able to handle 500mA. Would that be better?

A 2N3904 is a very popular signal transistor, but not really designed for higher current switching, I would select a power transistor that has a max current rating of a couple of amps at least. Resistor (For the transistors collector): After hours and hours of reading about transistors I still have no idea how to find out which resistor to use here. I'm guessing 1-2k should be okay?

Should be OK at 1k, more base current is fine (up to the output pin 30ma limit or max transistor base current limit, which ever is less) and will just insure that the transistor is fully saturated on for minimum voltage drop.

Diode: I need to put a diode on the coil. I have some 1N4001, they should be able to block up to 50V 1A. Is that enough?

Yes, the old rule of thumb for this kind of service is a diode PIV or at least 4X the applyed voltage.

Caps: I'm going to power this with a cheap USB charger. I assume the coil will make a lot of noise and that I should add a capacitor near the AVR chip, and possibly on the power supply. I suppose I don't need any near the coil. I don't even know what to suggest here. I haven't even bought any, but I have some salvaged ones.

Not clear if you mean your going to power an arduino board and the relay coil from the charger or just the relay?

Lefty

Somewheres in all those datasheets, it usually indicates that transistor
current-gain falls off radically as collector current gets large, so instead
of nominal hFE = 100, it's more like hFE = 10 for currents over 100-mA.
Every part is different.

That would mean, for 500-mA collector current, you'd need 50-mA base
current drive. Way too much. A dinky little 2N3904 TO92 package will
probably melt.

As mentioned, for 500-mA drive you need a larger better power transistor,
and then you might need 2 stages to develop enough output current, due
to the low hFE at high currents. I would probably use a logic-level n-channel
MOSFET transistor here instead of bipolar.

Also for the 1N4001, 1A is the rated "forward" current, while 50V is the PIV
or peak "inverse" voltage. They are 2 totally different things, one forward
re current capacity, the other inverse re blocking voltage meaning
no current.

1N4001 should be fine for coil reverse EMF suppression, it really only has to
block 5V in the inverse direction.

And just a note about ratings - if a rating is "absolute maximum" then you don't go there, that's when damage happens - allow a safety factor.

For a 5V relay you probably shouldn't waste more than 0.5V in the transistor to ensure the relay gets most of its 5V - at 0.2A and 0.5V a transistor would be dissipating 100mW which isn't too bad (it'll be warm but shouldn't burn fingers).

Select a transistor with Vsat < 0.5V for 0.2A current. Choose base resistor so definitely in saturation (sometimes the datasheets tell you the base current for various saturated currents).

My favorite high-performance transistor is the ZTX851, Vsat=0.05V at 1A, will take 5A continuous and 20A peak - all in a tiny through-hole package.

Thanks for your comments. I'm trying to understand and remember all of it. :slight_smile:

Transistor
I can't pull more than 20-30 mA from the AVR, so I need a gain/hFE of at least 40-50, even at 200mA through the collector. So I'm looking at a BC517 darlington, with a gain of at least 30.000. It tak max 500 mA collector current, peak 800. But MarkT reminded me of the voltage drop. The BC517 datasheet says the collector-emitter saturation voltage is max 1V, if there is 100mA through the collector and 0.1mA through base. Assuming it's still 1V at 200mA, that's 0.2 watt. The datasheet says total power dissipation in 25C is 0.625W. Maybe it's okay if I add some airholes?
The relay datasheet says 3.75 V is actually enough, so ... it's pretty close. I guess I'll try, and consider getting some ZTX851's.

Resistor
With a gain of >30.000, 0.0067mA should be enough. The resistor has a base-emitter saturation voltage of 1.5V. That's about 525.000 ohm for the resistor. Is that correct? Is a 100k resistor a good idea?

Diode
1N4001 it is.

Caps

retrolefty:
Not clear if you mean your going to power an arduino board and the relay coil from the charger or just the relay?

I will power everyting with a single USB charger. The AVR, the relay, a JY-LKM1638 module, a DS18B20 (one-wire thermometer) and a piezo/speaker/buzzer of some sort. Now you have probably guessed it's a kind of thermostat. XD

I don't know how much current the JY-LKM1638 draws, and my amperemeter is broken. But I hope this all together will draw less than 500 mA, and I'm pretty sure it will be less than 1A.