How to choose the right transistor, diode, resistence for my relay

Hello,

I would like to connect a relay to arduino to drive some lights (230V).
I have seen this Arduino Playground - HomePage and this Arduino Project: Tiny Relay Shield
but I don't understand how to choose components in the right way.
I have a Finder relay 36.11.9.005.4001 (http://www.soselectronic.com/a_info/resource/h/Finder/F36EN.pdf) which works on 5V and should be ok for loads 230V.
Said so, I don't know how to choose the transistor nor diodes/resistors accordingly.
At home I have the following:
Diode: 1N4001, 1N4004, 1N4007
Transistor: 2N3904 NPN, 2N3906 PNP
Does anyone can help me understand which should I use for my relays?
Thank you,
dk

Any of those will do appart from the PNP transistor. Even that will work if you wire it correctly but it is normal to use a NPN.

Your transistors only have to handle the relay current which is small. The diode shorts out the back EMF which they will all do.

Look at the data sheet for the maximum current and voltage the transistor will take, you will find it to be greater than 5V.

Thank you for your reply.
Ok, so the final schema should be this one assuming I will connect it to digital pin3.

		 5V
		 |
		 |
		----
		|   |
		|   ----S  Relay
	Diode	|       S
	1N4004	A   ----S
		|   |
		----
		 |
Pin		 |c
D3 ---/\/\/\---|<     Transistor
	R 1K	 |e   2N3904 NPN
		 |
		 |
		GND

@d82k

Yes

Cathode diode & one side coil to +5
Anode diode & one side coil to NPN collector
NPN emitter to Gnd
Resistor (470 to 1K Ohm) between NPN base and uC port

If you desired to use a PNP, follow this circuit
www.jaycar.com.au/images_uploaded/relaydrv.pdf

What we are trying to accomplish is to drive enough current through the base of the transistor to put the transistor into saturation mode. Hence, we use a base resistor to limit current through the transistor base-emitter junction. (Also, through the uC port!)

There is math to figure these things out precisely, but for saturation mode, we generally act pretty sloppy and just go-for-it...

If your 5-function solar power $1 calculator is gathering dust, you can exercise it from this information Basic Transistor Circuits

Ray

Grumpy_Mike:
Any of those will do appart from the PNP transistor. Even that will work if you wire it correctly but it is normal to use a NPN.

Your transistors only have to handle the relay current which is small. The diode shorts out the back EMF which they will all do.

Look at the data sheet for the maximum current and voltage the transistor will take, you will find it to be greater than 5V.

why ?

Because the circuit for a PNP transistor driving a relay is different from the circuit for an NPN driving the relay.
For a PNP, wire up:-
emitter to +5V
collector to relay
ground to other end of relay
base to a resistor to the arduino output.
Then a LOW on the output turns the relay on and a HIGH turns it off.

It is normal to use a NPN because with that configuration you can switch much higher voltages than the 5V from your arduino. With a PNP you can only switch 5V, if you want to switch higher voltages then you have to use a second transistor ( a NPN ) to generate a base signal that goes up to the voltage you want to switch in order to turn the transistor off.

Yes, Mike, I know all of this :slight_smile:
I was asking because OP didn't say anything about the way he would drive the relay.
And he said "the relay works at 5volt."
One of the advantages a microcontroler gives, is that is is very easy to change an output state, thus you can adapt your code to the logic needed "output HIGH->ON" or "output LOW-> ON"

Given that, you can use a PNP as well as an NPN, both will work, and there is not a "normal" one :wink:

and there is not a "normal" one

There is is you look at what is normally used. The vast majority of circuit's will use an NPN transistor, it is the default transistor these days. Back in the 60s the default was PNP but we have come a long way since then.

My post didn't mean just to contradict (is it the right word ? ) you with no reason .
I often use pnp transistors, just because I prefer to switch the "+" than the GND : GND is more easily accessed on most PCBs and everywhere (cars....), and it is easier to have it connected by accident :wink:

I didn't do electronics back in the sixties (I was only 2 years old then ^^ ) , and I'm not sure that NPN is really the default transistor , maybe beginners use it more often, because the 1rst part of most tutos describe it first, but I can't see why it should be the default one. Both are easily found.
Its different with mosfet, N-channels are more widely used and easier to find than P-channels

My understanding is that, because of differences in manufacturing and the physics of N and P type semiconductors, it is simpler to get higher gain, higher current, higher power handling, and higher voltage with NPN transistors than PNP.

But if you have a PNP that is rated to handle what you need it to, then use it!