A simple relay doubt - Page 1
Forum section: electronics / beginners

author: alecto
author_rank: Contributor
timestamp: September 06, 2017, 02:37:23 pm
content: Hello,I attached(I hope) a shema of a little circuit I breadboarded...it works fine...well it seems to anyway...would you advice such kind of stuff?PS : Please excuse the crudity of this model. I didn't had time to build it to scale or paint it.thanks in advance for your time...

author: Brumby
author_rank: Unknown
timestamp: September 06, 2017, 02:43:34 pm
content: Not bad - but the first thing I would suggest is a back emf protection diode.Just something like a 1N4007 connected between coil + and coil - with the arrow pointing up.Reason: When you energise a coil, the magnetic field builds up according to the ability of the power supply and the circuit energising it. However, when you disconnect the power, there is no current to maintain the magnetic field, so it collapses.... very quickly. It is this speed of collapse that can generate hundreds or even thousands of volts which could kill any susceptible components, such as your transistor.The mechanism is identical in the coil in a car ignition system. That's how they get 12V to generate the voltages required for spark plugs.

author: Connoiseur
author_rank: Regular Contributor
timestamp: September 06, 2017, 02:47:49 pm
content: What's exactly you want to accomplish? I'm guessing this is some sort of an emergency lightThe circuit will illuminate an area, depending of the wattage of LED. You can improve efficiency by eliminating the relay and using either a PMOS in its exact place or NMOS on the common ground side of LED's.

author: Ian.M
author_rank: Super Contributor
timestamp: September 06, 2017, 03:07:43 pm
content: Also the 2N3904 has a minimum HFEof 100 @Ic=10mA dropping to 60@Ic=50mA. With a 10K base resistor, it only has about 0.43mA base drive, its only good for a bit over 30mA, before in the worst case scenario, it could drop out of saturation and the relay may fail to pull in reliably. Although you'll get away with it if the relay draws less than 30mA coil current, its good design practice for a saturated switch to provide excess base current, so Ib=Ic/10, and it should *NEVER* have less base current thanIc/(2*HFE)2*Ic/*HFE, so replacing the 10K resistor with a 1K one would be advisable.P.S. We *much* prefer a clear hand-drawn schematic, in black ink on an even white background, to blurry photos of a breadboard or a schematic sketched in faint pencil on what looks like a used paper wrapper from a takeaway kebab, taken on a crappy low-res phone camera by someone with an essential tremor. Overall I think I'd award you 7/10 for that schematic - its clear enough and had readable part numbers and component values.Edit: corrected formula above. Sorry - brain fart!

author: alecto
author_rank: Contributor
timestamp: September 06, 2017, 03:18:59 pm
content: Quote from: Brumby on September 06, 2017, 02:43:34 pmoops sorry there is one...I just forgot to put it on the shema...Quote from: Connoiseur on September 06, 2017, 02:47:49 pmjust some lightings for my 3D printer...I had a relay...some leds...and a cheap nano clone....this was just a test...I was just wondering if I could tie the com to the coil...but I heard your remark about PMOS or NMOS...and for the efficiency...if I understand correctly...the speed is not really that important to me in this case...and the 50mA current for the coil is not too much...the circuit as it is is around 123mA wich is ok for my purpose

author: alecto
author_rank: Contributor
timestamp: September 06, 2017, 03:25:35 pm
content: Quote from: Ian.M on September 06, 2017, 03:07:43 pmthank you...there you see I am a complete noob...so much to learn....I will change the resistor....and try to understand this...till now I only used transistors as switch without reflexion...it is time to evolve

author: madires
author_rank: Super Contributor
timestamp: September 06, 2017, 03:36:26 pm
content: I second the idea to replace the NPN with a logic level n-ch MOSFET switching the LEDs directly (low side switch). That would also allow you to PWM the LEDs by the Arduino.

