Temperature sensor with LM393 Comparator and NTC Thermistor

Thread Starter

q12x

Joined Sep 25, 2015
2,227
Im experimenting with a NTC thermistor that is looking exactly like this: 1724270507206.png I have them brand new for awhile for different values. The cct works fine but it is shifting the temperature reading left or right and this is a big error that I partially close my eyes to it but I want another better and stable solution than this sh*t.
- I tested the cct back and forth and the conclusions lead me that this thermistor is the sh*t that is actually shifting, and not some other component in the cct. I even put long wires in the idea that temperature of the diode legs might interfere with the input reading. It is not the legs. And many other experiments, and nothing, no remedy or explanation of the shifting.
- I read that a simple 1N4148 might play a very secure thermistor role. I haven't test it yet.
I found these 4 categories:
1. Negative Temperature Coefficient (NTC) thermistor
2. Resistance Temperature Detector (RTD)
3. Thermocouples
4. Semiconductor-based temperature sensors (with the 1N4148)
- I want your input about this subject... your experience, what do you think is best to test for-- stability-- and --precise-- temperature reading. Without any kind of drifting. Or at least how to combat the drifting?
I used a 2k thermistor instead of that 100k.
1724270544119.png

---
With this occasion I discovered an inconvenience.
You can observe in the cct here, that the LED is powered from the (+)5V rail and surging into the Output pin1 of the LM393.
- LM393 is having a floating state on the output and a negative one when is triggered from its inputs. It does not have a positive output state at all. Some people here suggested this IC to buy, but they didn't tell me at all about this very important detail. I assume probably like me, they are also shocked by this details for the first time too. I also looked into LM393 datasheet and indeed it is having a single NPN (T8) on its output, otherwise stays floating. I presumed its like a 555 with + and - states on the output. What a waste of money. This will be good only to drive very small signals. I just tested with 1k to +VCC on its output pin and a LED surging to 0V rail. The LED is powered by the 1k and shut off when output goes to 0V. The led must be sensitive enough to lit up from 1k or even 10k. It's an annoyance to remember from now on to add that 1k to (+) on its output every time. It's only a single resistor to remember to add after all. I searched for other comparator ICs that has the 'normal' (+) and (-) output switch. I already got a suggestion for TLC3702 or the TLV1812. They are 1$ per 1pcs or some offers of 10pcs at 5$. Not that cheap. The idea is to get 100pcs at about 1to5$ like these LM393. See if you can find something better price/quantity/quality. If possible.
---
And back to the circuit, I already build 4 ccts in my simulator, that are using 1 single NTC thermistor sensor, and 4 or 6 comparators that are reading it. They will lit up a led for 30,40,50,60,70,80*C. The last cct I made is the best in tweaking the values and I got very good results in simulator. But in reality...a ton of drifting and way more errors than I expected. For some reason this turns out to be a very hard project. Thats why Im coming to you.
Here is the last cct I made and it is very easy to tweak (the other ccts before this, were extremely hard to tweak - trust my word).
That voltage on the (+) input, theoretically, I can tweak it from a voltage divider with 2 resistors.
1724272417598.png
In reality, the measured and expected resistor values, didnt worked at all. Possibly because of the drifting problem?!?
I only tested with 1 comparator, and with very bad results and bad luck.
- I dont think is the fault of the comparator. I think is the heat sensor, drifting up when Im increasing the temp and drifting down when Im decreasing the temp. I also think the resistors in the cct are influenced by the temperature and further skewing the result.
I looked for other temperature sensors and there are 4 types, while mine, are between the good ones. I have no idea what to do.
- Lets see, maybe you guys have a better, more consacrated circuit than mine here? Mine maybe is too experimental? It might be that too, a reason for why is not working.
Thank you.
 
Last edited:

Alec_t

Joined Sep 17, 2013
15,112
1) You have no decoupling capacitors on the comparator inputs, so mains and RF interference will result in instability.
2) What provides your 5V supply? What is its current rating? Is it adequately decoupled?
3) Any unused inputs of the LM393 should not be left floating.
4) Each LED should have its own current-limiting resistor.
5) Long wires to the thermistor will act as antennae and pick up interference.
 

sghioto

Joined Dec 31, 2017
8,634
That 1K resistor for the LEDs should connect to 5 volts not ground. As recommended 1 resistor per LED since several can be ON at a time.
 

Thread Starter

q12x

Joined Sep 25, 2015
2,227
I have no such issues with interference or LM393 instability. He and its inputs is doing ok. The only problem is the fact that the sensing resistance from the NTC is moving or shifting or drifting when I cross it's expected point of switching. I already explained: "drifting up when Im increasing the temp and drifting down when Im decreasing the temp". It is not a FIXED point ! Thus, the voltage is drifting and the comparator is switching too late or too soon than the expected (fixed) temperature point.
 

