fake lm35dz temperature sensors

Anything not related to STM32
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

fake lm35dz temperature sensors

Post by ag123 »

Well, as usual, the 5pcs for a dollar lm35dz
https://www.ti.com/product/LM35
from the usual AliExpress/eBay pirate bay are too good to be true, and so they are not true :lol:
I got a bunch of fakes, pretty much lm35dz listed at around a dollar for 5, that's pretty expensive for a fake.
The sensor readings from stm32 PA0 ADC1

Code: Select all

pa0:129,0.10
pa0:161,0.13
pa0:252,0.20
pa0:288,0.23
pa0:326,0.26
pa0:350,0.28
pa0:378,0.30
pa0:398,0.32
pa0:388,0.31
pa0:458,0.37
pa0:455,0.37
pa0:463,0.37
pa0:484,0.39
pa0:501,0.40
pa0:510,0.41
pa0:502,0.40
pa0:508,0.41
pa0:508,0.41
Every 10th millivolt is the temperature, sample rate is every 1/2 seconds, so it goes from 13 deg C to 41 deg C in under 8 secs.
My wall thermometer did not change a single centigrade/Fahrenheit all that time :lol:
Initially, the readings are even more variable than this, so I added 2 more lines (libmaple core f4)

Code: Select all

void setup() {
	//adc clk max 36mhz, using 84/4 ~ 21mhz
	adc_set_prescaler(ADC_PRE_PCLK2_DIV_4);
	adc_set_sampling_time(ADC1, adc_smp_rate::ADC_SMPR_480);
	...
}
480 ADC clocks sample time, that is the longest possible in the register.

It is disappointing, I'd likely get back to the vendor about it, at least to inform them about the fakes.

Then I searched Farnell (element14.com) catalogue. I found better sensors, they are more accurate 0.4 deg C and cost less than the LM35DZ list price there.
https://www.ti.com/product/LMT86
https://www.ti.com/product/LMT87
and best of all, they run off low voltages which can be powered from the 3.3v VDD on most stm32 'pill boards'.

For high precision, high accuracy parts, it is still way safer to get them from the 'regular' sources, digikey, mouser, farnell (element14), octoparts etc.
The premium is no doubt high, but one can be assured of original parts. Adafruit, Sparkfun counts among them as well and it's possible to get nice modules all built and ready to go than just the chips alone.
Last edited by ag123 on Tue Sep 07, 2021 7:30 pm, edited 1 time in total.
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: fake lm35dz temperature sensors

Post by mrburnette »

Weird...

Are the units physically warm after power is applied? Even fakes should be stable. Maybe the factory wired the die incorrectly.
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: fake lm35dz temperature sensors

Post by ag123 »

The temperature sensors are intended to calibrate thermistors (of course the 'cheap' types), I got a 'bad surprise', what is deemed 100K thermistors in a 3d printer kit, measures 52k at 25C, the rated temperature for which it is supposed to read 100k.
And now even the 'precision' 'pirate bay' temperature sensors are fakes.
I'd guess many of the 3d printing problems could be faulted on goofy thermistors.
I could have used thermocouples to calibrate them, but I prefer the semiconductor sensors as they are far simpler, and they are engineered / manufactured to spec.

@mrburnette nope they feel just the same temperature as I touched them, and maybe a little warmer as I warmed it up with my hand :lol:
I tested alternate pieces, same behaviour, irregular readings

That LMT86, LMT87 are recommended, a thing is it isn't totally linear (but close to linear), TI gave a quadratic equation in its spec sheet.
https://www.ti.com/product/LMT87
I'd guess using that equation would give you 0.4 degrees accuracy and precision. It'd seem stm32f4xx would have no issues dealing with that with floating point hardware.

ST has LM335, they are cheaper per part than LM35DZ from TI
https://www.st.com/en/mems-and-sensors/lm335.html
But another stockist accessible from my end list them in packs of 1000, uh oh :lol:
I'd think LM335 is the safer part to get from the likes of AliExpress/eBay. But if precision and accuracy is important, then the options are lesser and original parts give some assurance.

So it is after all fake, found a thread here
https://forum.allaboutcircuits.com/thre ... ad.118398/
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: fake lm35dz temperature sensors

Post by mrburnette »

Pete (deceased) has an interesting article regarding "Linearizing" a NTC thermistor. The impact on CPU cycles is minimum as it was developed during the heyday of 8-bit Arduinos.

https://www.phanderson.com/picaxe/lin_thermistor.html

In a perfect world, high quality thermocouples and special transconductance and cold-junction corrected amplifiers would be used. I have used this technique and the results are awesome. But, a 5-cent NTC thermistor is generally satisfactory using the Steinhart-Hart equation. Pete's approach can drive the accuracy even better; but, it does take time to do a custom solution.

I suspect your issue could be as ugly as a manufacturing mislabeling or contamination problem. 52K @25C is not a standard value unless special order.

