Problems in reading temperature using the LM335 and arduino Mega

I wanted to try out this program where i can use the LM335 to measure the temperature. Now, this is what happens, when i run my program, the temperature reading is around 23 degree centigrade but strangely if i touch any hot object to the LM335 sensor, the temperature drops. What could be the issue?

I have followed the following circuit diagram;-

int outputPin= 0;
void setup()

//main loop
void loop()
float rawvoltage= analogRead(outputPin);

float reading = (rawvoltage*5000)/1024;
float centigrade = (reading - 500)/100;
Serial.println(“Centigrade” );


The output is as follows;-

Raw voltage:- 593.00
Reading in Millivolts:- 2895.51
Centigrade:- 23.96593.00


float rawvoltage= analogRead(outputPin);

analogRead() returns an int, not a float.

try to do your calculations like this:

int rawvoltage= analogRead(outputPin);

float reading = (rawvoltage*5000.0)/1024.0;

Thanks for your reply. I adjusted that part of my code but the problem remains the same. I tried touching the sensor and the temperature immediately drops and if i bring a burning match stick, temperature drops at a drastic rate instead of going up which is driving me crazy. What could be the issue?

What could be the issue?

Wiring, calculation, Serial output problem ? What happens to the value of rawvoltage when you heat up the sensor ?

I noticed that the raw voltage drops down from 591 to 581 to 561 drastically as i apply heat to the sensor and so does the temperature. Apparently, it should be increasing but for some reason it drops down.

can't see your circuit diagram, how do you have the sensor wired?