PDA

View Full Version : Transistor Selection for Switching Relay Coil-with a little bit of info on my "ARSC"



rxforspeed
- 30th October 2008, 05:49
Hey guys-I'm racking my brains trying to figure out 1) which transistor to use and 2) how to wire it into my current project to use it for switching a 5V relay coil. The code for the project, my "A.R.S.C." (Air Ride Smart Controller), isn't written yet-I want to make sure I've got the hardware aspect of the project covered to ensure correct operation with the proper code, but I've pretty much got most of the code layed out; I just need to play with a few variables and determine which pins will operate relays, which will read the sensors, etc. I'm hoping I can at least get all the hardware right the first time; I don't really have the option to "breadboard" this project, but I did get a PICkit 2 (another great thing this forum has introduced me to) so the code can be changed via ICSP "on the fly", a lot easier than I can change out a transistor or other hardware component.

I have found at least two other threads on this forum and a few other schematics to go by, but I'm not 100% sure what I have found is compatable with my project. I have done my research, but I wanted to get the opinion(s) and help of somebody that's basically done the same or similar thing with PIC MCUs, somebody who actually knows what they're doing with not only the MCUs, but with transistors (or a similar circuit) also...

The MCU I'm using with this project is a 16F690, mostly for the A/D channels (I'll only need a total of six including the Vref-one per corner of the car/air spring and another for the tank pressure sending unit), the extra code space (4K, more than most smaller devices) for future upgrades/expansion, and the fact that I have about ten or so on-hand. I'm using PCB-mount Omron G5LA-14 5VDC coil relays (SPDT) with a 1N4001 diode placed across the coil for protection (the MCU outputs to the relay aren't wired up yet, but will be wired to the correct side of the relay's coil in regard to the diode once I know exactly how the circuit will be layed out). The relays are only switching automotive 12VDC current (depending on the state of the battery and alternator, somewhere in the neighborhood of 9V-14.7/15V max) at less than one amp (I believe) to operate the SMC brand "air valves", or pneumatic solenoids to control the flow of air into the air springs (or 'bags) based on the pressure reading obtained from oil pressure sending units installed in each corner and in a tank port on this particular vehicle. The sensors were part of a digital gauge kit designed for air ride applications; even though the sensors were made to work with oil, they still work within a 4psi accuracy (from 100psi or less) when used with compressed air.

My current dilemma is choosing the right transistor to install between the MCU and the relay. I plan to drive the selected output pin that controls a single relay "high" for a fraction of a second when the analog input that controls it's function gets a "low psi" reading (a small analog voltage signal-under 1.525VDC-from the sending unit that will be preset for this prototype, a non-adjustable constant in this version), then re-checks the psi level and either continues to open the valve (back to same loop if pressure still isn't at it's correct level) or goes on to check the other pressure levels in their respective corners of the vehicle (moves to next corners' pressure reading subroutine)...

I believe it was on this forum that I read it was highly recommended to use a transistor to "drive" a relay instead of powering the unit directly from CMOS levels. I have a vast array of transistors on hand, mostly plain ol' bi-polar NPN's and PNP's; not many FET's, BJT's, etc. Transistors are one thing that I don't really know much about; I can solder or install one from a schematic to a circuit or breadboard, but as far as using one in a circuit of mostly my own design I have no clue how to properly choose them. If anybody mentions getting my hands on a copy of "The Art of Electronics", I've had my local library order it (I can't believe they didn't have it in stock!) so I could browse through it before buying a copy of my own (it's still not in yet)...

One frustrating fact is that I don't know how to check and determine which lead is the collector, base, or emitter. I don't have an oscilliscope but I do have a nice Fluke multi-meter. I keep meaning to order a "transistor tester" or a kit/tool that determines whether the transistor inserted in it is an NPN or PNP and lets you know which leads are what. I've seen a couple of them in online stores but have never ordered one because I haven't really needed it until now. I need to get one soon...

I have a few MPSA2222A's that I thought were the same as (or very similar to) 2N2222(A)'s or PN2222(A)'s, but they apparently aren't. I could only find datasheets for T0-18 case 2N2222's, and the ON Semiconductor datasheet I found for the PN2222(A) did NOT have the same leads/pin-out as the MPSA2222A's I have on hand (when I hooked what the datasheet said was the collector to +9VDC and what was supposed to be the emitter to the 9V battery's ground terminal, that little thing quickly heated up to "burning hot"-I played around with a couple others, testing each with my Fluke meter to verify that 9V stayed on the display; I noticed that each one only got hot when the Fluke display's DC voltage was dropping-one reached 1.6V before I removed it and felt like it was about to explode; yes, I disposed of each one that warmed up), so I really need a method for determining which lead is which, especially on some of the lesser-used/known transistors I have. I do have quite a few 2N3904's, 2N3905's, 2N3906's, and a great deal more of what some would consider "common" transistors. Some of the more common ones should have the same pin-outs regardless of the brand, shouldn't they? I do have at least one manufacturer's datasheet saved for almost each transistor I have, but most of them don't have the manufacturer's logo or name printed on their T0-92 cases...

To sum the above novel up into a single-dual question, what transistor would be best to use in my case and how do I wire up the collector, base, and emitter of said transistor for use as "driving" a relay-installed between the PCB mounted 5VDC coil of the relay and the PIC16F690 20DIP MCU. I'm planning on driving the selected output pin "high" on the MCU to activate the relay, but I could change it's state to low-with the other side of the coil attached to +5V, if that's what is recommended and works correctly and reliably. Whatever would be the most reliable and dependable choice for this application is what I need-I don't care to buy a few more expensive T0-220 transistors if that's going to create a better and more dependable finished product compared to any T0-92 case transistor I have...

