Controlling a relay with a PIC microcontroller - diyAudio
Go Back   Home > Forums > Design & Build > Parts

Parts Where to get, and how to make the best bits. PCB's, caps, transformers, etc.

Please consider donating to help us continue to serve you.

Ads on/off / Custom Title / More PMs / More album space / Advanced printing & mass image saving
Reply
 
Thread Tools Search this Thread
Old 12th October 2006, 12:57 AM   #1
diyAudio Member
 
Join Date: Sep 2005
Default 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!
  Reply With Quote
Old 12th October 2006, 01:09 AM   #2
diyAudio Member
 
xplod1236's Avatar
 
Join Date: Dec 2003
Location: On the couch
Send a message via AIM to xplod1236
Should be fine.

Just curious, which uc are you using?
  Reply With Quote
Old 12th October 2006, 02:11 AM   #3
diyAudio Member
 
Join Date: Sep 2005
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.
  Reply With Quote
Old 12th October 2006, 02:13 AM   #4
diyAudio Member
 
xplod1236's Avatar
 
Join Date: Dec 2003
Location: On the couch
Send a message via AIM to xplod1236
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.
  Reply With Quote
Old 12th October 2006, 02:20 AM   #5
diyAudio Member
 
jackinnj's Avatar
 
Join Date: Apr 2002
Location: Llanddewi Brefi, NJ
use a Darlington configuration on the switching transistor...
  Reply With Quote
Old 12th October 2006, 02:23 AM   #6
billr is offline billr  New Zealand
diyAudio Member
 
Join Date: Dec 2003
Location: new zealand
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
  Reply With Quote
Old 12th October 2006, 06:52 AM   #7
Leolabs is offline Leolabs  Malaysia
diyAudio Member
 
Leolabs's Avatar
 
Join Date: Dec 2004
Location: Bukit Mertajam
Send a message via MSN to Leolabs
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.
  Reply With Quote
Old 12th October 2006, 07:29 AM   #8
Electrons are yellow and more is better!
diyAudio Member
 
peranders's Avatar
 
Join Date: Apr 2002
Location: Göteborg, Sweden
Blog Entries: 4
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.
__________________
/Per-Anders (my first name) or P-A as my friends call me
Tube Buffered Gainclone in work |Thread || Diamond buffer |Thread for the group buy | Wiki
  Reply With Quote
Old 12th October 2006, 07:43 AM   #9
RussB is offline RussB  United Kingdom
diyAudio Member
 
Join Date: Oct 2006
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.
  Reply With Quote
Old 12th October 2006, 09:29 PM   #10
cpemma is offline cpemma  United Kingdom
diyAudio Member
 
Join Date: Jul 2003
Location: S Yorkshire OK
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.
  Reply With Quote

Reply


Hide this!Advertise here!
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SCR + Transformer Electronic Controlling saarcgsm Power Supplies 2 16th September 2008 09:19 PM
New way of controlling mid range dispersion. Snickers-is Multi-Way 6 21st April 2008 02:39 AM
Controlling power phreeky82 Parts 2 10th August 2007 04:45 PM
Controlling transient response AdamZuf Tubes / Valves 29 6th July 2007 01:38 AM
Problem controlling a PGA2310 daatkins Solid State 7 27th December 2003 02:54 PM


New To Site? Need Help?

All times are GMT. The time now is 03:35 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