author: Ian.M
author_rank: Super Contributor
timestamp: September 06, 2017, 03:47:42 pm
content: Arrgh. Formula error!Use: Ib>2*Ic/HFE_min, as the minimum safe base current for saturation should be double what would be needed for the desired Ic with a minimum HFEtransistor in its linear region. Be aware that Vce_sat voltage drops in the datasheet are likely to be quoted for a 1:10 Ib:Ic ratio, and will be higher at the lower base current, which may result in excessive dissipation. However I think that wont be a problem unless you try to drive a low coil resistance heavy duty relay.

author: alecto
author_rank: Contributor
timestamp: September 06, 2017, 04:14:01 pm
content: Quote from: madires on September 06, 2017, 03:36:26 pmI am not sure I have one of those...probably a few p-channel...but I'll admit I never tried mosfets...yes I feel the shame...but to my defence I don't have too much free time to exercise my passions...the work...the wife...the kids...(and yes my wife and kids are also a passion...she can read you know)anyway with such nice replies I feel the need to do some homework...first trying to understand what Ian.M wrote...it won't be easy...like a child trying to speak to an engineerand next checking if I can't find a n-ch mosfet somewhere...i have a lot of recup stuff...and then read a lot I guess + some experimentationscould you write me a note for my wife

author: Ian.M
author_rank: Super Contributor
timestamp: September 06, 2017, 05:35:42 pm
content: To help understand my comments above, take a look at page 6 of theOnSemi 2N3904 datasheetFigure 15.Normalised DC Current Gain shows how the large signal current gain varies with collector current. Normalised means its plotted as a fraction of the peak HFE(DC current gain), so if you want to put some actual numbers on it, the 25 deg C curve reaches '1.0' on the vertical axis at about 8mA Ic, which is near enough the 10mA Ic quoted in the ON CHARACTERISTICS section on page 2, so the minimum peak HFE(worst transistor) will be 100 and the maximum (best transistor) will be 300. It also shows you how the DC gain falls off at high or low currents or at low temperatures, which is typical for most BJTs (bipolar junction transistors) . A graph like this is found in most datasheets.The next graph - Figure 16. Collector Saturation Region is not a common one, but its very useful if they provide it. It shows you the voltage drop for various fixed IC as you vary Ib. As I previously pointed out if you don't have enough base current, the voltage drop rises rapidly as the transistor starts to come out of saturation*.The final graph of interest is Figure 17. “ON” Voltages. This is plotted for a 1:10 Ib:Ic ratio and lets you predict the base voltage, and thus the drop across the base resistor, giving you the avaible base drive current, and the Vce drop to expect at the corrisponding 10x higher collector current.You may also findSparkfun's Transistor Tutorialhelpful as it goes into BJT usage in some detail but still manages to avoid the heavy maths.Quote from: alecto on September 06, 2017, 04:14:01 pmJust copy this out in your own handwriting and sign it:Quote* Saturation is when the transistor is turned on hard enough for tVce to be less than Vbe, and is desirable for a low loss power switching application, but should generally be avoided if you need very fast switching.

author: Brumby
author_rank: Unknown
timestamp: September 08, 2017, 04:25:10 am
content: Quote from: Ian.M on September 06, 2017, 05:35:42 pmThat would take a brave man.....

author: alecto
author_rank: Contributor
timestamp: September 08, 2017, 11:01:08 am
content: Quote from: Brumby on September 08, 2017, 04:25:10 amin my own handwriting...no too risky...I won't be able to deny...and to quote somebody else..."she who must be obeyed" must be obeyed...anyway thank youIan.Mfor the explanation....this WE I have a bit of time ahead of me....so a lot of lecture...a bit(or a lot) of bjt testing...probably a few stupid questions.....and then I'll have to replace the relay with a N-Mosfet...because after all I have some of those...(and actually no P-Mosfets...)IRF540 / IRF510 / IRF634 / AP20T03 / 2N7000 / P55NF06 / VN10KN3 / BS170 ...a bunch of datasheets to read...err decypher I mean...to find a suitable onefinally quite a bit of work...and since my wife 's not at home...a little bit of thisand a little bit of thatand surely a lot of

