Controlling a relay with a PIC microcontroller

Status
This old topic is closed. If you want to reopen this topic, contact a moderator using the "Report Post" button.
I am controlling a relay switch with a microcontroller. The relay coil is rated at 5V, and the microcontroller is rated at 5V (maximum output voltage per pin). One pin on a PIC microcontroller is rated to source or sink 20mA max. The coil resistance is 125 ohms and the coil rated current is 40mA, so I don't *think* the microcontroller itself will be suitable to directly control the relay.

I also have the option of buffering the microcontroller output by using a BJT (3904) as a switch (the coil would be in series with the collector of the BJT), so more current can be sourced for the relay coil. If I do this, then the relay would only get about 4.3V for activation (5V supply - .7V Vbe drop). Is this a problem for reliable operation, considering it is rated at 5V control voltage?

I'm just looking for a simple (and cheap) solution!
 
I am using the 10F222 which is one of the smallest of the small in terms of PIC microcontrollers. Now that I have the datasheet in front of me, I see that the max source/sink current per pin is 25mA, not 20mA.

Thanks for your reply! I will try a direct connection between uC and the relay.
 
Sorry, I meant you should be fine using the transistor (4.3 v across the realy). I didn't read your post carefully enough. I was going to mention paralleling 2 or 3 pins, but I just saw that your uc only has 4 i/o pins, so I think that is out of the question.

Which language are you programming it in?

So many edits....
125 ohm resistance will pull 20 mA from 5v. So either way, it should work.
 
hi.

I use the ULN2003. its a 16 pin DIL device, with 7 darlington drivers in it, excellent for simple connections to relays, of course if you only have one relay to drive it is overkill, I have about 14 to do, so it works out fine for me.

YMMV.

kind regards

bill
 
billr said:
hi.

I use the ULN2003. its a 16 pin DIL device, with 7 darlington drivers in it, excellent for simple connections to relays, of course if you only have one relay to drive it is overkill, I have about 14 to do, so it works out fine for me.

YMMV.

kind regards

bill

Yes.The ULN2003 is a good stuff.I have been using it with an ADC driving some DC12V relays without problem.Beside,it is cheap and easily available.
 
Using 5 V relay is not very smart, 12 V or more is better and you must use a transistors, plain one, darlington or a small mosfet like BS170. Don't forget to add a doide across the relay coil, otherwise you will break the transistor, eventually. Cathode towards "+".

Worth noticing is that the ULN driver has built-in freewheeeling diodes.

It is not recommendable at all to drive a relay directly from an MCU output.
 
Check the relay data sheet for the minimum operating voltage, these are normally expressed as 'pull-in' and holding voltage. If the pull-in is within 4.3V, then you should be fine. Don't forget a diode accross the relay coil to suppress back-emf when the relay releases.
 
With relay on the 2N3904 collector, emitter to ground, drop is only about 200mV; it's VCE(sat) not VBE.

Most 6V relays will switch OK with 4.8V, though level-shifting to a 12V coil is no problem with an NPN switcher.

You will need a base resistor to limit the PIC current, say 470R for about 5mA, and an inverse diode across the coil. The ULN2803A is an 18-pin 8-channel darlington device with both diodes and base resistors built-in.
 
Status
This old topic is closed. If you want to reopen this topic, contact a moderator using the "Report Post" button.