Jump to content
Electronics-Lab.com Community

LM335 showing incorrect value?


Recommended Posts

Hey there,

I've been making an el-cheapo room thermometer myself, and stumbled into a problem: the LM335Z I bought is showing up temperature which is not even the room temperature.

Here's the rough schematic:
V-  ------------------------| GND
V+ ---(1)--/\/\/\/\-------------| +5V
2k resistor (2x 1k resistors in series)
ADJ ---- (floating)

(1) - Connected to voltmeter

Unfortunately it gives me 3.14V instead of anything around 2.99V. Even tried another LM335Z, but still giving the same thing. Btw, the LM335Z converts 1K to 10mV.

Any ideas?  ???  ::)

Link to comment
Share on other sites


I can't read your rough ASCII schematic, please post a clear drawing in either.GIF or .PNG format, avoid .JPG which can be fuzzy.

Look at the datasheet for more information on how to use the LM335.

Use ≤1% tolerance resistors - 5% won't be accurate enough.

http://www.national.com/ds/LM/LM135.pdf

Link to comment
Share on other sites

A quick look at the datasheet tells me that the voltage shouldn't vary much as the current changes so the resistor value won't make any difference - I was wrong earlier.

Does the voltage increase when the temperature sensor is warmed?

Have you had your multimeter and thermometer calibrated recently?

If not then how do you know it isn't your multimeter that's out or if your thermometer's reading is wrong?

I would suspect the multimeter is wrong, an output voltage of 3.14V would indicate a temperature if 40

Link to comment
Share on other sites


What is your room temperature?

You still haven't said.

How did you measure it? There's no point in calibrating it unless you accurately measure the temperature of your room.


Oh it's around 26 degrees. I've checked it using my old alcohol-based room thermometer.

I've tested it with the thing dunked into a small ice-bucket and the voltmeter showed up 2.99V, not even 2.73V as stated in the datasheet.

Edit: Ok, dunked it in the ice bucket again, this time showing a 2.80V which is 0.07V a little bit more.

I ripped it out from the ice bucket and put it back into the circuit and let it warm up back to the room temperature for a while, this time showing 3.01-3.03V constantly, but it's a bit jittery and could jump and fluctuate to 3.14V.
Link to comment
Share on other sites


How well water proofed is the sensor?

Could it be that moisture is getting in?


I changed to another voltmeter - this time it shows 3.03V and no more fluctuations which almost tally with my room thermometer. However, I still need to double check the sensor with the ice-bath.

In the meantime, my ADC inside the microcontroller showing weird results, guess I have to fix the routine in the system. :D
Link to comment
Share on other sites


Good, you found out what the problem was. It's just really back luck that both your DVM and ADC are wrong.


Yes - I've now got that voltmeter replaced. The DVM is broken, I bought it in 2007 and it's only $13 which was bought from Jusco.

Now, the another new problem is, it's the ADC in my microcontroller.

From the DVM, I measured : 3.01V

and from the ADC, checking the contents of the ADRESH in the debug (left-justified) which is : A8H or 16810 when I connected the wire from the sensor to the AD pin.

It is supposed to be 15510 or 9BH in the ADRESH.

I've double-checked the conversion time, and even the oscillator speed inside.

Here's the code, I might have missed one tiny thing there or something else:

#pragma config OSC = HS
#pragma config PWRT = OFF, BOR = OFF
#pragma config WDT = OFF
#pragma config DEBUG = OFF, LVP = OFF, MCLRE = OFF
#include <P18F4221.h>

//void TX_ISR(void);
void Send_TX(unsigned char);

/*#pragma interrupt chk_isr
void chk_isr(void)
{
	if (PIR1bits.TXIF == 1)
	TX_ISR();
}

#pragma code HiPrioInt = 0x0008
void HiPrioInt(void)
{
	_asm
	GOTO chk_isr
	_endasm
}
#pragma code*/

unsigned char hundreds, tens, ones, value,temp;