author: madires
author_rank: Super Contributor
timestamp: September 08, 2017, 11:38:46 am
content: If you want to use a MOSFET with a V_GS roughly around 10V you're going to need a driver. Or use a logic level MOSFET which can be driven directly by a 5V MCU.

author: alecto
author_rank: Contributor
timestamp: September 09, 2017, 04:32:00 pm
content: ok it is time for some stupid questions...first a few assertions1° 2N3904 has a HFE between 100~300 if Ic =10mA2° 2N3904 has a HFE of 60 if Ic =50mA3° Ic = HFE * Ib4° the coil of my relay needs about 40mA to pull in at 12vthen my deduction (probably wrong)...Let's say that with a current of 50mA I am sure that the coil will pull in....Ib@60HFE =0,05A/60 =0,00083A or 830µAso the base resistor could beR =V/I = (5v-0,7v)/830 µA = 4,3/0,00083 =5180=> about 5KAm I completely wrong here?is there something else I should take account of?PS sorry Ian.M...I tried to understand your explanations and if sometimes I kind of get it....most of the time I'm just...to be honest figure 16 is a complete mystery to mePPS if you think I am too much of a beginner...don't hesitate and tell me...I just feel I need some human help here...reading is not enough...I need a eureka moment with transistors

author: Ian.M
author_rank: Super Contributor
timestamp: September 09, 2017, 08:55:41 pm
content: "2° 2N3904 has aminimumHFEof 60 if Ic =50mA"You must remember that those figures are limits, beyond which the transistor doesn't meet spec. as a 2N3904 and shouldn't have made it out of the factory marked as one. However unless you want to be *REALLY* *STUPID* and f**k about with 'select on test' till it works*, you do have to design to the worst case specs, for each limit determining whether the worst case is the minimum or maximum value. Sometimes we extrapolate from the specs for a prototype or small scale production with reasonable confidence that failure to meet our extrapolated spec will be caught by testing, but if you are doing anything high reliability or for volume production, that can bite you in the ass.So @Ic=50mA it *probably* has more gain, maybe up around 120, or even as high as 180 as the 3:1 ratio at 10mA indicates the gain isn't tightly controlled.Your base resistor calculation is OK if you have actually measured the gain and don't care about saturation. However that's 'select on test' territory, and as you are already here asking for help understanding BJTs, I *KNOW* you aren't that stupid. As NOT STUPID, you will of course round down to 4K7 not up to 5K6. It will probably have enough excess base current, and an outlying HFE180 (estimated) device would have well over 3x excess base current so would be well into saturation.However the low gain outlier of a HFE60 (spec) transistor wont have enough margin, and here's why:Lets look at fig. 16 and consider 10mA IC load current for a bit (as we don't have a curve on fig 16 for 50mA, and have limiting values for the HFE@10mA), you will see its left saturation if the base current is below 0.085mA and the knee of the curve is at about 0.095mA. Unfortunately we aren't given a number for the typical HFEthe curve was plotted for but as all the other HFEvalues we were given were aat Vce=1V and the fig 16 graph goes up that high we can take Ib @ Vce=1V from the graph and calculate it: 10/0.08 gives typ. HFEof 125 @Ic=10mA. That's quite a surprise how heavily biassed it is towards the low end of the permitted HFErange.Looking at the 30mA curve, the knee is at about 0.45ma and at 1V its about 0.36ma, so the excess required to get below the knee is 25%, and similarly for the 100mA curve 4.3mA and 3.0mA shows it needs 43% excess base current. Its fairly obvious that providing 2x the base current will always get you below the knee and properly into saturationat 25 deg Chence the formula I gave earlier Ib>2*Ic/HFE_minIdeally we'd design to a forced beta of 10 (Beta is the *old* name for HFEand a forced beta is the ratio of Ic to Ib you decide to provide to ensure its saturated), as that will guarantee saturation over the full temperature range with any 2N3904, but assuming you are short of MCU output current, the highest forced beta we could tolerate would be HFE_min/2.Re-running the calc for a forced beta of 10:Ic=50mA, Vbe=0.85V (from fig.17), and Voh=4.55V (extrapolated from ATmega328P datasheet, assuming Vcc is 5% low)Ib=Ic/forced_beta=50mA/10=5mAVrb=Voh-Vbe=4.55V-0.85V=3.7VRb=Vrb/Ib=3.7V/5mA=740 OhmsNext lowest E12 preferred value is 680 OhmsRerunning it for a forced beta of 30 (HFE_min/2 @50mA Ic):Ic=50mA, Vbe=0.8V ('guesstimated' from fig.17), and Voh=4.7V (assuming Vcc is 5% low)Ib=Ic/forced_beta=50mA/30=1.67mAVrb=Voh-Vbe=4.7V-0.8V=3.9VRb=Vrb/Ib=3.9V/1.67mA=2340 OhmsNext lowest preferred value is 2.2KMy original suggestion of 1K is between these two values and biased towards the lower one.Going back to your understanding of fig.16:Take a PSU with an accurate current limit (or rig a current limiter or current source of some sort that can cover the range 1mA to 100mA).Keep the max voltage available from the current source down to a few volts as we are only interested in the region below 1.0V.Take a box of 2N3904 transistors and a transistor tester, set its test Ic to 10mA and select one with HFEof 125 - a truly average device.Hook it up on a breadboard with the emitter grounded and the current source feeding the collector. Set up to provide an adjustable base current in the range 10uA to 10mA - a variable voltage supply and a series resistor going up in decade steps would be the easiest option.Take 3 multimeters - one for base current, one for collector voltage, and the last for collector current (so you can be certain your current source is delivering the correct current), and wire them into the circuit and you can start plotting each curve. If you've got anEEVblog uCurrent, the base circuit would be a good place to use it.First set Ib to the leftmost point on the curve, then increase the collector current supply till it reaches the current marked by the line you are plotting, and then readjust Ib. Read Vce and Ib, plot them then decrease Ib to the next division on the graph paper, check Ic hasn't changed and repeat till Vce reaches 1.0V. That's one curve done. Reset Ic to the next curve and repeat till you've got them all. For the 100mA curve you should switch off and let the transistor cool in between readings. That's your whole afternoon gone reproducing one figure in the datasheet.A similar rig can be used for the 25 deg C line of fig.15 and for fig.17 though fig.17 needs an extra High impedance voltmeter to monitor Vbe.More practically you can get these sorts of plots from acurve tracer. Analog curve tracers consist of a ramp generator that controls a voltage or current source (selectable) over a preset range, + a circuit to measure the resulting current or voltage (again selectable) at the same or another terminal of the device. Additional fixed voltage or current sources are typically required to bias the device (e.g. at fixed Vce or fixed Ic or fixed Ib etc.) for the desired curve. The ramp generator and the measured result converted to a voltage are applied to a CRO in X-Y mode to plot the result. If the ramp is slow enough its also possible to plot it on a chart recorder, but then one assumes the ramp is linear with respect to time. Another 'cheat' is if your CRO has a timebase (X axis) ramp output on the back panel - then you can skip the ramp generator, let the timebase free-run and just scale the output with an OPAMP to drive your D.U.T. Another refinement is to add a crude 3 bit DAC to sweep one of the 'fixed' sources. Increment the counter driving it after every ramp and you'll get eight curves on the screen as that source is stepped.Nowadays you are better off with a digital curve tracer. It has a job lot of DACs, ADCs and scaling circuits, and pulses the device on only long enough to take each measurement so it doesn't heat up and shift the results. Output gets logged to a file and can be plotted on your PC. Google:Arduino curve tracerfor some ideas on how you could build one.* Occasionally 'select on test' is NOT STUPID e.g. when it lets you get away without a *MUCH* more expensive part, and you are certain that voltage and temperature variations wont throw the carefully tweaked circuit out of operation, but you'd better figure in to the costings your cost per hour, so if you are only saving a few bucks you are back to stupidity.