I can not even imagine how counterfeiters could make a decent profit from faux-thermistors... boggles the mind.
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: fake lm35dz temperature sensors

Post by ag123 »

The thermistors probably isn't faux, but it says something about 'quality control' if it exists after all. As thermocouples require cold junction compensation, without some proper temperature readings on the cold junction, I'd need to immerse it in a tub of melting ice, and I'd need to strap up an op amp contraption to amplify the signals (most likely on a breadboard). Hence, I selected semiconductor temperature sensors to calibrate them as those are easiest, made to spec, amplifies the signals, so I'd only need to use the ADC in stm32.
The cheapo in me found the 'pirate bay' ones too attractive a price, and so it turns out those LM35DZ on AliExpress/eBay etc are faux. This is really frustrating to say the least. The identification feature of the faux LM35DZ is a 'National Semiconductor' logo deliberately laser engraved on it.
It is exactly this
https://forum.allaboutcircuits.com/thre ... ad.118398/
The real lm35dz cost upwards of $1.50 each, ordered direct from TI (it is out of stock now ! Just how popular it is)
https://www.ti.com/store/ti/en/p/product/?p=LM35DZ/NOPB

I've ordered the TI's LMT86 currently from element14.com, Farnell. The premium is about a dollar each.
https://www.ti.com/product/LMT86
LMT87 https://www.ti.com/product/LMT87 may be closer to the voltage range of STM32. LMT86 give about 2.2v at 0 degree C, its rated design voltage. While LMT87 gives about 2.7v. It'd seem LMT86, LMT87 are elaborate NTC thermistors :lol:
Hope this makes for a much smoother experience.

Edit:
it seemed I should have got this instead DS1820, thermowell metal casing, waterproof, wires and all made-to-order $1
https://www.aliexpress.com/item/4000895660165.html
https://www.aliexpress.com/item/32676135779.html
either way, I'd just make do with what I've ordered for now.
david.prentice
Posts: 19
Joined: Thu May 14, 2020 8:39 pm
Answers: 1

Re: fake lm35dz temperature sensors

Post by david.prentice »

I am intrigued by stories of fake "small" chips.

An Ebay seller might shift a hundred "1-off" or "5-off" packages. Most buyers don't complain. The few that do will destroy any profit.

An AliExpress seller that shifts several "1000-off" or "10000-off" packages will not get very far. The buyers WILL complain.

Now I can quite believe QC failures being sold on Ebay. And sub-standard components being used in BluePills, BlackPills, ...
But this just means that the current consumption or accuracy is a bit off.

The business model works with sub-standard but I really can't see how it can be worth selling "fake" LM35DZ.

I would have been more impressed by the LM35DZ examiner reporting the standard characteristics of the suspected "NPN transistor"

David.
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: fake lm35dz temperature sensors

Post by ag123 »

Original LM35DZ from TI are selling for like USD 2-3 each on the likes of Digikey, Mouser, Farnell (element14), Octoparts, Adafruit, Sparkfun etc. and $1.5 possibly in bulk from TI. The huge price premium for a TO-92 'transistor' part and the demand for a popular item i.e. LM35DZ is probably the reason of criminal faux/fake manufacturing. The markings are precisely laser engraved with a 'National Semiconductor' logo, but it is probably pure plastic with 3 metal pins sticking out of it. There is no connecting between any of the 3 pins.
https://forum.allaboutcircuits.com/thre ... ad.118398/
this is deliberate criminal and intentionally manufacturing fakes and selling them.

It is probably safer to get other part numbers such as LM135, LM235, LM335 which ST sells as well.
https://www.st.com/en/mems-and-sensors/lm335.html
This is 'a little harder' to use than LM35DZ, I'd guess it is why LM35DZ is more popular as a 'plug and play' thermal sensor.
The thing is, this does not stop the criminals from laser engraving other TO92 part numbers and selling fakes of those as well. Hence, be wary of this.
There is also the DS18B20
https://www.maximintegrated.com/en/prod ... 18B20.html
This is less likely fake, as it is too easy to prove the fake. I'm a little foolish, insisting on 'analog' simply as stm32 has good ADCs.

It probably isn't even a transistor, as the PN base-emitter junction would show a stable voltage even if there is only a little current. The rather random voltages probably come from within stm32 itself (possibly capacitively coupled), it shows the same symptom of random voltages if I simply disconnect the sensor pin.
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: fake lm35dz temperature sensors

Post by ag123 »

Found some interesting articles
https://www.allaboutcircuits.com/techni ... ermometer/
https://www.ti.com/lit/pdf/sboa277
https://www.arrow.com/en/research-and-e ... ure-sensor

So that means one can simply use the cheap 1n4148 diode or a BJT transistor and call it a 'thermistor'.
Someone has done just that
https://www.youtube.com/watch?v=SEhWycnITKc
https://www.hackster.io/microst/thermom ... sed-524613