Also, if anybody knows any good tips or tricks on how to determine whether a transistor is an NPN or PNP stlye (or even determining/deciphering whether the transistor in quesion is bi-polar, an FET, BJT, Darlington, etc.) and how to figure out which leads are the collector, base, and emitter (that's a definate need for the cheap off-brand assortment of transistors I have on-hand), I would greatly appreciate any of them. Thanks in advance for any and all information and help you guys can give me; believe me, it's greatly appreciated!

Sincerely,
-Adam Collins

mackrackit
- 30th October 2008, 07:27
What is the coil rating is amps of the relay coil? If not known then what is the resistance?
If the amperage is less than 20ma then there is know problem driving it from the PIC as long as you have a fly-back diode installed. You need the fly-back for the transistor too.

The above info is needed even if you use a transistor.

Simplify things a bit. What is the amperage if the valves that the relays will be controlling?
Then we pick a MOSFET to drive the device directly doing away with the relay and transistor.

Melanie
- 30th October 2008, 09:33
I wouldn't have any Relays on the PICs 5v Rail if I could possibly avoid it.

Have a 12v Relay on the 12v line if you have one available, use any medium power NPN Transistor (Emitter to 0v, Collector to Relay). The other end of the Relay is connected to +12. Drive the Transistor Base from the PIC's I/O via a suitable current limiting Resistor (value depends on selected Transistor). You will still need a Diode reverse connected across the Relay coil (Kathode to +12, Anode to Transistor Collector).

If you are driving multiple Relays, it's less hassle to put in something like a ULN2004. No Resistors needed, you can connect it directly to your PIC, and the suppression Diodes are built-in.

If you are using ADC or Comparators, and if you are using the 5v rail as VRef, put NOTHING on your PICs 5v line that will unnecessarily load it, spike it, or in any way abuse it - and a Power Relay will.

mackrackit
- 30th October 2008, 17:54
rxforspeed,

If advice is given Melanie and myself, go with Melanie's. She is one of the people I am learning from :D

But just for the record. I do have two automatic punch presses using relays to control the solenoids ( air and hydraulic ). I picked the relays to work directly from the PIC. I can not remember why I went that direction, I normally use a MOSFET. Both machines run five days a week and run between 2,000 and 8,000 parts a day depending on the part punched. One machine has been in operation for five years and the other for four.

rxforspeed
- 30th October 2008, 20:16
What is the coil rating is amps of the relay coil? If not known then what is the resistance?
If the amperage is less than 20ma then there is know problem driving it from the PIC as long as you have a fly-back diode installed. You need the fly-back for the transistor too.

The above info is needed even if you use a transistor.

Simplify things a bit. What is the amperage if the valves that the relays will be controlling?
Then we pick a MOSFET to drive the device directly doing away with the relay and transistor.

Omron's datasheet for the relay specifies "360mW coil consumption (max)", and the resistance of the coil averaged around 67-Ohms for the four relays I have mounted on the PCB. The amp rating printed on the top of the relays is 10A at 250VAC (N.O.).

Here's a link to the same valves we're using: http://www.coastpneumatics.net/displayitem.php?keyword=VXD2130-03N-6G
They're the NC 12VDC VXD21XX parts. A link to the PDF datasheet is listed on that page...

Even that datasheet for the valves doesn't give a lot of information, and they're not in front of me at the present time to check with my Fluke meter. I found a 6W holding power consumption rating in the datasheet for the style of valve we're using; that would put the amperage near 0.5A, wouldn't it (with a 12VDC automotive electrical system)? That would still be over the PIC's 20mA output, so I'm assuming that I would need a MOSFET (or transistor array IC, transistor of another kind, etc.)...


I wouldn't have any Relays on the PICs 5v Rail if I could possibly avoid it.

Have a 12v Relay on the 12v line if you have one available, use any medium power NPN Transistor (Emitter to 0v, Collector to Relay). The other end of the Relay is connected to +12. Drive the Transistor Base from the PIC's I/O via a suitable current limiting Resistor (value depends on selected Transistor). You will still need a Diode reverse connected across the Relay coil (Kathode to +12, Anode to Transistor Collector).

If you are driving multiple Relays, it's less hassle to put in something like a ULN2004. No Resistors needed, you can connect it directly to your PIC, and the suppression Diodes are built-in.

If you are using ADC or Comparators, and if you are using the 5v rail as VRef, put NOTHING on your PICs 5v line that will unnecessarily load it, spike it, or in any way abuse it - and a Power Relay will.

I do have a 12V line on the PCB; it supplies power to the 5V regulator (7805's are the only dedicated 5V regulators I have on-hand, but future versions may incorporate either an LM2931T-5.0 or LM2940CT-5.0 automotive 5V regulator) and will be the tie point for the incoming switchd ignition hot power wire.

I don't have a problem ordering a few 12VDC relays, I had just foolishly bought about fifty of the 5VDC versions for this specific purpose. I wish I would've found this forum before placing that order...

The ULN2004 you mentioned-is it similar to the Motorola ULN2068B (quad high-current Darlington array) or the TI ULN2803A (eight NPN Darlington transistor array)? I don't have any of those on-hand, but I can order whichever would be the best for my project with the 12V relays, most likely a quad array because I really only have room for four relays on the prototyping PCB this circuit is being built on...

I can see why you've recommended what you have-mostly for protection of the PIC and it's A/D Vref (which will be connected to the 5V rail through a resistor-a value yet undetermined-that will reduce the voltage to 1.525V for greater accuracy within the psi range we'll be working with-100psi and less). It makes sense, and I can (for the most part) comprehend and picture it's lay-out. This method would still require a CMOS "high" output from the PIC to the base of the transistor (or array), correct? That would make the transistor act as a switch, grounding the collector side of the transistor (which is connected to the 12V relay coil) through the emitter when the CMOS "high" is applied to its' base from the PIC's output pin. I still get confused with "anode" and "cathode" terminology for diodes (but not LED's), so the +12 would connect to the striped end of the diode (to block +12V from passing through to the other side) and the opposite end without the stripe would connect to the negative (0V) side of the relay coil (for the same purposes, only with negative current), right?

I do believe I'll order a transistor array-that way there's no confusion as to which lead is which and I can make sure I get the proper datasheet from the same manufacturer. I'll need four 12VDC "sugar cube" PCB mounted relays, a quad NPN transistor array (like the ULN2004 or the ULN2068B), and I'm assuming it would be OK to leave the 1N4001's in place as long as they're connected correctly, right? I do believe I'm going to order a good "transistor tester", like this one from www.electronickits.com: http://www.electronickits.com/kit/complete/meas/dt100k.htm

rxforspeed
- 30th October 2008, 21:02
rxforspeed,

If advice is given Melanie and myself, go with Melanie's. She is one of the people I am learning from :D

But just for the record. I do have two automatic punch presses using relays to control the solenoids ( air and hydraulic ). I picked the relays to work directly from the PIC. I can not remember why I went that direction, I normally use a MOSFET. Both machines run five days a week and run between 2,000 and 8,000 parts a day depending on the part punched. One machine has been in operation for five years and the other for four.

No need to be so modest, Dave. ;) You still have WAY more experience than I do, so your input is extremely valuable to me-just as much as Melanie's...

So I take it your punch presses don't have a massive flywheel like a small manual punch (the kind I have more experience operating)? Are these massive industrial punches or smaller interchangable die style punches? Sorry to jump off topic, but this is an area that really interests me...;)

Thanks for all the help, guys (and gal)...

Sincerely,
-Adam Collins

mackrackit
- 30th October 2008, 22:27
So I take it your punch presses don't have a massive flywheel like a small manual punch (the kind I have more experience operating)? Are these massive industrial punches or smaller interchangable die style punches?

These were built to replace the massive flywheel manually operated types. They are more along the lines of the smaller type but the dies are a custom build.

Picture a 6 inch cylinder driven by a two stage pump on a 15 hp electric motor. That pushes the punch. The other one has two 4 inch cylinders in parallel driven the same way.

One is designed to punch a set of holes through a 1/4 x 6 x 6 inch piece. The other will take two pieces of 1/4 x 2 x 2 angle and punch a set of holes along with shearing the ends at 45 degrees on one step.

The plate punch has a feeder that uses an air cylinder to push the part into place from a stack. The angle punch uses a hydraulic cylinder to feed the parts.

Both machines have sensors, (pressure, mechanical, IR ) to control the operation and check for mechanical errors, like a stuck part or no parts.

Sorry to jump off topic, but this is an area that really interests me...;)
It is your thread :D

rxforspeed
- 31st October 2008, 08:39
These were built to replace the massive flywheel manually operated types. They are more along the lines of the smaller type but the dies are a custom build.

Picture a 6 inch cylinder driven by a two stage pump on a 15 hp electric motor. That pushes the punch. The other one has two 4 inch cylinders in parallel driven the same way.

One is designed to punch a set of holes through a 1/4 x 6 x 6 inch piece. The other will take two pieces of 1/4 x 2 x 2 angle and punch a set of holes along with shearing the ends at 45 degrees on one step.

The plate punch has a feeder that uses an air cylinder to push the part into place from a stack. The angle punch uses a hydraulic cylinder to feed the parts.

Both machines have sensors, (pressure, mechanical, IR ) to control the operation and check for mechanical errors, like a stuck part or no parts.

It is your thread :D


Wow-those sound a lot more advanced than any of the basic fab shop equipment I've operated before-presses, slip rolls, shears, etc. I've got years of experience working in fab shops, welding and fabrication, and various other contract fab work (such as building smaller industrial cleaning tools and equipment), but most of the punches I've ran were actually quite dangerous-they were all manual and nothing was electrical except for the 240/480VAC motors that powered up the flywheels. No sensors, pneumatic loaders, hydraulic ejectors, etc.-just one person trying to keep from losing a finger or a hand while holding what could sometimes be a quite large and heavy plate while at the same time trying to keep it centered in the punch. I'm sure quite a few shops have more sophisticated equipment like yours, but the places I had worked for were just getting CNC press and leaf brakes just a couple of years ago.

Since I've gotten into electronics, I've found so many possible uses for MCUs and potential products that could be built and marketed rather inexpensively on a smaller scale. These things are used in toothbrushes, toys, industrial and medical equipment; every USB programmer I've seen has an 18F2550-the possibilities are limitless. Every day we're making even greater technological advancements and improvements, so I figured I was way past due to check out what this field had to offer, and I'm glad I did. I enjoy working with electronics more than I do anything else, which is the number one reason I'm going back to school for a bachelor's in Electronic engineering. My ultimate goal is to have my own business, whether it's manufacturing products on a small to medium scale or contract work involving programming and creating software for bigger corporations. The demand for programmers and software creators for custom applications grows constantly, almost daily at an astonishing rate. To be honest, it's pretty scary thinking about what our children's and/or grandchilden's career options will be-even before the next century. I believe, possibly within our own lifetimes, pretty much every job and or career that humans take for granted today could very well be replaced with an automated system or robotic application-given the time and the rate of growth and expansion of the technology...

Think about it-in most situations in "war", combat, or possible hostile territories, we have un-manned aircraft and robotic surveyers. That's actually great for saving the lives of our brave soldiers, but that technology is being adapted into more than just our armed forces. A great deal of jobs have been lost in many industries (especially the automotive industry) within the past ten to twenty years due to automated robotic systems-assembly line part/component installers, welding robots, automated automotive painting robots, etc. The list continues to grow and more people are laid off and unemployed because their work has been completely automated by machines. Instead of corporations paying hourly, weekly, or yearly wages or salaries to human workers, they invest a single or few workers yearly salaries or wages into the construction of an automated robotic system that doesn't need to be paid, needs no breaks or sleep, never complains or goes on "strike", only really needs minor periodic maintenance, makes WAY less errors or mistakes (if any at all) than the human worker(s) it's replaced, etc. It really scares me to think how that technology will be carried over into mid-sized or even small businesses/corporations in the next few decades. Are you paranoid that some jerk-off at Mickey D's might cough or spit (or possibly something even worse) in your order-especially if you have to send it back because of a mistake on their part? Imagine walking into your local fast food joint, pushing a few buttons on screen at the counter to place your order and receiving it exactly as ordered, prepared by an automated robotic system without any human workers present to touch your food. It's very possible that could happen in a matter of just a few years...

Well, I've jumped pretty far off topic (both of the previous ones mentioned in the last few posts) and I'm up WAY past my bedtime, so I think I'll start a new topic in the "Other" section of the forum to attempt to discuss some of these possibilities with others when I get a chance tomorrow. I'd really like to see how others view this dilemma. The more our technology advances, the more likely systems like these are going to continue to drop in price and become more available and attractive to not only large manufacturers and corporations, but small and medium-sized businesses as well. Sooner or later, I sincerely believe that any and all jobs that were once handled by people will be fully automated and handled by machines or robotics, at least in some form. I just hope it doesn't affect my 8-year-old son by the time he graduates high school in a little over nine years, and hopefully his graduation from college four or more years after that (I won't MAKE him go right after high school, but I've tried my best to get him to work on programming these PIC MCUs, building some smaller "spy gadget"-style circuits, and electronics in general; hell, I've even paid him $4USD/hour to mostly watch and "help" me assemble a few circuits here and there, which is a great rate for a kid who's not even old enough to work yet, but he'd still rather play ball and skateboard with his little "skateboard punk" friends than become a "geek" like I have in the past year or so)...

If any of you guys/gals would like to share your opinions/thoughts/concerns about that topic, just look for a new thread in the "Other" section of this forum-hopefully sometime tomorrow...

In the meantime, I'll go ahead and order the parts that Melanie had suggested and I'll post any other questions, comments, concerns, or additional cries for help here after I receive those. I think I've got the hardware aspect of the "A.R.S.C." project figured out now, but I'm sure I'll have a few questions about certain code snippets that I'll post under the "Code Examples" section when I get to that point.

Again, thanks for your time, help, cooperation, and patience with me while I build this project. Any and all input is greatly appreciated, so please don't hesitate to correct me, criticize me, help me, or just straighten me out in the event I've forgotten an important or critical part/component/or anything else that would be a major mistake or cause a malfunction with this prototype. I truly appreciate the help, direction, guidance, and input you all have given me so far-I promise you it's not in vain. I've already learned quite a bit from this forum and I hope to continue to learn as much as I possibly can through the knowledge and wisdom of people like you, Dave and Melanie. I greatly appreciate the information you've shared with me so far...

Thriving for more knowledge,
-Adam Collins

Melanie
- 31st October 2008, 09:17
You won't need Diodes across the Relays, or any other components with the ULN2004 - they're all built-in to the chip, which makes it neat and easy to connect. Download the Datasheet for the chip. The pin with all the Diodes internally connected to it is wired to +12v. +12 also goes to one side of your Relay. The other side connects to one of the seven Output channels. The input to the channel connects to the PIC I/O. Drive High for Relay ON, and Low for Relay OFF. Unused channels can simply be left unconnected. Good practice states you ground the unused inputs, but you don't have to on this part.

There's nothing wrong with putting Relays on your 5v line if your 5v PSU is solidly built (and it looks like Dave builds solid gear!). Most folks on this list are hobbyists or new to electronics. The chances of building a crappy supply are high, putting a heavy load (Power Relay Coil) onto the same voltage line that becomes a REFERENCE for your ADC or Comparators is asking for trouble at best, and at worst is going to start resetting your PIC by tripping it's MCLR or corrupting EEPROM.

rxforspeed
- 31st October 2008, 20:34
You won't need Diodes across the Relays, or any other components with the ULN2004 - they're all built-in to the chip, which makes it neat and easy to connect. Download the Datasheet for the chip. The pin with all the Diodes internally connected to it is wired to +12v. +12 also goes to one side of your Relay. The other side connects to one of the seven Output channels. The input to the channel connects to the PIC I/O. Drive High for Relay ON, and Low for Relay OFF. Unused channels can simply be left unconnected. Good practice states you ground the unused inputs, but you don't have to on this part.

There's nothing wrong with putting Relays on your 5v line if your 5v PSU is solidly built (and it looks like Dave builds solid gear!). Most folks on this list are hobbyists or new to electronics. The chances of building a crappy supply are high, putting a heavy load (Power Relay Coil) onto the same voltage line that becomes a REFERENCE for your ADC or Comparators is asking for trouble at best, and at worst is going to start resetting your PIC by tripping it's MCLR or corrupting EEPROM.

I will download the datasheet for the ULN2004 in the next few minutes, before I place my order for these parts. As for the power supply, could I get by with installing an additional 5V regulator (7805, LM2931T-5.0, LM2940CT-5.0, etc) to power a seperate 5V rail for the 5V relays that would be pretty much isolated from the PIC's 5V supply?

Don't get me wrong, I'm going to take your advice and install the 12V relays on this prototype, but I've got a lot of the 5V versions of the relays and figured that if the additional regulator would allow me a "clean and solid" power supply, then I could go that route for the next project I build using the 5V relays.

I usually always install both a 10uF (50/63V electrolytic) and a 0.1uF (200V ceramic) input cap on the inlet side of the regulator (and in this case, from +12V to ground), as well as the same type and value capacitors on the output side of the regulator as bypass caps. Is this sufficient for a solid power supply; it will be connected to the vehicle's ignition hot or to a constant hot fused position by means of a SPST switch so it only operates when the owner wants it to. I know that sometimes the alternator can cause voltage spikes and current surges throught some components, so I really plan on getting my hands on some good automotive 5V regulators like the LM2931T-5.0 (only 500mA in a T0-220 package) or the LM2940CT-5.0 (1-1.5A in a T0-220 package), which both have built-in protection designed for these types of spikes and surges...

Melanie
- 1st November 2008, 03:13
That's fine. Your isolating the PICs supply from that used for other significant switching loads, which is the whole idea. What that 'other' supply becomes, is irrelevant.

I really can't comment on the size of your Capacitors without knowing what your total worst-case load will be and what is actually going to be used as the Regulator. Build it and see...

If it's an automotive application, you should really be using 12v Relays. All you are accomplishing (other than using up your stock of 5v components) is heating up the planet! When the ice caps melt, it's now public knowledge that it'll be YOUR fault.

rxforspeed
- 1st November 2008, 23:29
That's fine. Your isolating the PICs supply from that used for other significant switching loads, which is the whole idea. What that 'other' supply becomes, is irrelevant.

I really can't comment on the size of your Capacitors without knowing what your total worst-case load will be and what is actually going to be used as the Regulator. Build it and see...

If it's an automotive application, you should really be using 12v Relays. All you are accomplishing (other than using up your stock of 5v components) is heating up the planet! When the ice caps melt, it's now public knowledge that it'll be YOUR fault.

I'm sure the "carbon footprint" of my modified vehicles doesn't exactly qualify me as an "environmentalist", either. ;)