author: alecto
author_rank: Contributor
timestamp: September 10, 2017, 08:57:36 am
content: first of all, I can't be thankfull enough for the time you spent to explain me this...unfortunatelly I have to stop now because the wife is about to come home....and I don'have to explain why I have to put her on my top priority list....first because I'm afraid...and more so because...well... she's my wife and I love her ( I repeat she can read)So even if I didn't had my eureka moment yet...reading you gave me some "aaaah" moments....I understand the 'select on test' limitations and the necessity to take in account the worst case specs...BTW I did round down to 4.7K...even though I understand now a 1k would have been better(your calculated demonstration was ideal to make me get it)...I hope you don't mind that I didn't use one right after you first told me to...I read a few articles and tried to get it my own way...wich wasn't the best way...I knowNow I look at fig. 16 and it is not as "hieroglyphic" as it was yesterday...another of the "aaah" moments...I don't have (yet) a proper PSU with an accurate current limit...but I have seen in the datasheet of the LM317(I think) circuits for simple current limiter...wich, I believe, in serie with my ampmeter could prove usefull for lack of anything better at the moment....I'll think seriously about purchasing an EEVblog uCurrent...I see the point...and a third multimeter...man it isn't the cheapest hobby...thank you also for the idea of the curve tracer...I did google "Arduino curve tracer" and I am more than motivated to build one(even improve one) and surely program it myself...because I like that...and also because I know I learn more by writing my own libraries than to just copy/paste existing ones....without forgeting the hobby part of it tooanyway my work is settled... (<==hope it's english) THANK YOU again...i feel I never been so close to finally understand, more in depth, the bjt...that strangely complicated little beastan MCU is so much easier to understand than those I think...maybe the 400+ pages of datasheet...who knowsHave I already thanked you?? well...thank you

