Notifications
Clear all

how to use a transistor with an arduino

65 Posts
7 Users
27 Reactions
3,175 Views
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7118
 

@pajhum42 Although new to transistors, I think the following is correct.

It depends on whether you want the transistor to operate as a switch or amplifier. In the case of a switch, you want the Ibe to be in the saturated zone so the switch is fully on, but if you want an amplifier, then either a fixed R or variable R that has a value that allows Ibe to be within the 'active' range. Since the 'active' region is a range, the potentiometer is your best bet unless you have a lab power supply with adjustable voltage and current then, an Rb in the middle of the cutoff and saturation points is the best choice. If you want to use a pot, make sure it is of the linear type instead of the log type.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
Inst-Tech reacted
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1723
 

Hi @pajhum42,

One think I'm still trying to understand is how to calculate the value of the base resistor. Your example used an 2.2K resistor. I looked up the datasheet for the TIP121 transistor and the max base current is 120mAdc. The Arduino is supplying 5volts so the resistor needs to be 5V/.120A = 42Ohms. Nowhere need the 2.2K you used? I must be missing something.

   Sorry, but you haven't grasped the 'general' principle that a transistor is an amplifying device. A 'small'  base-emitter current can control a 'larger' collector-emitter current.

---------

The data sheet will list MAXIMUM currents and voltages for the transistor's pins and junctions, but these are MAXIMUMs, implying that device failure  is the most probable outcome if one or more of these values is exceeded. They are NOT the values required to make it work in a useful circuit.

You haven't provided a reference to a particular circuit (which is always a great help), but from your description, I thank its this one, from https://dronebotworkshop.com/transistors-mosfets/

junk

The same article also lists some of the main characteristics of the TIP120

Here are the main specifications of the TIP120:

  • NPN Medium-power Darlington Transistor
  • High DC Current Gain (hFE), typically 1000
  • Continuous Collector current (IC) is 5A
  • Collector-Emitter voltage (VCE) is 60V
  • Collector-Base voltage (VCB) is 60V
  • Emitter Base Voltage (VBE) is 5V
  • Base Current(IB) is 120mA
  • Peak load current is 8A
  • Available in To-220 Package

 Note it says it has a high current gain (around 1000) and that it is a Darlington (pair) transistor.

--------------