As for your suggested components, I have downloaded the datasheet for the ULN2004 and briefly read through it. Since I'm currently classified as a "student" (even though my classes don't begin until January), I've requested some samples of both the ULN2004 and the ULN2803 from TI, but at least ten of each are on my next Digikey purchase, which will be placed before the end of this weekend. The 12V relays are coming from both Digikey (two different kinds-Omron's G5LA series and Tyco's PB114012-eight of each for the time being) and anykits.com (along with a few additional PIC peripheral components and development boards). I should have both orders in by the 6th, so I'll concentrate on writing the code for the '690 in the meantime...

I made sure to download the correct manufacturer's datasheet for both transistor arrays...

Again, I really appreciate the time you've taken to help me out with this. It's people like you (Melanie and Dave) that make this forum a wonderfully educational site that I'm proud to be a part of. Thanks to you guys, I'm sure that my "A.R.S.C." project will be a success...

Sincerely,
-Adam Collins

RussMartin
- 2nd November 2008, 00:47
My personal choice, at the tinkering stage, would be to use a plain old 2N7000 MOSFET to drive each relay (with flywheel diode, of course).

Multiple device drivers are handy and certainly have their place, but they also have some inherent limitations, one of which is the total power dissipation available in the DIP package. For example, see the thermal curves for the ULN2004.

