I’m supposed to use a TMP36 transistor for a class to read the temperature of the environment, but I only have a 2N2222 transistor; the Arduino will have an analog read of it, but the numbers won’t change even if I heat it up. Am I screwed or can I fix this?arduinotransistorssensortemperatureshareedit follow flagedited 2 days agoPeter Mortensen1,63633 gold badges1616 silver badges2323 bronze badgesasked Oct 4 at 2:03John Rawls19711 silver badge22 bronze badges New contributor
- 9A TMP36 is not a transistor, so there is no way to substitute it with a 2N2222 which will give you useful results. – brhans Oct 4 at 2:12
- 4@John Rawls, Ah yes, you can turn 2N2222 into a TMP2222 for your class to read temperature of the environment. The problem is that Arduino ADC is only 8 bit so it is not precise enough to detect the small 2N2222 characteristic differences (eg, hFE, Ic etc) as temperature changes. A workaround is to use a dirt cheap 10bit/12bit ADC such as MCP3008/MCP3201/MCP3208 which enable you to read 0.!% to 0.025% accuracy. Then you need a thermometer to calibrate the hFE/Ic vs temperature graph. The graph might not be that linear. But / to continue, … – tlfong01 Oct 4 at 3:12
- 3/ continue, … you can show your class that you are an innovative future engineer, and of course they would see you as a hero, and your teacher couldn’t resist to give you a A grade, and your school principal to give you an outstanding R&D academic award, Then your principal can write to Analog Device about your fake TMP36 studies, and request them to give your class 40 real TMP transistors to do real research. 🙂 – tlfong01 Oct 4 at 3:17
- 2Vbe of the transistor depends on temperature in a fairly predictable way. Using a diode or base-emitter junction as a temperature sensor is a fairly common application. Spehro already answered, though, so I won’t write another answer saying the same thing. – mkeith Oct 4 at 4:43
- 1Does Vbe really depend on temperature? I think, instead it is the collector current which depends on temperature (for a fixed Vbe) – and Vbe must be reduced by app. 2mV/K to bring Ic back to its former value. – LvW 2 days ago
- 1@tlfong01 “The problem is that Arduino ADC is only 8 bit” – The Arduino Uno and comparable boards use an Atmega328P, which has 10 bit ADCs. – marcelm 2 days ago
- 4“the Arduino will have an analog read of it but the numbers wont change even if I heat it up.” – Sooo, how did you connect the transistor and your Arduino? Provide a schematic please. – marcelm 2 days ago
- @marcelm, Ah, the first line of my updated answer says that that I will be using MCP3008/3201 ADC, and followed by the schematic. 2N2222 is biased by fixed value Rb (Gloen_geek, suggests 1 Meg, so I will blindly try it.) As shown in the schematic, 2N2222 output will go to ADC, controlled by Arduino/Rpi through SPI. – tlfong01 2 days ago
- I know the 2N2222 output vs temperature might be very non sensitive and very non-linear, and even 12 bit ADC is not accurate enough to process. So I already have 16/24 bit ADC standby, to brute force do ADC and massage non linear curve to become linear. I know I am walking a long and winding road, and at the end of the journey find nothing. But think I will at least know more 2N2222 inside out, and also 24 bit ADC usage. – tlfong01 2 days ago
- 1@tlfong01 My second comment (asking for a schematic) was intended for the OP 😉 – marcelm 2 days ago
- @marcelm, (1) Many thanks for pointing out my careless mistake of wrongly thinking that Arduino ADC is only 8 bits resolution. I wrongly mixed up Arduino ADC with PWM. Actually Arduino PWM has 8 bits only, but Arduino ADC has 10 bits. (2) Now I think Arduino 10 bits ADC is OK to start our experiments. Actually many applications might not need to accurate, 2 Celsius degrees is enough. / to continue, … – tlfong01 2 days ago
- (3) Therefore I decided to remove the external ADC (MCP3008) in my answer. I will also remove Rpi from my answer, because it is only Rpi that needs MCP3008 ADC. Arduino is just about right for our project here. I will update my schematic ASAP. Thanks a lot. Cheers. PS – I would suggest to move our discussion to chat. See you in the chat room. – tlfong01 2 days ago
- Let us continue this discussion in chat. – tlfong01 2 days ago
- 1I just dropped in (been busy.) Top rated answer says “no can do.” Not one single person here has even given the slightest nod to using the collector region where the lower doping and a higher electric field can be used to advantage in providing better linearity and sensitivity. – jonk 2 days ago
- 1@LvW, yes, Vbe depends on temperature. If you can find it, Bob Pease covered this at length in “what’s all this Vbe stuff anyhow.” This link is working, for the moment. forum.vegalab.ru/… – mkeith 2 days ago
- 1@jonk you mean forward bias the base/collector junction and use it as a temperature sensing diode? – mkeith yesterday
- 1@mkeith, I am afraid you did not interpret the article from Bob Pease correctly. In connection with Fig. 2 he wrote: “This illustrates the bias of transistors at various constant currents versus temperature.”. So – as I have stated: Vbe does not vary with temperature, but it MUST be changed EXTERNALLY by app. 2mV/K for a constant collector current Ic. This is because Ic is the source of temp. dependence! – LvW yesterday
- 1@LvW I have biased Vbe junctions with constant current on the bench and watched Vbe change with temperature. Same holds for diodes. Please try it yourself. – mkeith yesterday
- 1@LvW you may be right that I misinterpreted the direct applicability of Bob Pease’s article to this situation. Still, diodes are often used as temperature sensors on IC’s. The Vbe junction can be used as a diode. Or the base and collector can be tied together. Either way, Vbe will change with temperature under constant bias. – mkeith yesterday
- 1@LvW ti.com/lit/an/sboa277a/sboa277a.pdf – mkeith yesterday
- 1@mkeith, am I wrong when I think that it is the CURRENT change which is used as an indicator for temp. variations? – LvW yesterday
- 1continued: But – with reference to the linked TI note, of course, I agree that for a constant current, the Vbe change can be used in a special circuit (as shown) for temp. measurements. – LvW yesterday
- 1You don’t need a special circuit if your ADC has enough effective bits. But you do need to calibrate. – mkeith yesterday
- 1@mkeith No. I guess no one here ever reads BJT-as-temperature-sensor research papers from folks who actually research this stuff. For example, there are innumerable papers on using BJTs created on CMOS process technology exactly for this purpose. And that’s only one small category of research papers on this specific topic. Some of the knowledge there would apply to discrete design (not all of it, obviously.) I guess for engineers, it’s work; and unless they work in this field they don’t read research papers just for fun and enjoyment as I do. They have a life. 😉 – jonk yesterday
- 1Well, @jonk, enlighten us! Or at least give a link or something. LOL. – mkeith yesterday
- 2@mkeith “The temperature characteristics of bipolar transistors fabricated in CMOS technology,” Guijie Wang & Gerard C.M. Meijer, 2000, is one I quickly see on disk here at home (searched, since I knew what to look for in this case.) – jonk yesterday
- @jonk, Many thanks for the reference. Unluckily it is a book costing US$40!. Luckily I googled the book author Meijer and found a free PDF paper also by him: Precision Temperature Measurement Using CMOS Substrate PNP Transistors, M Pertijs, G Meijer, IEEE SENSORS JOURNAL, VOL. 4, NO. 3, JUNE 2004 citeseerx.ist.psu.edu/viewdoc/…. – tlfong01 yesterday
TMP36 is specifically a temperature sensor, not an NPN transistor like the 2N2222. You might have them confused because they both can come in TO-92 package. It is possible to look at the various properties of 2N2222 transistor and correlate it to temperature (see the other answers on this page), but that seems not practical for your application.
You will have to find a suitable alternative temperature sensor that “provide a voltage output that is linearly proportional to the Celsius temperature” with similar output to the TMP36 or try a different approach.shareedit follow flagedited yesterdayanswered Oct 4 at 2:34syntax53911 silver badge77 bronze badges
- 11This is the only answer so far that is actually an answer to the question, rather than a science experiment – BeB00 Oct 4 at 3:46
- 2@BeB00 actually, the use of a BJT as a crude temperature sensor is usually taught in microelectronic courses to stress the dependency of the characteristics from temperaure. If anything, this answer misunderstood the OP intention to create the best temp sensor possible with a single BJT transistor. Scroll down to see actual answers to the question asked. – Sredni Vashtar yesterday
- @SredniVashtar Yes, it is, but thats not what the question was. You can use many different things as temperature sensors, and most of them are not very good (for example, BJT transistors). A system built with the 2N2222 will not be a good temperature sensor without significant calibration and effort. The fact that the poster mentions the TMP36 suggests that they are supposed to use an actual temperature sensor, and OP did not understand that although the two devices look similar, they are very different. You can see from the upvotes that people agree with this comment. – BeB00 yesterday
- 1@SredniVashtar the question isn’t “I need to make a temperature sensor with a 2n2222, how do I do it”, it’s about a class where the person is supposed to use a temperature sensor to read the temperature. These other answers, while interesting, are not actually relevant to OP, since they are a beginner who needs a simple way to get the temperature, rather than create a complex circuit, calibrate it, and try to use that instead. The OP has confused the TMP36 with a transistor, and they’re asking if they can use the 2n2222 as a subsititute. The answer to this question is no – BeB00 8 hours ago
- 1@SredniVashtar It’s quite common on this site to have beginners come in and ask questions, and then have long answers suggesting (relative to the OPs knowledge level) complex and clever circuits which are of basically no help to the asker. This is one of those times. As I said, the answers are interesting to read, and should be encouraged, but people should also take into account what the question really is, because if Syntax hadn’t answered, there would be nothing that actually helped OP – BeB00 8 hours ago
If you connect the transistor as a diode and bias it with a reasonable current, maybe a couple hundred uA, you can read the voltage. It will require calibration (say at room temperature and 0°C in an ice-water slurry.
Sensitivity will be about -2mV/K so with a 5mV resolution ADC you’ll have 2.5 degrees C resolution, not great.
If you connect it as a Vbe multiplier, say with 5:1, and average many measurements you might be able to get a usable resolution of about 0.5°C. Or just use an op-amp.
Edit: Here is a simulation result used as a simple Vbe multiplier.
The current drops as the voltage increases (due to the use of a simple resistor as a current source) so the linearity isn’t great= 11.2mV/K average at 0..25°C and 10.5mV/K average at 75..100°C, but for narrow excursions around room temperature it should be fine, or it can be corrected digitally. With a 10-bit ADC and 5V Vref the resolution is about 0.5°C, which is adequate for many purposes.
There are much better ways to measure temperature with a transistor, however the complexity is increased. Using matched transistors or multiple (2 or 3) currents with a single transistor allows cancellation of many of the transistor parameters that vary from unit to unit, as well as connection resistance. Unfortunately, the sensitivity is reduced by at least an order of magnitude so better analog circuitry is required.
I tried this with a single diode-connected BJT (base connected to collector) with a 10K resistor to the regulated (and otherwise unused) 3.3V rail on an Arduino Nano. Reference set to nominal 1.1V as suggested by @EdgarBonet, summed 100 sequential readings.
- Calibrated the voltage by adding a multiplier so the reading was accurate in mV compared to a handheld 3.5 digit DMM.
- Wrote the equation for temperature based on the current room temperature and the mV, with an estimate of -2.0mV/K for the Vbe temperature coefficient.
- Tested it at 0°C and 45°C against a type K bead thermocouple.
- Adjusted the 2.0 to 2.2 to reduce the error at the temperature extremes.
adc *= 1.0532319391 * 0.01; // calibrated voltage in millivolts, 100 summed temp = -(adc - 556)/2.2 + 24.0;
Works quite well with only one unexpected thing- the INTERNAL1V1 constant was not defined even though the Arduino environment knows it is an ATMega328p (using an Arduino Nano). I added one line to code the definition:
#define INTERNAL1V1 2 analogReference(INTERNAL1V1);
- 1The sensitivity depends inversely on bias current. Lower bias current will give slightly higher sensitivity. And I am not sure but I think maybe a couple hundred microamps will give sensitivity of more like 1.8mV per degree. I think maybe 10uA is enough, but I guess it depends on the ADC leakage current spec. You want the bias current to be much higher than the ADC leakage current. – mkeith Oct 4 at 4:59
- Note that you need an OP amp in order to read the signal using an Arduino (as the OP mentions in the main question). The Arduino required an impedance of 10kOhm or lower in order to stay within spec for the analog inputs – Ferrybig 2 days ago
- @Ferrybig There are techniques for allowing several hundred K input impedance without significant error (10n cap + certain delays), or reduce the resistors 5:1 for similar results. – Spehro Pefhany 2 days ago
- 2Note that on most Arduinos you can set the voltage reference of the ADC to some internal reference lower than Vcc: 1.1V or 2.56V on AVR boards, 1.0V on the SAMD boards… – Edgar Bonet yesterday
- 1At 1.1V a single diode-connected transistor with a 10K series resistor to +5 would work very nicely. Resolution about 0.5°C. Might have to average a bunch of readings. – Spehro Pefhany yesterday
Can 2N2222 transistor be converted to a temperature sensor, such as TMP36?
Sauna test results – stackOverflow!
Hot water bath overflows my digital thermometer!
Update – 2020oct07hkt1151
Tidying up messy wiring, getting ready for Hot Sauna Cold Plunge
So I adjust the values of Rb and Rc to move operation region from saturation to amplification, where current gain is around 250, similar to the value measured by the multi-meter, as illustrated below.
I then used a hot gun to blow hot air to the 2N2222 circuit. I guess the temperature around the circuit should be higher than 50 degree C, because my hand could not bear it for more that one or two seconds.
I am glad to see that Vc, Ic, and Ib rose, as summarized below.
------------------------------------------------------- Temp Ib (mA) Ic (mA) Vc (V) β ------------------------------------------------------- 28°C 0.0230 5.6 0.18 243 Hot air 0.0244 6.6 1.30 270 -------------------------------------------------------
Of course the temperature as measured by hand is very crude, but the changes of Ic, Vc, and β is significant.
I don’t worry that Ic, Vc, and β vs temperature is non linear, because we can use software to calibrate, sort of flatten/straighten the non linear curve to a straight line.
Next step is to use ice cold water around 0°C and hot water at 90°C to measure and plot Ic, Ib, Vc, and β against temperature in C°.
Now I am updating my old design with an opAmp.
As I found that my old tests do not give expected results, because of wrongly chosen components values. So I am moving the old design and bad test results to the GiHub page.
I think @csabahu’s answer is very good. So I am studying his design and using his testing parameters to do my coming tests. I originally thought that I should be using the 2N2222’s current gain to amplify the very small output values for easy measurement. Now I thnik @csabahu’s use of the opAmp is a much better approach, because the opAmp should not load down output signals and also can easily adjust gain factors.
But I have little experience in using opAmp for instrumentation. So I need to google some more tutorials before I start my new circuit.
My old design with Ic of the order 1mA has already saturated the 2N2222. Now I am thinking of up shifting the Ic test range from 1mA to 10mA, and even up to 100mA. My old selection of Ib of the order of 1uA is also too small for my cheapy multimeter to measure.
/ to continue, …
The old reference list was getting too long and messy, so I have moved those not too relevant old references (16 in total) to the GiHub page.
My first idea of testing plan is wrong, because I don’t understand the small signal properties of 2N2222. My knowledge and experience is only on the use of 2N2222 as a switch. So I am studying the datasheet and thinking of designing a new test plan. One thing I am doing is to shift the Ib and Ic testing range, so it is easier to use my multi-meters to do measurements. The new datasheet summary is pasted below.
I am also using the new MMBT2222 datasheet instead of the old 2N2222.
- 6The dreadful P2N2222 is about to strike again. To the OP: watch out for inverted C and E terminals, if you have a 2N2222. – Sredni Vashtar Oct 4 at 3:49
- 2@Sredni Vashtar, Many thanks for your very important and critical warning. Do you know why some chips have the two terminals inverted? In my long electronics hobbyist life, I have never heard of such a ridiculously dangerous pinout trap, for newbies, ninjas, and even pros alike. – tlfong01 2 days ago
- 1That 2N2222 circuit shown here with one base resistor, and one collector resistor is about the best you can do for a simple temp sensor. However, choice of resistor values depends greatly on transistor HfeHfe, which varies greatly from device-to-device. Try a base resistor of 1Meg, and then choose Rc so that collector voltage is roughly half-way at room temperature. – glen_geek 2 days ago
- @glen_geek. Ha, many thanks for your instruction, which I think is simple and concise. I must confess I don’t know at all your rationale or theory behind. But it so simple, so I guess both me and the OP which I guess is around 16 old student can also blindly follow your tip, and then do some measurement to see if your circuit might lead to anything promising. Then I will study the datasheet or other theories behind, and try to find why you suggest your design. / to continue, … – tlfong01 2 days ago
- I now see our approach is odd, because it is not like the photo transistor, which sort of using CE junction, without electrical but only photo/light input from base. Of course I know I can just use a diode, which according to the (Schottky?) diode equation, is current dependent to temperature. Anyway, I will stop selfie brainstorming, and start experimenting @glen-geek’s geek tip.. – tlfong01 2 days ago
- @glen_geek, now I have set up the test circuit to test out your suggestion of using 1MR for Rb, varying Rc and see how it goes. I have also update the circuit and put it at the very top of my answer. Comments and counter suggestions welcome. Cheers. – tlfong01 yesterday
- 1tlfong, my opinion is that the pn2n2222 was created for the Japanese market (I have no hard evidence, though) where transistors have usually the CBE pinout, opposite to the customary (but not universally shared) EBC pinout of American and European transistors (I am talking about small signal BJTs – power transistor are another thing and the usually have to middle pin connected to the collector or drain). – Sredni Vashtar yesterday
- 1@tlfong01 Please keep your edits to a minimum and your answers a bit shorter, the answers are a bit long. Thanks – Voltage Spike♦ yesterday
- @Voltage Spike, Thank you for your advice. Actually some of the suggestions and tests in my answer are out of date, misleading and plain wrong. So I have decided to set up a GitHub page, and place the datasheet summaries there. This way I can make my answer perhpas many times shorter, and only refer to my GitHub page for not too relevant details. Thanks again. Cheers. – tlfong01 yesterday
- 1Also note that the OP thought that the TMP36 was comparable to a 2N2222 so most of this is probably way over his/her head. Pitch the answers so that the OP has to reach just a little to grasp the concepts. – Transistor 17 hours ago
- @Sredni Vashtar, I agree with you that the vendor packages 2N2222 with pinouts as ordered by the Japanese buyers. I also notice that the new datasheets provide different styles of pin layouts for customers to order. – tlfong01 17 hours ago
- @Transistor, Ah yes, I am not surprised to discover that the OP is just a 15 year old student and a member of a computer hobbyist club in his school. My thinking is that he might be happy if we guide him to read the datasheets and how he can convert the 2N2222 into a temperature sensor, however crude or non linear his converter sensor it is. I guess even the designer of TMP36 is doing some sort of curve fitting/straighten to make final product linear and accurate. We might explain to the OP, that even if we cannot DIY a temperature sensor with accuracy of 0.5 degree. / to continue, … – tlfong01 17 hours ago
- But in many applications, eg, measuring the temperature of warm water in a bath, or even room temperature to control air conditioner/heater, an accuracy of two degrees is acceptable. My objective in making this answer is educational, learning how to read a datasheet, idea of non linearity and how to use software to workaround. Accuracy is never a requirement in my suggested DIY sensor, because it is not supposed as a accurate scientific instrument. / to continue, … – tlfong01 17 hours ago
- As you said, grasping concept, doing/learning/appreciating engineering design, trade off, cost benefit analysis, and the joy of DIY/making things or just a toy, even the project ends up a “failure”, is important, not accuracy or applicability – tlfong01 17 hours ago
At zero degrees, set 3V at the output with a 47k resistor. Then at 100 degrees with 10k resistor to 1V. (Ice water or boiling water.)
- 1You probably meant to write ‘potentiometer’ instead of resistor. – Sredni Vashtar yesterday
- 1Almost. A smaller potentiometer with which the ratio of the given resistors can be fine-tuned. For example, a 2k potentiometer between 47k and 10k. Here, it is not the absolute value of the resistance that is interesting, but the voltage setting of the non-inverting input. Of course, this is only needed if we want to calibrate the thermometer. – csabahu yesterday
- 1@csabahu, Ah, your colourful schematic is looking nice, and the opAmp Vout vs Temperature chart is impressively ideal. So I will search my jun bin for an opAmp and try it out. – tlfong01 yesterday
- 1@tlfong01, What’s the weather like in your city today? Have you tried the thermometer? – csabahu 12 hours ago
- 1@csabahu, (1) Ah, I usually Yahoo to get the weather in my city: hk.news.yahoo.com/weather. (2) I do have a couple of thermometers. See update today (2020cot07) of my answer to see how I am using my digital thermometer. Cheers. – tlfong01 3 hours ago