Help with Arduino Temp analog

Hi,

I just started with programming with the Arduino and I'm building a temperature sensor (analog 3 pin sensor) but I can't get the correct C/F value. I think that my wiring sucks. I tried a lot of things but I'm still stuck thats why i opened a topic on the Arduino forum.

So my wiring is the same as:

Pictures:

The code:

int inputPin = 0;
 
void setup()
{
  Serial.begin(9600);
}
 
void loop()
{
  int value = analogRead(inputPin);
  float millivolts = (value / 1024.0) * 5000;
  float celsius = millivolts / 10; 
  float fahrenheit = (celsius * 9)/ 5 + 32;
 
  Serial.print( celsius );
  Serial.println(" degrees Celsius");
  
    Serial.print(  fahrenheit );
  Serial.println(" degrees Fahrenheit");
 
  delay(1000); // wait 10 seconds 
}

Output: (Can't be correct)

179.66 degrees Fahrenheit
83.01 degrees Celsius
181.41 degrees Fahrenheit
82.52 degrees Celsius
180.54 degrees Fahrenheit
83.01 degrees Celsius
181.41 degrees Fahrenheit
83.01 degrees Celsius
181.41 degrees Fahrenheit

Any help would be appreciated!

Add Serial.println(value) in there. I want to see the raw count value you're getting from the ADC.

Hi,

Thanks for the answer the output is:

83.50 degrees Celsius
182.29 degrees Fahrenheit
171
83.98 degrees Celsius
183.17 degrees Fahrenheit
172
83.98 degrees Celsius
183.17 degrees Fahrenheit
172
83.98 degrees Celsius
183.17 degrees Fahrenheit
172
83.98 degrees Celsius
183.17 degrees Fahrenheit
172
83.98 degrees Celsius
183.17 degrees Fahrenheit
172
83.50 degrees Celsius
182.29 degrees Fahrenheit
171

That's weird. When I hooked my LM35 I was reading a raw count of around 45-55 at room temperature. Are you sure you have an LM35?

So i tried another code and ended up with:

int sensorPin = 0;
void setup()
{
  Serial.begin(9600); 
}
 
void loop()                   
{
 int reading = analogRead(sensorPin);  
 
 float voltage = reading * 5.0;
 voltage /= 1024.0; 
 
 Serial.print(voltage); Serial.println(" volts");
 
 float temperatureC = (voltage - 0.5) * 100 ;  
 Serial.print(temperatureC); Serial.println(" degrees C");
 
 float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
 Serial.print(temperatureF); Serial.println(" degrees F");
 
 delay(1000);                                  
}

Output:

32.52 degrees C
90.54 degrees F
0.83 volts
32.52 degrees C
90.54 degrees F
0.82 volts
31.54 degrees C
88.78 degrees F
0.82 volts
32.03 degrees C
89.66 degrees F
0.82 volts
32.03 degrees C
89.66 degrees F
0.82 volts
32.03 degrees C

Still not sure if thats the temp around me or just the temp of the sensor

I'll ask again: are you sure you have an LM35 there? Maybe you have one that's 10mV per F, not 10mV per C. The values you're getting just don't make sense, and are way too hot.

Carefully touch the sensor while it's running. Is it very hot, or at a moderate, room temperature? Do the values you read go up while you are touching it?

Have you thought about using the DS one wire sensors. I started my project with what you are using and found the readings where not accurate enough. Depending on your project. the DS18B20 is a digital device which is very easy to use and you can have a number of them on one 3 core cable.

check out this link

http://bildr.org/2011/07/ds18b20-arduino/

Jiggy-Ninja:
I'll ask again: are you sure you have an LM35 there? Maybe you have one that's 10mV per F, not 10mV per C. The values you're getting just don't make sense, and are way too hot.

Carefully touch the sensor while it's running. Is it very hot, or at a moderate, room temperature? Do the values you read go up while you are touching it?

Hey,

I'm not sure cause there is nothing writted up but i'll ask. When i touch the sensor the values go up. Its not very hot though

I did a test again:

tempemp: 24C
temp: 24C
temp: 24C
temp: 24C
PLACED MY FINGER ON IT:
temp: 25C
temp: 26C
temp: 27C
temp: 27C
temp: 28C
temp: 28C
temp: 28C
temp: 29C
temp: 29C
temp: 29C
temp: 29C
temp: 29C
temp: 29C
temp: 29C
temp: 29C
temp: 28C
temp: 28C
temp: 28C

code:

int sensorPin = 0;

void setup()
{
  Serial.begin(9600); 
}
 
void loop()                   
{
 int reading = analogRead(sensorPin);  
 
 float voltage = reading * 5.0;
 voltage /= 1024.0; 
 
// Serial.print(voltage); Serial.println(" volts");
 int temperatureC = (voltage - 0.5) * 100;  
  Serial.print("temp: ");

 Serial.print(temperatureC);  
 Serial.print("C");


 
// float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
// Serial.print(temperatureF); Serial.println(" degrees F");
 
 delay(1000);                                  
}

vermithrax:
Hey,

I'm not sure cause there is nothing writted up but i'll ask. When i touch the sensor the values go up. Its not very hot though

What is written on the flat part of the sensor? Mine, for example, has

03AE
LM35
DZ

written on it. What does yours say?