Controlling a relay from an Arduino UNO

Ok, basically I want to connect a relay to my arduino, the relay in question has a 5V coil and a 40mA current rating.
I know that the absolute maximum current rating per pin is 40mA so I don’t particularly want to run it at that.
So how can I do it without potentially damaging my board? I have heard of using a transistor, but I don’t particularly understand how it would work (as I thought a transistor was basically a switch), or what transistor to use etc.

Thanks

This tutorial should sort you out…

Edit… the switching part is that the Arduino output, instead of turning the relay itself on, “tickles” the transistor into connecting the relay to ground, this completing the circuit from 5v through the relay to ground so that the relay activates.

Had a quick read of that tutorial, so essentially you are switching the transistor with an acceptable Arduino current which then switches and supplies the higher current from the battery to the coil of the relay and it switches?

Indeed.

(Edit... or voltage too.... if the relay needed say 24v you wouldn't be able to power from the Uno at all anyway.)

Also don't leave out that diode across the relay coil, and yes, it's meant to be fitted backwards. It protects the transistor from spikes and is required when switching any device with a coil, like a motor.

Can't a transistor be used to amplify current as well, so you wouldn't need the battery and could just kind of amplify the Arduino current, for example?

That's above my knowledge I'm afraid....

Can't a transistor be used to amplify current as well

It is amplifying the current.
A relatively small base current switches a much larger load current.

Ah understood, I guess I just interpreted it wrong then!

harvs899:
Can't a transistor be used to amplify current as well, so you wouldn't need the battery and could just kind of amplify the Arduino current, for example?

No.

No.

Obligatory "Homer Simpson: In this house, we obey the laws of thermodynamics!"