diyAudio

diyAudio (http://www.diyaudio.com/forums/)
-   Parts (http://www.diyaudio.com/forums/parts/)
-   -   Controlling a relay with a PIC microcontroller (http://www.diyaudio.com/forums/parts/88134-controlling-relay-pic-microcontroller.html)

rtarbell 12th October 2006 12:57 AM

Controlling a relay with a PIC microcontroller
 
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!

xplod1236 12th October 2006 01:09 AM

Should be fine.

Just curious, which uc are you using?

rtarbell 12th October 2006 02:11 AM

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.

xplod1236 12th October 2006 02:13 AM

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.

jackinnj 12th October 2006 02:20 AM

use a Darlington configuration on the switching transistor...

billr 12th October 2006 02:23 AM

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

Leolabs 12th October 2006 06:52 AM

Quote:

Originally posted by billr
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.

peranders 12th October 2006 07:29 AM

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.

RussB 12th October 2006 07:43 AM

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.

cpemma 12th October 2006 09:29 PM

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.


All times are GMT. The time now is 09:08 AM.


vBulletin Optimisation provided by vB Optimise (Pro) - vBulletin Mods & Addons Copyright © 2014 DragonByte Technologies Ltd.
Copyright 1999-2014 diyAudio


Content Relevant URLs by vBSEO 3.3.2