To make life simpler, an 'expensive' part may be needed - a constant current source
https://www.ti.com/product/LM134
https://www.st.com/en/mems-and-sensors/lm234.html
what is a little interesting is that the constant current sources can be 'abused' as temperature sensors

The hard part is amplification (takes an op amp or transistor) and the first 'accurate' benchmark piece to calibrate all the rest.
For those in a hurry, it is possibly better to get those pre-calibrated ones, thermistors etc.
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: fake lm35dz temperature sensors

Post by ag123 »

Apparently, as I searched further, more examples of using a diode or transistor as a temperature sensor are found
https://www.analog.com/media/en/technic ... an137f.pdf
https://www.ti.com/lit/sboa173
https://www.onsemi.com/pub/collateral/and8494-d.pdf

All of them are derived from the Shockley diode equation in one way or another
https://en.wikipedia.org/wiki/Shockley_diode_equation

Lots of interesting stuff
https://2n3904blog.com/1n4148-diode-for ... i-v-curve/
https://hackaday.com/2018/04/16/two-cen ... e-sensors/
the hard part as always is calibration, pretty much 'fitting' the Shockley equation. No 2 'analog' devices works identically
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: fake lm35dz temperature sensors

Post by ag123 »

OK, here is an update with a genuine LMT86 part from TI
https://www.ti.com/product/LMT86
https://www.ti.com/lit/gpn/lmt86

Temperatures aren't the most stable, but it looks much better, sample interval is about 1 sec between prints
pa0:2200, 1772.46mV, 30.42 deg C
pa0:2194, 1767.63mV, 30.86 deg C
pa0:2199, 1771.66mV, 30.49 deg C
pa0:2198, 1770.85mV, 30.56 deg C
pa0:2197, 1770.04mV, 30.64 deg C
pa0:2193, 1766.82mV, 30.93 deg C
pa0:2197, 1770.04mV, 30.64 deg C
pa0:2196, 1769.24mV, 30.71 deg C
pa0:2196, 1769.24mV, 30.71 deg C
pa0:2195, 1768.43mV, 30.78 deg C

code for the sketch (libmaple f4)

Code: Select all

#include <Arduino.h>
#include <math.h>

void sleep(uint16_t msecs);

void setup() {
	Serial.begin();
	pinMode(LED_BUILTIN, OUTPUT);

	//adc clk max 36mhz, using 84/4 ~ 21mhz
	adc_set_prescaler(ADC_PRE_PCLK2_DIV_4);
	adc_set_sampling_time(ADC1, adc_smp_rate::ADC_SMPR_84);
	pinMode(PA0, INPUT_ANALOG);

}

float f(float t, float v) {
	return 1777.3F - (10.888*(t-30)) - 0.00347*(t-30.0F)*(t-30.0F) - v;
}

float df(float t) {
	return -10.888*t - 0.00347*2*(t-30.0F);
}

float nstep(float t, float v) {
	return t - f(t,v) / df(t);
}

float newton(float v) {
    float t0 = 30.0F;
    float t;
    uint16_t n = 0;
    while(true) {
        t = nstep(t0, v);
        n++;
        if(fabs(t-t0) < 0.001)
            break;
        t0 = t;
    }
//    Serial.print("loop ");
//    Serial.println(n);
    return t;
}

void loop() {
	togglePin(LED_BUILTIN);
	Serial.print("pa0:");
	uint16_t val = analogRead(PA0);
	Serial.print(val);
	Serial.print(", ");
	float mv = 3.3 * (float) val * 1000.0 / 4096.0;
	Serial.print(mv);
	Serial.print("mV, ");
	Serial.print(newton(mv));
	Serial.println(" deg C");
	sleep(2000);
}

void sleep(uint16_t msecs) {
	for(uint16_t i=0; i<=msecs; i++)
		asm("wfi");
}
That 4 functions in there is newton's method to solve the quadratic equation given in the
specs
https://www.ti.com/lit/gpn/lmt86
It takes about a hundred newton iterations average in single precision floating point to converge to 0.001 C precision.
It is pretty fast on stm32f401 84 MHz, there is hardly any delay waiting for a converged figure.
But accordingly Newton's method may not converge at times, for now it seems stable and converges for a last half hour of run.
The FPU in stm32f401 is perfect for such, it saves encoding a big table. This kind of iterative stuff used to be done on bigger computers, it is cool that microcontrollers are fast enough for all these and in real time.

edit:
there is a strange feeling the variations may be due to 'electrical noise' from elsewhere, interference etc. even a few millivolts variations varies the deg C figures below the decimal point. But otherwise, it is pretty close to spec, about +/- 1 deg C
snazzed up with an oled display
temp sensor
temp sensor
temp_sensor_oled.jpg (64 KiB) Viewed 4521 times
Post Reply

Return to “Off topic”