Thread Starter

q12x

Joined Sep 25, 2015
2,227
That 1K resistor for the LEDs should connect to 5 volts not ground. As recommended 1 resistor per LED since several can be ON at a time.
It is correct as it is! You are explaining the classical LED theory. The modern LEDs are different. I am using NEW tech LEDs and not 80's OLD tech LEDs. We discussed about this subject already and is well known. The cct, as it is, will work fine.
Here is the proof: How many ON LEDs can you count in this proof image? at 5V
.20240822_011315.jpg
Enough about the LEDs because they are also drawn like that as an -idea- in the same time.
Take a look at the LM35 temp sensor it can be connected to an ADC input of a micro and processed from there.
Yes, I've seen them on some arduino projects on youtube already. Im not very sure about them either. In code, there are some conversions and some corrections. Im aware to not expect them to be linear but... mine are awful, or at least, Im not using them right maybe? These LM35 will be considered in the future. Until then, lets see if we can correct this aberration from the ones I have here. Hopefully. Give me some ideas to try on them. Also try yourself if you have them and tell me your results.
 

Ian0

Joined Aug 7, 2020
13,117
I'd say that there's only one thing wrong with your circuit - your choice of the 330Ω resistor. It's much too small. Everything will be cramped down on end of the scale.
Choose your resistor to be about the same value of the thermistor at the middle of the range - my guess is that it would be about 22k.
Change that and I bet it works perfectly.
 

Thread Starter

q12x

Joined Sep 25, 2015
2,227
I'd say that there's only one thing wrong with your circuit - your choice of the 330Ω resistor. It's much too small. Everything will be cramped down on end of the scale.
Choose your resistor to be about the same value of the thermistor at the middle of the range - my guess is that it would be about 22k.
Change that and I bet it works perfectly.
I already tried that. Please look in my simulator image. I used 1k for the NTC and another 1k for the R in the voltage divider. To have a 2.5V start. It is not helping it. I didnt beat this horse too much in reality. I know I did changed a couple of times this resistor (in reality) but not that many. I will consider changing it more in the next experiments and see if it helps.
 

Ian0

Joined Aug 7, 2020
13,117
Your reference voltages are far too close together. With a 4.7k NTC to ground and 1k pullup, I get the following voltages:
100°C = 1.588V
90°C = 1.86V
80°C = 2.17V
70°C = 2.52V
60°C = 2.92V
50°C = 3.29V
40°C = 3.64V
30°C = 3.98V
 

Thread Starter

q12x

Joined Sep 25, 2015
2,227
Your reference voltages are far too close together. With a 4.7k NTC to ground and 1k pullup, I get the following voltages:
100°C = 1.588V
90°C = 1.86V
80°C = 2.17V
70°C = 2.52V
60°C = 2.92V
50°C = 3.29V
40°C = 3.64V
30°C = 3.98V
sorry about that. I forgot to mention this detail. Those voltages are for the simulator only. To click one time that POT down/Up and to see the changes in the LEDs. So NOT for the real life.
The measured values in real life are these:
30°C = 2.70V
40°C = 3.03V - 3.06V ↓
50°C = 3.29V - 3.34 ↓
60°C = 3.57V
And theoretically the voltage divider for these voltages are these:
(-) (+)
1k-918
1k-788
1k-680
1k-572
These are the expected values. But slap on my doink, its not even close. I am strongly suspecting this drifting Im confronting with. I start to formulate an idea why this drifting is happening. My believe so far, is because of that glass surrounding the heating element. I have 2 probes side by side, One from the electronic thermometer that Im reading the *C and the other one for this circuit here. As you can clearly see, they are very different, not the same. Mine is PTC and the other is a Thermocouple. I believe that glass as a strong insulator is heating up MORE slowly and cooling down MORE slowly too. I basically have to wait it warm or cool down and it is inducing this error or drifting as I call it. Hmmmm - Im not entirely sure yet, if this is the real offender. But I start to think it MIGHT be it. Right? what a pain in the arse.
20240822_023546 Copy.jpg
 

Thread Starter

q12x