rxforspeed
- 2nd November 2008, 04:28
My personal choice, at the tinkering stage, would be to use a plain old 2N7000 MOSFET to drive each relay (with flywheel diode, of course).

Multiple device drivers are handy and certainly have their place, but they also have some inherent limitations, one of which is the total power dissipation available in the DIP package. For example, see the thermal curves for the ULN2004.

In all honesty, I'll most likely build two, three, or four prototypes of this project. I've installed the air ride suspension and all the related components on the vehicle that this project will control, but I've got a couple of other friends wanting to go the digital route with their air ride suspensions and have push-button control over their ride height/psi level as well. So instead of using up my solder braid to remove the 5V relays, I'll start fresh with a new prototyping PCB (www.anykits.com #K003, the only thing I dislike about it is the single-sided copper clad) and build the new one for the "Phantom" (the vehicle I installed the air ride on-a Johnson Motor Company re-worked '88 Pontiac Firebird, Nova/Chevy II front frame clip, and custom fiberglass work to resemble an older Rolls Royce Phantom) with Melanie's suggested parts. When I placed the orders, I did happen to find a good deal on a few IRF540 N-channel MOSFETs in a T0-220 package, so I picked up a few of those in hopes to use with either the 5V relay PCB or for a different future project when the need arises (and I learn a bit more about transistors)...

I'll build the important prototype-the "Phantom's"-with Melanie's suggested parts, but I don't want to discard the other. If nothing else, I'll be able to teach myself something about transistors along the way with it. I have enough 16F690's to be able to fry one or two without worry...

Remember-I'm still a "noob" in the general area of electronics, but I'm a quick learner. Thermal curves on datasheets aren't usually something I study at the time being, but I WILL compare the ones on both of the transistor array datasheets I've ordered (the ULN2004 and the ULN2803A) and the IRF540 and 2N7000 MOSFETs.

Are you familiar with the IRF540, Mr. Martin? Regardless, I know what I need to do to figure out if it's interchangable with the 2N7000 you've recommended-download and read the datasheet. The most visited site on my notebook (and the one I download the most from) is probably www.datasheetarchive.com...

Thanks for all the input, info, and help you guys have given me, I sincerely appreciate it. It seems I've learned something new with almost every post on this topic, and of course there's always more than one way to skin a cat, SOOOO...even if I do use the board with the 5V relays it'll most likely go to a buddy of mine that only drives his air ride equipped truck for a few hours on nice, sunny weekends. I don't think that would contribute a great deal to melting the polar ice caps... ;)

