Weird readings for a lm335a analogue temperature sensor


I’m a complete newbie to Arduino, and coding and electronics. I’m trying to get a reading for a lm335a temperature sensor. This is the code I’ve used

float temperature = 0;
#define INTERNAL1V1
void setup()
Serial.println(“LM35 Thermometer “);
void printTenths(int value) {
// prints a value of 123 as 12.3
Serial.print(value / 10);
Serial.println(value % 10);
void loop() {
int span = 20;
int aRead = 0;
for (int i = 0; i < span; i++) {
aRead = aRead+analogRead(potPin);
aRead = aRead / 20;
temperature = ((1001.1aRead)/1024)*10;
// convert voltage to temperature
Serial.print("Analog in reading: “);
// print temperature value on serial monitor
Serial.print(” - Calculated Temp: ");

If it makes a difference I’m using a mega 2560.

The odd thing is even though I’m getting high readings (85c) when I place a finger on the sensor the temp goes down? I’ve tried several different variations on wiring and code, but this always happens. Has anyone got any idea why.

thanks again


how do u setup the reference voltage of the ADC?

where do u define potPin?
is the pin correct?
i mean: what if u disconnect the sensor and pull it up and then down?