author: Ian.M
author_rank: Super Contributor
timestamp: September 10, 2017, 11:31:46 am
content: A LM317 configured as a current source cant go below 5mA, its minimum load current and remain stable. However for 10mA up to its current limit it will work nicely.For lower currents you can use a JFET with a resistor between its gate and source. It can only deliver a maximum of its Idss, which is not well specified, so its 'select on test' territory (OK here as the alternative would be a $$$.$$ bench supply).e.g. a 2N3819 has its Idss specced as between 2.0V and 20V, and its pinch-off (or cutoff) voltage Vgs_off specced as max 8.0VYou can measure Idss and Vgs_off quite easily. Take the circuit below and replace R2 with a short. Ramp up the supply voltage till the current stops rising and then 50% more (or to whatever voltage was specced for Idss), and measure it. Vgs_off is also quite easy - replace R2 with your DMM on volts. It will read slightly under the true pinch-off voltage because a few hundred nanoamps will pass through your meter's 10Meg input impedance, but its near enough. Its difficult to calculate the current source current even with those parameters measured, but I will be more or less proportional to 1/R2, so put a pot in and twiddle it!The final easy option is a BJT and a single cell battery to bias the base. There is 1.5V - Vbe across R3 so its pretty easy to work out the expected current. It does have a few flaws - if you reduce the supply below about 1V the b-c junction becomes forward biassed and it starts passing reverse current. Also the battery then has to supply all the current through R3, so disconnect the battery before switching the main supply off. You can use just about any transistor including a spare 2N3904, and in normal operation the battery only sees the load current divided by HFEso an AA cell wont discharge significantly over the course of a bench session.A uCurrent reduces the burden voltage for low current measurements. Its by no means essential but it does make a lot of measurements easier and allows a cheap multimeter (or even a Harbour Freight 'free' seven function multimeter) to read current down to picoamps.I wouldn't trust a really cheap multimeter for a lot of things, but if all you are measuring is DC voltage under 50V on a breadboard, don't care if the input impedance may be less than the normal DMM 10 Meg, and you have a better quality multimeter to check it against, then just about any sh!tty DMM will do. It only needs to be stable, repeatable, and within the same small percentage of the good DMM when spot checked at the upper limit, middle and lower limit of the voltage range you are interested in.

author: madires
author_rank: Super Contributor
timestamp: September 10, 2017, 11:52:51 am
content: Quote from: Ian.M on September 10, 2017, 11:31:46 amThere are also CLD/CRDs, for example 1N5283 - 5314.