Back to "The Art of Electronics"...
-Adam Collins

Acetronics2
- 2nd November 2008, 11:43
Hi, Rx

Sorry for NOT having read all your explanations in details ( Difficult for me to read BIG pieces of prose on the screen ...)

BUT

There's one thing I didn't see in all these posts ...

use a RC filter between Relays supply and Pic Supply ... Small R ( 10 - 100 Ohms ) not to drastically reduce PIC voltage and BIG C ( 1000 + µF -Low ESR is best- ).

The only Drawback is to power the possible Leds from the relay side of the RC Filter ( inverted logic, then ) ... not too difficult, in fact; and also use an external ref. for ADCs.

For ULN 2x0x ... keep in mind those are Darlingtons outputs ... so Vce sat ~1 v ... 5v - 1v = not so much for 5v relays ...

Now ... for the Ice Cap ... nothing keeps you away from using a switching regulator like LM 2575 ... instead of a linear low drop '2940.


In the end ... do not forget to play the S.Gainsbourg 's tune "Melody Nelson" ... more than perfect for THE Phantom atmosphere.

Alain

Pic_User
- 3rd November 2008, 00:55
Hi Adam,

....what transistor would be best to use in my case and how do I wire up the collector, base, and emitter of said transistor for use as "driving" a relay-installed ...
2N3904, 2N4401, 2N2222, PN2222 are suitable to actuate a small relay.

