Hello,
I am trying to read the temperature from a Lilypad Temperature Sensor - connected to a Lilypad Arduino USB.
Unfortunately, the temperature values I get are far too high: I'm measuring approximately 60°C in a room with ~28°C !
This is how I did it.
- The Signal is connected to A3 on my board (using alligator clips)
-
- of the sensor to + on the arduino
-
- of the sensor to - on the arduino
- the arduino board is currently connected (and powered) via USB to my computer
As for the program, the temperature sensor says
This sensor will output 0.5V at 0 degrees C, 0.75V at 25 C, and 10mV per degree C
or more precisely from the datasheet:
The MCP9700/
9700A and MCP9701/9701A temperature coefficients
are scaled to provide a 1°C/bit resolution for an 8-bit
ADC with a reference voltage of 2.5V and 5V, respec-
tively.
Also, the analog value read by analogRead says that
it will map input voltages between 0 and 5 volts into integer values between 0 and 1023. This yields a resolution between readings of: 5 volts / 1024 units or, .0049 volts (4.9 mV) per unit
So, my understanding is that the conversion from the analog value to degrees Celsius should be:
degreesC = ((sensorValue * 0.00488) - 0.5) * 100;
But that's not giving good values...
Sensor value is: 224
degrees C = 59.31
What's wrong? How should I read the temperature from the sensor?
Thanks
For reference, here's the full sketch:
int sensorPin = A3;
int sensorValue;
float degreesC = 0;
void setup()
{
// Set sensorPin as an INPUT
pinMode(sensorPin, INPUT);
// on board LED
pinMode(13, OUTPUT);
// Initialize Serial, set the baud rate to 9600 bps.
Serial.begin(9600);
}
void loop()
{
// I just want the LED to blink to be sure something is happening
digitalWrite(13, HIGH);
// voltages between 0 and 5V are mapped to 0-1023
sensorValue = analogRead(sensorPin);
Serial.print("Sensor value is:");
Serial.println(sensorValue);
degreesC = ((sensorValue * 0.00488) - 0.5) * 100;
Serial.print("degrees C = ");
Serial.println(degreesC);
// I just want the LED to blink to be sure something is happening
delay(500);
digitalWrite(13, LOW);
}