I am not sure if you mentioned how much current you are controlling (i.e. in Bill's circuit, how much current the lamp would need), so let's assume it is a maximum of 1 Amp.

Now, roughly speaking, the current gain of 1000, implies that to pass 1 Amp through the collector-emitter path, you will need

( 1[A] / 1000 [current gain] ) base-emitter path current. i.e. 1/ 1000 th of an Amp, 1 milliAmp.

There are many descriptions of Darlington pair on the web, which expands on this  ... 1st one I found on Google was https://kitronik.co.uk/blogs/resources/how-a-darlington-pair-transistor-works

------

The other consequence of a Darlington pair, is the base-emitter voltage drop is twice that of a single transistor, so that whan switched on, the base-emitter voltage drop will be around 2 X 0.6 = 1.2V

So that, with a 5V Arduino, when the output from the Arduino is 'high', it will be nearly 5V.

And using the above circuit, the voltage at the transistor end of the base resistor will be about 1.2V

This means the volatge across the resistor will be about (5V - 1.2) V = 3.8V.

So to get the base current of 1 milliAmp, as previously estimated, use Ohm's Law R = V/I

R = 3.8 [V] / (1/1000) [A]  = 3.8 * 1000 Ohm = 3.8 kOhm

----

Now remember there are a lot of approximations in the above, including the current gain specification, so we would aim for 'a bit larger than necessary' base-emitter current, say roughly twice, which will be 2 milliAmps, to allow for the implicit 'margin of error'.

This would be achieved by halving the base resistor value

R = 3.8 [V] / (2/1000) [A]  = 1.9 * 1000 Ohm = 1.9 kOhm

So allowing for resistors coming in preferred values, the nearest preferred value of 2.2 kOhms

will give a base current of about 3.8[V] / 2.2 [kOhms] = 1.7 milliAmps

Which is comfortably more than the 1 milliAmp minimum requirement, without needlessly passing an excessive current.

---------------------------------------

I hope that helps you to understand how Bill might have chosen 2.2 kOhm, and also shows the path to calculate your own case. Please take the trouble to try to follow the simple maths, etc. involved.

There are a several assumptions and choices that might be different in your case, and hence need a different value of resistor. My description is of the general steps to take to estimate the value needed for the base resistor  ... 2.2 kOhms is not a universal value for all possible circuits!!

Best wishes, Dave


   
Inst-Tech and Ron reacted
ReplyQuote
Inst-Tech
(@inst-tech)
Member
Joined: 2 years ago
Posts: 554
 

Posted by: @pajhum42

@dronebot-workshop Bill,  Thank you, that video was very helpful.  I have a prototype working as expected now.  One think I'm still trying to understand is how to calculate the value of the base resistor.  Your example used an 2.2K resistor.  I looked up the datasheet for the TIP121 transistor and the max base current is 120mAdc.  The Arduino is supplying 5volts so the resistor needs to be 5V/.120A = 42Ohms.  Nowhere need the 2.2K you used?  I must be missing something.

@pajhum42, I've been following your post and see where you would be somewhat confused..The maximum base current is is the parameter that you should not exceed, not what you calculate for the base current.A simple solution is to look at this example: in the data sheet for the TIP120,

image

 you will see that the DC current gain (Ic=0.5A , Vce=3.0 vdc)  and hfe=1000, this is a power transistor, NPN type with a  max current of 5 Amps, and a peak of 8 Amps..

Lets say you have a device that draws 1 amp and is in the collector circuit. you know that the hfe =1000, and the collector current will be 1 Amp.. therefore, the base current required will be Ib=Ic/hfe, (base current = 1 Amp/1000) =1 mA.

If you are powering your circuit with 5 Vdc, the Rb, (base resistor) = Vcc - Vbe(voltage source , minus the base to emitter voltage of ~0.7V) / Ib ( divided by the base current required)=4300 ohms, or 4.3K ohms, since resistors come in standard sizes, a 4.3K @5% tolerance would be selected to give you the ~1 Amp collector current you desire. Of course, since the resistor is +/- 5% tolerance, the actual base current can be between 1.05mA to 0.952mA ( or 952uA), giving you a collector current of 0.982 Amps ( or 982.84 mA).

this simulation I have drawn will demonstrate what I've been trying to say..

image

 Now you can see the the collector current is pretty close to what we have calculated, and the the precision of the resistors, voltage and other components contribute to the the differences we may experience in our practical circuit. I Hope this will help you in your understanding of how to calculate the base current of this simple circuit.

Regards,

LouisR

 

 

LouisR


   
ReplyQuote
(@pajhum42)
Member
Joined: 6 months ago
Posts: 14
Topic starter  

@davee Thank you,  things are starting to make sense.  I'll have to take some time to work through your explanation to be sure I understand it.

The circuit diagram you posted is the one I'm using.  I'm only powering a few LEDs so about 40mA.  I'm using a transistor instead of a relay or directly from the Arduino because  1. I want to learn how transistors work, 2. I don't like the noise the relays make and 3. I prefer to slowly brighten the LEDs instead of the abrupt on/off the relays produce.

My final project will use more LEDs than the I think the Arduino can power at one time.  That is why I think I need either a relay or transistor. 


   
ReplyQuote
(@pajhum42)
Member
Joined: 6 months ago
Posts: 14
Topic starter  

@inst-tech Thank You, that explanation helps.  The same circuit works if I replace the TIP120 with a BC548 which I have more of.  I'm planning on running about 8 pairs of LEDs turning them on and off at different times/rates.

I'll go through the explanations you and @davee provided again but I think I'm starting to understand.  


   
Inst-Tech reacted
ReplyQuote
Inst-Tech
(@inst-tech)
Member
Joined: 2 years ago
Posts: 554
 

Posted by: @pajhum42

@inst-tech Thank You, that explanation helps.  The same circuit works if I replace the TIP120 with a BC548 which I have more of.  I'm planning on running about 8 pairs of LEDs turning them on and off at different times/rates.

I'll go through the explanations you and @davee provided again but I think I'm starting to understand.  

@pajhum42, Very Good!.. Now your on the right track.

The reason why the TIP120 probably didn't work for you is it's typically used as a high power ( voltage and current) transistor. Note the specification in the data sheet, and you will note that the  max voltage and current ratings are much higher than a BC548, along with the hfe (transistor's gain) https://www.circuitdatasheet.com/bc548-transistor-specifications-features-alternatives-uses-datasheet/

Compare the spec sheets. This is a vital part of electronics to learn how to read and interpret specification and data sheets. Nothing in electronics is easy, but it is all doable with hard work and studying. Remember, math skills are your friend, and after the initial theories and concepts break thru, you'll be in makers heaven building all sorts of circuits. 🙂 

regards,

LouisR

 

LouisR


   
robotBuilder, Ron and DaveE reacted
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1723
 

Hi @pajhum42,

   Clearly your LEDs and choice of transistor change the circumstances quite a bit, but hopefully the explanations from @inst-tech and myself will be a starting point for your own calculations. Points of difference to note, include:

  • BC548 is a
    • single transistor, not a Darlington pair, so base-emitter voltage will be about 0.6 V, not 1.2 V
    •  
    • a lower current and power transistor .. good for 40 mA current you mention, but max of 0.1 A rather than 5A. Also, much easier to overheat. If you are switching between full on and full off, this is unlikely to be a problem, but not when operating in the 'linear mode'. A full explanation is another sermon or two, and would need more details of your circuit intentions, but to start with, keep a finger near the device to check it is not getting too hot.
    •  
    • being a single transistor means the current gain will be lower than the Darlington pair. A quick look at a data sheet suggested DC current gain is typically in the range 90-300. Take the lowest value, probably 90, for your calculation, unless you can be sure it is a higher gain device. (Check the letter after 548)
    •  
    • In general, a bit higher base-emitter current (say an extra 1mA) is not a problem, assuming it is still well below the maximum value in data sheet, which it normally is.  Too low may mean the transistor is only partly conducting, and may get hot, as well as failing to fully power the load, the LEDs in your case.
    • (I couldn't see a maximum base-emitter current for the BC548 in the data sheet .. I would guess values up to 10mA would be fine, whilst I would expect the highest value you would need to be around 2mA.  Of course, these are only guesses .. the design responsibility is 100% yours.)
    •  
  • You mention 40 mA LED current .. I am not clear how you arrive at that figure. If you have any doubts, you might like to post a sketch of your intended circuit, and invite comments. I am not suggesting your estimate is incorrect, just that I simply don't know, and sometimes it pays to check first.

Best wishes and good luck, Dave


   
robotBuilder and Ron reacted
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7118
 

@davee @pajhum42 @inst-tech I would like to add one other point to the excellent points raised by Louis and Dave. If you are having difficulty reading datasheets, you are not alone. It would be much easier if they were all written the same, but they are not. Why? One possible reason is they know that another part may be 'better' (that will always be true), so it is to their advantage to obscure the facts without leaving something out or making false claims. All the information is there; it may be hard to find.

Sorry for the long-winded critique; I just want you to know it will be difficult at times to figure out what part is 'better' but just keep trying; smoking a transistor or two is not expensive.

 

 

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
robotBuilder reacted
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1723
 

Hi Ron @zander et al,

   Of course, you are right to say that datasheets do come in a wide variety of styles, and usually contain a lot of information that it is not needed for a particular application, making them several pages longer than the reader might be wishing for, when trying to find a device to meet their needs. Even more annoyingly, it is not uncommon to find that the particular parameter you had in mind, doesn't get a mention in 16 or more pages of otherwise largely uninteresting stuff.

Whilst such situations are ideal for conspiracy theories, I suspect most of the reasons are a lot more mundane.

In particular, the manufacturer may simply not know the details of the characteristic of the device they manufactured, and has finally ended up in your spares box or potential shopping list.

If a manufacturer states a particular value, or range of values, for something that can be measured, then this is potentially a part of a contract. How legally watertight that contract is, I'll leave for the lawyers, but at the very least, delivering devices which fail to achieve the data sheet values, possibly with catastrophic consequences, is a great way of trashing the company's reputation. So manufacturers are going to be careful not to claim values they do not carefully measure and monitor, not just for the first test batch of that design, but continually throughout the production lifecycle.

In principle, testing devices is straightforward, but it is VERY, VERY expensive. Remember, if we can buy production devices for few US cents each, in small quantities of say 10 off, then the manufacturing cost per device has probably got to be less than 1 cent each. If the entire factory price is less than 1 cent, you can't spend much on testing a product that has already required millions of dollars of equipment to make it, as well as some of the purest chemicals, etc.

---------------

The testing might be part of characterisation of the first batches of that design. This is likely to cover a wide range of tests, including frequency response, thermal heat flow, and so on. It will probably involve a relatively small number of samples, but lots of specialist manual technical expertise and expensive equipment that can measure performance over wide frequency ranges, etc. And before converting the results of such tests into data sheet values, they must be assessed for the likelihood of those values being maintained for countless subsequent batches, without needing the tests to be repeated.

--------

Other tests might simply be a pass/fail test for each device to reject the ones that have suffered some kind of problem .. a spec of dust, a thermal fracture, etc.  Furthermore, they are likely to need to be performed more than once, say initially when the devices are still in the wafer form, and then again as the packaged device.

----------------------------------------

Consequently, a data sheet is likely to concentrate on the values that the manufacturer thinks the major customers will be most interested in. A transistor that is used in low power applications, typically dissipating less than 1 milliWatt, is unlikely to be worried about thermal resistance, so a simple 'generic' value, or not even specifying a value is unlikely to lose many sales. But a power transistor, is obviously likely to need more care in this parameter. And clearly, this principle will apply to many other data sheet parameters.

------------------------------------------

So what should you do when faced with a datasheet?

Like, most things in life, experience helps a lot, but as next best substitute, try to list what matters most in this application? Typical considerations might be:

  • Purpose description ... many devices are described by their likely usage in a phrase or two a the start of the data sheet.
  • Voltage and current ... including allowance for transients, etc. Be careful to think on 'pin by pin' basis
  • Frequency range ... for many 'GPIO' driven applications, this might be quite low, but PWM, memory access, etc. can require the pin to handle sub-microsecond and even  sub-nanosecond transients
  • heat dissipation
  • packaging ... will I need PCB with Pick and place, or can I use a 0.1" matrix board
  • gain requirement

Of course, not all projects will require all of the above to be considered .... they are just suggestions.

When you have a 'minimal' set of requirements, then start to hunt through the data sheet for possible matches.

Be careful to check what each value means. e.g. MOSFET gate threshold voltage usually refers to the voltage the device will be 'turned off' .. the value it needs to be properly 'turned on' is quite different.

------------------

So this is a long list of 'waffle', but hopefully gives a little insight into matters that you may become aware of from experience, but rarely see in the text books.

Good luck with your projects and best wishes, Dave

 


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7118
 

@davee Don't be so quick to rule out 'conspiracies'. I can legally tell you I once had a job that allowed me to look at the data of numerous corporations, I am not legally allowed to go further. I can tell you with 100% certainty that conspiracies exist. Even a person who isn't really looking for them can't tell me with a straight face they have not heard how the oil companies knew as far back as the 50's that they knew about the effect of fossil fuels on the environment, also that the cigarette companies knew that cigarettes caused cancer despite their many statements to the contrary. Then there is the whole nitrates fiasco, that is the most interesting. However the one I mentioned in relation to datasheets is roughly on a par with 'puffery'. What is puffery? It is legally allowed 'fibbing'. It takes many forms, but shows you the power of the lobby groups.

Since there are no laws, industry standards or any kind of enforcement of what goes on a datasheet, I can only assume that if something is missing it is because it does not reflect well on the manufacturer. TBH, I doubt much of that exists except for the smaller manufacturers so when I look for a part, I try to find it from a well established company.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1723
 

Hi Ron @zander,

  I never ignore the possibility that individuals and organisations can and will, lie, commit fraud, conspire with competitors, and so on. I can't look at a news summary, without being reminded. And I take it as a given, that something like a datasheet might omit to state a value, if the author thinks it will disadvantage the described product.

However, with something like a transistor, it may pay the supplier to be upfront with the limits of a device, as the same supplier may have a 'better' device that they can also sell, at a premium. And trying to sell a product like a transistor, that is usually bought in large quantities for production, may soon turn a supplier into a pariah within the industry, if it pushes its luck too far.

Furthermore, I also know that 'simple' devices, like a single transistor, are far from simple to accurately model over all possible conditions, and when all the changes in characteristics that can occur due to small random process variations, etc. over an extended production period, then it is impracticable to monitor everything that leaves the factory with anything more than minimal a simple broken/not broken checking, when the devices are only returning a cent or two each in income.

Enlarging the picture to include integrated circuits, means a single package may have from (say) 10 to more than 1,000,000,000,000 transistors, yet each complete device must be tested in seconds, for most mass production requirements.

----------

So, various 'obviously criminal' activities can, and in some cases, will contribute to the level of confusion.

But statistics and reasonably legal business requirements, including cost, also limit the amount of information that even the most 'moral' suppliers can supply.

------------

However, the main object of my sermon of waffle, was to try to point to how someone can approach getting the best out of a data sheet. It is unrealistic to expect every sheet to answer every question, but they usually give you a fair idea, at least to beyond the point, that almost every prototype just smokes due to something that wasn't mentioned, but could reasonably have been included.

That is not to say, comprehensive testing and analysis of prototypes, prior to production, is unnecessary, but in most cases, the problems that are discovered should mainly be from more obscure and difficult to predict causes. For most of us on this forum, we probably do not make enough products to encounter these more unusual cases.

Best wishes and take care of yourself, Dave 


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7118
 

@davee I think we agree, Dave, but as usual, there are too many words for my autistic brain to handle. To be 100% honest, when reading a datasheet, it is more often than not my autistic brain that is the problem, not the datasheet. That is why I pester you and others to learn the 'key' parameters so I can search the pdf to get the critical value.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
DaveE reacted
ReplyQuote
(@pajhum42)
Member
Joined: 6 months ago
Posts: 14
Topic starter  

@davee

I mentioned 40mA because I'm using two red LEDs and remember hearing that each LED used about 20 mA.  Since I'm running them through a single resistor  I used 40mA in the online LED resistor calculator.  I'm assuming each led will get 1/2 of the current through the resistor.   Don't know if I have the LEDs represented in the correct orientation in the following diagram but the circuit works in practice.

eyes test bb

   
ReplyQuote
(@pajhum42)
Member
Joined: 6 months ago
Posts: 14
Topic starter  

@inst-tech The TIP120 transistor actually works just fine.  I started with building my test circuit exactly as outlined in the video.  I only substituted the BC548 after I had the circuit working because I purchased a transistor package that came with 20 BC548 transistors and the Darlington package only came with 5 TIP120s.  I still have to go through the explanations give to be sure I understand how to calculate the base resistor correctly.  Thanks again.


   
Inst-Tech reacted
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7118
 

@pajhum42 This is a learning moment!

Did you learn the difference and rationale for the Darlington transistor? Your circuit does NOT actually need a Darlington, just a basic BJT transistor like the BC548.

If this is going to be a serious hobby, buy a few transistor assortment packs plus some logic mosfets and power mosfets plus regular diodes https://amz.run/7U3r , zener diodes https://amz.run/7U3k or https://amz.run/7U3p , shotky diodes https://amz.run/7U3q . Then a few thousand resistors https://amz.run/7U3Y a few hundred capacitors https://amz.run/7U3h andthat is just electrolytic, there are also tantalum, ceramic https://amz.run/7U3i , and one more I don't remember  and now you have the first $0.01 of a $1 of a well stocked hobbyists consumables.

 

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
Inst-Tech reacted
ReplyQuote
Page 4 / 5