<IMG SRC="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=2959&stc=1&d=1225669430">


... I do have quite a few 2N3904's, 2N3905's, 2N3906's, and a great deal more of what some would consider "common" transistors. Some of the more common ones should have the same pin-outs regardless of the brand, shouldn't they? I do have at least one manufacturer's datasheet saved for almost each transistor I have, but most of them don't have the manufacturer's logo or name printed on their T0-92 cases...
Transistors of the same number almost always have similar pin placements, not always!

<IMG SRC="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=2958&stc=1&d=1225669266">


....Also, if anybody knows any good tips or tricks on how to determine whether a transistor is an NPN or PNP style (or even determining/deciphering whether the transistor in question is bi-polar, an FET, BJT, Darlington, etc.) and how to figure out which leads are the collector, base, and emitter (that's a definite need for the cheap off-brand assortment of transistors I have on-hand), I would greatly appreciate any of them. ....
Sincerely,
-Adam Collins
The best way to tell the type of transistor, is the transistor number. The best way to tell the “pin-out” is the data sheet.

My personal choice, at the tinkering stage, would be to use a plain old 2N7000 MOSFET to drive each relay (with flywheel diode, of course).

Multiple device drivers are handy and certainly have their place, but they also have some inherent limitations, one of which is the total power dissipation available in the DIP package. For example, see the thermal curves for the ULN2004.
True, plain old 2N7000 MOSFET, or plain old BS170 MOSFET is a good choice if you have them on hand.
<IMG SRC="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=2960&stc=1&d=1225669503">

I wouldn't have any Relays on the PICs 5v Rail if I could possibly avoid it.

Have a 12v Relay on the 12v line if you have one available, use any medium power NPN Transistor (Emitter to 0v, Collector to Relay). The other end of the Relay is connected to +12. Drive the Transistor Base from the PIC's I/O via a suitable current limiting Resistor (value depends on selected Transistor). You will still need a Diode reverse connected across the Relay coil (Kathode to +12, Anode to Transistor Collector).

If you are driving multiple Relays, it's less hassle to put in something like a ULN2004. No Resistors needed, you can connect it directly to your PIC, and the suppression Diodes are built-in.

If you are using ADC or Comparators, and if you are using the 5v rail as VRef, put NOTHING on your PICs 5v line that will unnecessarily load it, spike it, or in any way abuse it - and a Power Relay will.The ULN2004 is a real space saver for multiple relays.
-Adam-

rxforspeed
- 3rd November 2008, 03:19
Hi, Rx

Sorry for NOT having read all your explanations in details ( Difficult for me to read BIG pieces of prose on the screen ...)

BUT

There's one thing I didn't see in all these posts ...

use a RC filter between Relays supply and Pic Supply ... Small R ( 10 - 100 Ohms ) not to drastically reduce PIC voltage and BIG C ( 1000 + µF -Low ESR is best- ).

I don't believe that anybody else has mentioned installing a filter between the PIC and the relays, only isolating the relay coils from the PIC's power supply. I'll have to study that section in "The Art of Electronics" before I connect the relays to the PIC's I/O pins on the 5V relay board(s)...



The only Drawback is to power the possible Leds from the relay side of the RC Filter ( inverted logic, then ) ... not too difficult, in fact; and also use an external ref. for ADCs.

I'm sure you meant LEADS here, right? ;) That does bring to mind another idea I had-connecting LEDs to the PICs' I/O pins that will power the relay coils. I've found some schematics using 5V relays and NPN transistors that also incorporate an LED per relay coil into the design. I'm sure I can just follow those if I decide to use the LEDs; that'll just be a simple visual indication of the relay's correct operation (they'll only be on for about 100msec at a time, anyway)...



For ULN 2x0x ... keep in mind those are Darlingtons outputs ... so Vce sat ~1 v ... 5v - 1v = not so much for 5v relays ...

I've studied the datasheets on both the arrays I've ordered, and I believe I'll only use those for the 12V PCB-mounted relays that Melanie had suggested. I'll either use a MOSFET or an NPN transistor to switch the 5V relays on the other board(s)...



Now ... for the Ice Cap ... nothing keeps you away from using a switching regulator like LM 2575 ... instead of a linear low drop '2940.

I'm not familiar with the '2575, but I'll download the datasheet and compare it to the other regulators I've thought about using. Remember, I don't yet have the education you do-I'll only be starting my "higher education" this coming Spring semester (so you can rightfully still consider me a "noob")...



In the end ... do not forget to play the S.Gainsbourg 's tune "Melody Nelson" ... more than perfect for THE Phantom atmosphere.

Alain

A "Phantom of the Opera" melody? I can't claim to be familair with that tune-my musical background has been limited to songs that I've learned to play on guitar, attempted to learn, or wanted to learn, and most of those were Rock/Classic Rock/Hard Rock/Metal (not the horrible death-crap, but good music like Zakk Wylde's BLS). Classical music is rather relaxing, but I wouldn't be able to differentiate between Mozart and Beethoven (sp?) if I had to. I'm sure the owner of the "Phantom", an elderly man in his seventies, would probably recognize the tune...

BTW-Sorry for the "long-winded" post, this really is an attempt to stick to the facts and details without going to far overboard...


Hi Adam,

2N3904, 2N4401, 2N2222, PN2222 are suitable to actuate a small relay.

Thanks for the schematic! I've seen a similar schematic used with Holtek's HT12D decoder IC, but even that datasheet didn't tell me whether a "high" or "low" CMOS level was output from the IC to the transistor...



Transistors of the same number almost always have similar pin placements, not always!

I've got datasheets for most of the transistors I have on-hand, but I'm sure some manufacturers don't follow an "industry standard". I had played around with a few different cheaper transistors from a different manufacturer (unknown) than I had the datasheet for, and the pin-out obviously wasn't the same. No more cheap transistors for me, I'll pay extra to know that the pin-outs on the datasheets I have are correct...



The best way to tell the type of transistor, is the transistor number. The best way to tell the “pin-out” is the data sheet.

What I had meant by the "off-brand" transistors was a cheap $4 order from e-bay for about 700pcs of two different kinds of transistors, 2N3905 PNPs and 2N3563 NPNs; neither of them have ANY markings whatsoever. They came in seperate and labeled bags, but that's one of the main reasons why I need the transistor "tester". No manufacturer name, markings, anything-just a plain black T0-92 package...



True, plain old 2N7000 MOSFET, or plain old BS170 MOSFET is a good choice if you have them on hand.

I've got a few 2N7000's (T0-92) on-hand. I figured I did after I checked the "My Datasheets" section of "My Documents" (under the N-Channel FET folder) and found the datasheet for it. The schematics you posted will definately help me out with the 5V relay board-thanks a lot!



The ULN2004 is a real space saver for multiple relays.
-Adam-

There's currently only four relays on-board this prototype, but I'm sure I'll have one or two others down the road with eight or more relays to control not only the "fill" valves to compensate for minor leaks over time and keep a single preset ride height/psi level, but for multiple and possibly user-adjustable ride height/psi level settings that will operate all four "fill" valves and all four "dump" valves per vehicle...

GLCD commands would come in handy here for a custom gauge display, and possible touch panel controls...but there's already a digital psi gauge in the "Phantom", I just need to control the air in the 'bags for this application.

Thanks again for all the help and cooperation with this, I really have gained a better understanding (of at least one application) of where and how to use transistors and transistor arrays and a good basis for using relays with PICs. All your input and suggestions are greatly appreciated!

Sincerely,
-Adam Collins

RussMartin
- 3rd November 2008, 06:03
Are you familiar with the IRF540 . . . ?


It strikes me as overkill for driving garden-variety relays. Do you need that kind of current and voltage capability? The 2N7000 is a venerable old workhorse good to 60 VDC for up to 200 mA continuous duty.

rxforspeed
- 4th November 2008, 06:27
It strikes me as overkill for driving garden-variety relays. Do you need that kind of current and voltage capability? The 2N7000 is a venerable old workhorse good to 60 VDC for up to 200 mA continuous duty.

True, I had noticed that on the datasheet after I ordered them. I got a great deal on 'em, though! I believe the total amperage needed for each relay on this prototype is only about 36mA, or somewhere close within that range. Don't quote me on that, it's been a long day-so I could be off a bit. I'm sure it wasn't much over that figure for my intended usage...

I've got 19 T0-92 2N7000's on hand, like you had recommended, so I believe I'll use those. I didn't think I did at first, but I browsed through "My Documents" and found the datasheet there without even having to search datasheetarchives.com for it. I knew that meant that I either had them on-hand or had planned on ordering some at one time, so I checked one of my transistor storage boxes and found them neatly labeled in a little baggie under the "N-Channel FET" compartment...

BTW-the Texas Instruments datasheets I have for the ULN2004 and the ULN2803 don't list the thermal curves for either. I've been meaning to find another manufacturer's datasheet that lists them, but I haven't gotten around to it just yet. I've been back and forth between "The Art of Electronics" and "Programming PIC Microcontrollers with PICBasic" by Chuck Hellebuyck, and have had a rather long day today with my preparation for next semester's courses. I WILL find datasheets with the thermal curves for those Darlington arrays. Thanks again for the help and advice-I really appreciate it!

Sincerely,
-Adam Collins

P.S.-Just wait until I'm asking for help here on some of the problems I encounter with the four semesters worth of Calculus I'll be taking in the coming four years...:D

LOL-Just kidding about the Calc. questions-I'll figure it out when I get there... I've got a "refresher" course coming up this month to better prepare me. In a little over four years from now, I should be "qualified" to actually assist others! A scary thought, huh? ;)

mackrackit
- 4th November 2008, 06:42
P.S.-Just wait until I'm asking for help here on some of the problems I encounter with the four semesters worth of Calculus I'll be taking in the coming four years...:D

LOL-Just kidding about the Calc. questions-I'll figure it out when I get there... I've got a "refresher" course coming up this month to better prepare me. In a little over four years from now, I should be "qualified" to actually assist others! A scary thought, huh? ;)
Calculus???
Whats that? :D

RussMartin
- 5th November 2008, 09:23
BTW-the Texas Instruments datasheets I have for the ULN2004 and the ULN2803 don't list the thermal curves for either. I've been meaning to find another manufacturer's datasheet that lists them, but I haven't gotten around to it just yet.


You might start with Figures 14 and 15 on page 10 of this:

http://focus.ti.com/lit/ds/symlink/uln2003a.pdf

And Figures 11 and 12 on page 5 of this:

http://www.st.com/stonline/products/literature/ds/1536.pdf

RussMartin
- 5th November 2008, 20:05
. . . Just wait until I'm asking for help here on some of the problems I encounter with the four semesters worth of Calculus I'll be taking in the coming four years...:D
LOL-Just kidding about the Calc. questions-I'll figure it out when I get there... I've got a "refresher" course coming up this month to better prepare me. In a little over four years from now, I should be "qualified" to actually assist others! A scary thought, huh? ;)