void main(void)
{
	TRISB = 0x0;
	PORTB = 0x0;

	TRISAbits.TRISA0 = 1;
	TRISAbits.TRISA1 = 1;
	TRISCbits.TRISC6 = 0;

	TXSTA = 0x20;
	SPBRG = 15;
	RCSTAbits.SPEN = 1;
	TXSTAbits.TXEN = 1;

	//PIE1bits.TXIE = 1;

	ADCON0 = 0b00000101;
	ADCON1 = 0b00001001;
	ADCON2 = 0b00101101;

	INTCONbits.PEIE = 1;
	INTCONbits.GIE = 1;

// 	test for digits to be sent to computer thru serial port
//	hundreds = 'A'; 
//	tens = 'B';
//	ones = 'C';
//  y = 0.51x + 140

	while (1)
	{
		ADCON0bits.GO = 1;
		while (ADCON0bits.DONE == 1);
		// Raw ADC results
	//	hundreds = (ADRESH / 100) + 0x30;
	//	tens = ((ADRESH % 100) / 10) + 0x30;
	//	ones = ((ADRESH % 10) % 10) + 0x30;
	//	Send_TX(hundreds);
	//	Send_TX(tens);
	//	Send_TX(ones);
	//	Send_TX(0x0D);

		// Converted ADC results
	/*	temp = ADRESH;
		value = (temp - 140) / 0.51;
		tens = (value / 10) + 0x30;
		ones = (value % 10) + 0x30;
		Send_TX(tens);
		Send_TX(ones);
		Send_TX(0x0D);*/
	}
}

/*void TX_ISR(void)
{
	TXREG = temp;
	PIR1bits.TXIF = 0;
}*/

void Send_TX(unsigned char input)
{
	while(PIR1bits.TXIF==0);
	TXREG = input;
}

Link to comment
Share on other sites


I don't know much about MCUs, especially C so I can't help you with the coding.

I don't it's a coding problem, it's more likely to be a hardware problem.

Where does the ADC get its reference from?

I'd recommend checking that before anything else.


Oh I see - well according to the microcontroller, I've set the reference voltage as the supply voltage, hence the 5V on it.

I'm going to check whether is the microcontroller is faulty or not. I'll hook that sensor up to another microcontroller and see whether the values show up correctly or not. :D
Link to comment
Share on other sites

I had a feeling you'd done that.

Have you measured the power supply voltage?

Bear in mind that most regulator ICs such as the LM7805 have a poor voltage tolerance and will vary by 1% or so depending on the ambient temperature and load current.

If the supply voltage is too low, the ADC will read a slightly higher voltage than what you would expect. I wouldn't be surprised if it's in the region of 4.8V.

You should use a real precision voltage reference with a close tolerance preferably ≤0.25%.

Link to comment
Share on other sites


I had a feeling you'd done that.

Have you measured the power supply voltage?

Bear in mind that most regulator ICs such as the LM7805 have a poor voltage tolerance and will vary by 1% or so depending on the ambient temperature and load current.

If the supply voltage is too low, the ADC will read a slightly higher voltage than what you would expect. I wouldn't be surprised if it's in the region of 4.8V.

You should use a real precision voltage reference with a close tolerance preferably ≤0.25%.


I finally found out the problem - the Vref is isn't really 5V, and that's why it affects and deviates the ADC's results severely.

I dunked that sensor one more last time into an ice bucket and it's really 2.73V, without no doubts.

I even checked my workshop's digital thermometer in my work, which the temperature feels similar to my home - yes, and the room temperature is around 28 degrees too.

And all I ever found out now is the Vref isn't 5V. It's hovering around 4.64V, and not even my 78L05 is even exactly 5V!

In the end, I changed and tweaked a bit of the algorithm in the microprocessor since I have to make do with these components. Perhaps later, I'll buy a better voltage regulator to replace my 78L05 which only costs a few cents in my place.

Anyway thanks for the guidances! I learned a lot of ADC operations from doing this home-made experiment! :D
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
  • Create New...