Using a relay to light a 120VAC light

Hi, I want to try this Hobby Robotics » Using Relays with Arduino – Turning on the Lights but I'm wondering what is the use of the transistor ? Also, is a S8050 transistor safe to use to replace the 2N222 ?

Thanks.

The Arduino can't provide the current for the relay coil, so you need a heftier 5V supply: the transistor switches that supply to de/activate the relay. That 5V at the top is not the Arduino 5v pin.

You would be better off with one of these.

Thanks for the answer but the guy in the tutorial wrote that he was not using another source since the relay is 5v. I picked a 5 volt relay because that lets me use the Arduino board’s 5V volt output thus eliminating the need for another power source.

But I find your idea interesting. I should have bought it before buying these yesterday.

You would need to check that the relay coil current is not too high for the Arduino then. I forget off the top of my head what the max current from the 5V is, sorry.

Thanks. And do you think it is safe to use with an S8085 transistor ?

If you mean the S8050 the yes.

And you can use the Arduino 5V but it's a bit complicated.

If you power it via USB from the computer you're limited to the current of the PC (most likely <500mA)

If you power it via USB from a powerbank or charger you have more headroom but the limiting factor is the 500mA fuse in line with the USB.

If you tap off that supply from a charger or powerbank as a 5V line (aka, cut the USB cable) the charger/powerbank is the limit

And the most complex, if you power it from 7V or more via the jack (or Vin) the heat dissipation in the on-board current regulator is leading. I would say, stay under 0,5W which is 250mA @ 7V or 100mA @ 12V.

I think it will work since the relay coil needs 15-20 mA. I'm supposed to received it thursday. I'll keep you update. Thanks for the help !