Hints for succeeding with your calculus course(s):

1) Memorize as many of the common integrals as possible ASAP.

2) Do as many of the exercises as possible, even ones the instructor doesn't assign.

3) Decide your objective: Do you want to master calculus or (recommended) pass the course(s)? (Bear in mind that many of us who took required calculus haven't used it since school.)

rxforspeed
- 6th November 2008, 05:10
Hints for succeeding with your calculus course(s):

1) Memorize as many of the common integrals as possible ASAP.

2) Do as many of the exercises as possible, even ones the instructor doesn't assign.

3) Decide your objective: Do you want to master calculus or (recommended) pass the course(s)? (Bear in mind that many of us who took required calculus haven't used it since school.)

That's a huge relief to hear-but at least I'll be able to understand more of "The Art of Electronics" once I get familiar with Calculus and Trig. Even the first chapter's lost me with some of the exercises, probably mostly because I just slid through Algebra 2 my senior year in high school. I had enough math credits to graduate, and I stayed busy hanging out with the wrong crowd back in those days; partying and racking up scores like Wilt Chamberlain...

But alas, those glory days are over now; my main focus today is my eight-year-old son, my education, and finding a job to work around my schedule. It feels kind of degrading to search for jobs at gas stations and near minimum wage establishments compared to the jobs I've had in the past ten years, BUT-that's a sacrifice I'm willing to live with to earn my degree. Besides, I've spent a huge chunk of my savings on a hardware, software, and a massive component collection that would make a few smaller distributors jealous. I should be prepared for almost any project I tackle in the next few months or so...

Here I go with another "long-winded" ramble...;) I'll get to the point:

