Hi everybody and thanks a lot.
@Mark: Yes! This could be part of the problem... the main part. I'm going to try with a different ground for led and sensor.
@Mike: I put no resistor in line with led. I'll try this solution also.
I put the code I'm using for a better knowledge. One important thing - I suppose - is that I'm using an Apple MacBook Pro, connecting Arduino duemilanove board via USB port.
I think that my voltage is not 5V... but something similar to 4.8V.
In fact if I put in my sketch analogValue = (5000*(analogValue/1024.0))/10-273; the resulting temperature is completely wrong (about 45° celsius... man, here in Rome is warm... but not so much!). So I tryed to change the value in 4800, as you can find in the code below. And now the value is correct (23° celsius). But this solutions seams to me a little bit... redneck way.
Mark, how can I know exactly the Voltage that goes out from my USB?
Thanks again!
Zongo
int sensorPin = 0;
# define LED1 7
void setup() {
Serial.begin(9600);
pinMode (LED1, OUTPUT);
}
void loop() {
//write the temperatre to serial
//Centigrade
Serial.print("Centigrade: ");
Serial.println(getCentigrade(sensorPin),DEC);
Serial.println();
//Fahrenheit
Serial.print("Fahrenheit: ");
Serial.print(getFahrenheit(sensorPin),DEC);
Serial.println();
//Kelvin
Serial.print("Kelvin: ");
Serial.println(getKelvin(sensorPin),DEC);
Serial.println();
//wait 1000ms (1sec) before next read
delay(2000);
}
int getCentigrade(int analogPin) {
unsigned int analogValue = analogRead(analogPin);
analogValue = (4800*(analogValue/1024.0))/10-273; //convert to degrees C
return analogValue;
}