How can I use a 2N2222 transistor as a temperature sensor?

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.


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.

enter image description here

0°C 3.591V

25°C 3.328V

50°C 3.057V

75°C 2.781V

100°C 2.500V

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.

Edit/Epilog:-

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.

  1. Calibrated the voltage by adding a multiplier so the reading was accurate in mV compared to a handheld 3.5 digit DMM.

  2. 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.

  3. Tested it at 0°C and 45°C against a type K bead thermocouple.

  4. 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);

Question

How can I use a 2N2222 transistor as a temperature sensor?

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?

I am in high school studying for math.


Answer

Update 2020oct08hkt2248

So I did the preliminary test and measured the three values, Ib (Note 1), Ic, and Vc against temperature from about 3°C to above 50°C (Note 2). I also use Excel to calculate β. A summary is given below.

test results 1


Note 1 - The Ib column is almost constant, as is Vbe. So Vcc and Rb is an approximation of applying a current source to an diode (2N2222 BE junction), and measure Vbc, as advised by @Tony Stewart Sunnyskyguy EE75.

Note 2 - My cheapie digital thermometer for home use overflows somewhere above 50°C. The OP's requirement anyway is to measure the "environment" which I think is approx a range from 0°C to 50°C. So I won't bother for now to find a thermometer for higher temperature.

Actually my calibration plan is to use the DS18B20 temperature sensor to replace my cheapy home use thermometer.


Update 2020oct08hkt1413

Now 2N2222 is enjoying a cold plunge

cold plunge


Update 2020oct08hkt1111

A more high school student friendly schematic of the 2N2222 temperature sensor.


2n2222 temp sensor


Update 2020oct07hkt1549

Sauna test results - stackOverflow!

Hot water bath overflows my digital thermometer!

sauna 1

sauna 2


Update - 2020oct07hkt1151

Tidying up messy wiring, getting ready for Hot Sauna Cold Plunge


temp sensor test


cat spa


Update 2020oct06hkt2141

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.

2n2222 test

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°.


Update 2020oct06hkt1534

Now I am updating my old design with an opAmp.

enter image description here


Update 2020oct0601

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, ...


References

(1) P2N2222A Amplifier Transistors NPN Silicon - On Semiconductor

Update 2020oct06

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.


(17) Precision Temperature Measurement Using CMOS Substrate PNP Transistors - M Pertijs, G Meijer, J Huijsing etal, IEEE Sensor Journal 2004.

(18) Diode-Based Temperature Measurement - TI, Application Report SBOA277A–March 2018–Revised May 2019

(19) What's All This Vbe Stuff, Anyhow? - Bob Pease, Electronic Design's Analog Applications Supplement, 2000jun26

(20) How do you get a temperature sensor from a transistor? - Randy Frank, Sensor Tips, 2017oct27

(21) Using Diodes or Transistors as Temperature Sensors - electronicsNmore, 400K subscribers, 11,037 views 2014nov01

(22) AliExpress LM134/LM234/LM334 3-Terminal Adjustable Current Sources - TI, US $2/5pcs

(23) DS18B20 Programmable Resolution 1-Wire Digital Thermometer Datasheet (±0.5°C {9-bit to 12-bit} accuracy, -10°C to +85°C) - Maxim

(24) DS18B20 Temperature Sensor - Rpi 3/4 Driver, Wiring, Detection, and Python Programming - Rpi SE 2019jul02


Appendices

Update 2020oct06hkt1434

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.


2n2222 1

2n2222 2

I am also using the new MMBT2222 datasheet instead of the old 2N2222.