For some reason, I couldn't get that second link from your other post to open, Mr. Martin. It's probably my computer-I've got so much RAM occupied with all the windows, browsers, PDF datasheets, MCS, etc. open and minimized for quick reference that it really slows down this notebook. I've got a collection of parts to build a nice desktop, but that hasn't really been a priority as of yet...

I did save the first link to the ULN200X-ULQ200x datasheet and I see exactly what you mean about the "thermal curves". I don't believe I'll have an issue with the Darlington arrays on the main prototype I'm building. Please correct me if I'm wrong, but I believe I remember that P=VI, with P being power (in watts), V being voltage (in volts), and I being current (in amps). I know from Omron's G5LA datasheet that the coil power consumption for both the 5V and the 12V relays is 360mW, so to find the total amperage I'd rearrange the equation to: I=P/V (I=0.36W/12V=0.03A). Sound right, 30mA? That's one relay; I'm using four on this prototype, so 4*30mA=120mA through the array.

I may be wrong in my assumptions about the duty cycles for these components, but my experience with duty cycles comes from my use of ARC and MIG welding machines where the duty cycle is measured in half-hour increments. I.E., 20% duty cycle on a 90A MIG setting means that the machine can be run for only six minutes at a time (30min*0.2=6) and then must rest without use for the remainder of the half-hour, or 24 minutes...

This datasheet for these components isn't identical to the arrays I'm using, but I'll even assume the thermal characteristics are worse for the ULN2004AIN's I have. The charts show between an 80-100% duty cycle for all four relays operating at 30mA each (120mA total), but the program I've written only samples one corner at a time, opening the "fill" valve for 100msec (plus the time it takes to execute the instructions minus the 10msec "operation time" then plus the 5msec "release time" for the relay's electromagnetic coil-so I'd still say roughly 1/10th of a second at a time per corner). Just to be safe, however, I have added an additional "PAUSE 50" statement after each sample (that's about 40msec more than I need for the A/D conversion with the ADC_CLOCK defined at "3", or internal RC oscillator, right?)...

The program loops via a variable "ANINRTNE" (abbrieviated "ANalog IN RouTiNE") to decide which corner to check next and is regulated by the pressure reading from the tank's psi sensor (if the tank pressure is below 90 psi, or "207" from my calculations with an 8-bit resolution and the Vref established at 1.525VDC, then the program waits an additional second before checking the tank psi level again and continues this routine until there is 90 psi or more in the tank)...

In order to reach 50 psi and 40 psi in both the front and rear corners, respectively, I know this won't be the quickest route for the program but the owner of the "Phantom" will not be in a rush to get anywhere with it; it's his show car. I'll concentrate on speeding it up when I get more acquainted with PBP and interrupts, but I believe this should be adequate for the time being. I really just need to get a prototype in the car so the owner can flip the switch to power it up, get up to "ride height" in about a minute or so (less time than the poorly engineered GM TPI V-8 takes to properly warm-up), then be ready to go. I'll practically have all winter (minus class and study time) to work on learning interrupts and exactly what I need to add to (or change/delete from) the program to make it a bit more efficient.

I hope the calculations and assumptions I've made for the project are at least "in the ballpark", and I'm sure there are quite a few variables I'm overlooking, but I think I've pretty much gotten this down (or at least I'm VERY close to it). One more quick read through the PBP manual and the '690 datasheet and I should have it in order. If I have problems with the code, I'll try to search the forum and all the other references I have handy to resolve the problem before posting a cry for help on here...

Sorry for the "long-winded" post-I just wanted to *attempt* to clear things up, although I may have done the complete opposite and just totally confused some of you, but I really doubt it. Most (if not all) of the members here that have helped me out have proved in some way or another that they really "know their stuff", so even if I haven't confused you then I'm sorry to make you read this short novel. I sincerely appreciate all the time, effort, knowledge, and help you guys have provided and shared here-it really means a lot to me!

Thanks!

RussMartin
- 6th November 2008, 08:33
For some reason, I couldn't get that second link from your other post to open . . .

Try http://www.st.com/stonline/products/ and then use the second box to do a part number search for ULN2803 or ULN2803A.

rxforspeed
- 7th November 2008, 05:41
Try http://www.st.com/stonline/products/ and then use the second box to do a part number search for ULN2803 or ULN2803A.

That worked, thanks again sir! I see exactly what you mean, too-the more ouputs you're using and/or the higher the current draw through the array equals less overall time the array IC can be used. I don't believe that my program and the current needs of the relays I'm using will be too much for these.

I will, however, have a back-up-just in case, with the 5V relays (power supply isolated from PIC's) and the 2N7000's. Thanks again for all the help!

Sincerely,