Joined Sep 25, 2015
2,227
1) You have no decoupling capacitors on the comparator inputs, so mains and RF interference will result in instability.
So to see that Im considering any suggestion, I put 1nF on both inputs of the comparator. Maybe its a placebo effect, for the moment, but from the little experiments I did, MAYBE? the drifting is more stabilized now? I did about 1h of experimentation with them connected. I want to believe they improved the reading. With 100nF I could see a small delay or the drifting itself so I switched to 1nF, and it seemed better. Hmmm... will see after more time. Not very concludent at this point. But it was a very good idea.
2) What provides your 5V supply? What is its current rating? Is it adequately decoupled?
Im using my usual variable SMPS 30V@5A. Im not using an isolation transformer.
5) Long wires to the thermistor will act as antennae and pick up interference.
I thought about this thing too, but in this case, the 'drifting' is way more powerful than any other possible interference or noise. The cable I use is 15-20cm long. It is not meters long to catch any serious interference.
 

Thread Starter

q12x

Joined Sep 25, 2015
2,227
I was speaking of your lower schematic in post #1. One end of the 1K resistor should connect to 5 volts not ground.
In the simulation there, Im using a general comparator omponent, that has this (+) and (-) output, not like this crap lm393 with only half of the normal output, what a bad joke it is. I am very annoyed over it. But on the other hand, it was cheap for 100pcs.... so I will swallow it. But I will be forever annoyed !
 

MrChips

Joined Oct 2, 2009
34,714
In the simulation there, Im using a general comparator omponent, that has this (+) and (-) output, not like this crap lm393 with only half of the normal output, what a bad joke it is. I am very annoyed over it. But on the other hand, it was cheap for 100pcs.... so I will swallow it. But I will be forever annoyed !
There is nothing wrong with the LM393 comparator. If you were to examine all other comparators, they have uncommitted outputs. This is called "open collector" and it is done by design. It gives the circuit designer the ability to use a supply voltage that is different from the chip's Vcc.

In fact some comparators go one step better. LM311 comparator has both output emitter and collector uncommitted. In other words, this is both "open emitter" and "open collector" output. This is a beneficial feature, not a deficiency.
 

Thread Starter

q12x

Joined Sep 25, 2015
2,227
There is nothing wrong with the LM393 comparator. If you were to examine all other comparators, they have uncommitted outputs. This is called "open collector" and it is done by design. It gives the circuit designer the ability to use a supply voltage that is different from the chip's Vcc.

In fact some comparators go one step better. LM311 comparator has both output emitter and collector uncommitted. In other words, this is both "open emitter" and "open collector" output. This is a beneficial feature, not a deficiency.
It is a strange 'feature'. One I recognize I'm not used to. For me the normal is "1" or "0". Not "F" and "0". I looked into your LM311 internal cct, and it is more weirder than I imagined. Its new stuff for me, and is intriguing.
Have you used these "features" as you say? Where and when? Give me 1 good simple example.
So let me say what I understand from your last explanation. I can power the IC with 5V but drive a 10V on its output? Correct? That's the idea? Hmmmm....very interesting.
 

MrChips

Joined Oct 2, 2009
34,714
Open-collector and tristate outputs are two of the three fundamental types of outputs found in digital logic gates. Of course, the third one is "totem-pole output".

SN7406 and SN7407 driver logic gates have been around since 1964.

"open-collector" outputs were used dating back pre-1980 when all computer bus systems used "wired-OR" logic. This is where two or more logic outputs could be wired directly to form an OR function without any risk of blowing the gates.

So, instead of lambasting something you don't know anything about, you should ask questions first right here on AAC.
 

MisterBill2

Joined Jan 23, 2018
27,362
One thing that may not have entered the discussion is that thermistors are NON-LINEAR!! Always they are not a uniform change in resistance for a given step change in temperature. IN ADDITION, the fairly large current flowing in the thermistor will certainly cause self heating. No way around that, either. So if you want stable and accurate at more than one point, a thermistor is not what you need. They are cheap and fairly durable but seldom used in a circuit like the TS is using.
The most linear sensor is the RTD, although some semiconductor sensors can be as linear and possibly as stable.
Certainly a diode sensor in the correct circuit can be stable and accurate if the power source is regulated and all the capacitors required for stability are in place. That can be a problem because it is quite possible to have a comparator oscillate quite well, producing amazing results.
 
Last edited:

Ian0

Joined Aug 7, 2020
13,117
Have you used these "features" as you say? Where and when? Give me 1 good simple example.
  • Comparing two voltages between 0 and 12V and outputting to a microcontroller input (the inputs normally have a selectable pullup resistor)
  • Comparing two small voltages and driving a string of LEDs in series.
  • Putting the LED between output and ground (with a pullup resistor). Then there are no large changes in current when the LED switches on and off.
  • Making a bargraph by putting all the LEDs in series and shorting out those which should be off (LEDs driven from V+ via single constant current source)
 
Top