Hi, Thanks to
http://arduino.cc/forum/index.php/topic,132302.0.html and
http://www.dave-auld.net/index.php?option=com_content&view=article&id=89:arduino-analogue-in-temperature&catid=53:arduino-input-output-basics&Itemid=107I have managed to get readings much closer to what I expect, however I am still experiencing some challenges ... mostly with my understanding I think (Disclaimer: I am a RANK noob)
This is my situation so far.
Arduino Leonardo connected 5v and Gnd to breadboard. LM60 connected middle pin to A1. Actually I have 2 LM60s the second sensors middle pin is connected to A2 while the other pins are correctly connected to the 5v and Gnd rails. I know they are correct because the get flippin HOT if they are the wrong way around)
I have the following code below:
void setup() {
Serial.begin(9600);
}
float getVolts(int pinIn) {
int inputValue = 0;
int bigT = 0, smallT = 0;
for (int i = 0; i < 20; i++) {
inputValue = analogRead(pinIn);
bigT += inputValue;
delay(1);
}
smallT = bigT / 20;
float volts;
volts = (((float)smallT / 1024) * 5000);
Serial.print("Input Value: ") ; Serial.print(inputValue);
Serial.print(" | Voltage: ") ; Serial.print(volts);
return volts;
}
float getTemp(float volts) {
float temp = (volts - 424) / 6.25;
Serial.print(" | Temperature: "); Serial.print(temp); Serial.println(" 'C");
return temp;
}
void loop() {
//Get Temp from both sensors
float temp1 = getTemp(getVolts(A1));
float temp2 = getTemp(getVolts(A2));
Serial.println();
Serial.print("Temp: "); Serial.println((temp1 + temp2) / 2);
Serial.println();
delay(1000);
}
Basically I read each sensor 20 times to get a more consistent reading and then work out the mV (I think that is what I am doing); I am wanting an average temperature so I take the readings from both sensors and divide by 2 (simple enough).
What I see on pin A1 is an input of 125 and on pinA2 164. It is about 30 'C in my office at the moment. I think my calculation is pretty close if not correct however what I really want to find out is the following:
- Am I correct in assuming that the 125 on pin A1 is actually a 10bit value (int). So for the LM60 sensor a value of 0 would equate to -40 'C and a value of 1023 would equate to +125 'C?
- When I use my multimeter to measure the mV between Gnd and the middle pin I get a pretty constant 620 (which looking at the LM60 datasheet would be the value I expect to correlate to the temperature in my office) - however, here's the thing with my multimeter I get a reading of 620 from both sensors, so how come the inputValue on the second sensor is around the 164 mark ... I would expect it to be 125 the same as the first sensor ... they are on the same breadboard after all.
Thank you for your assistance - I must say I am loving this new experience.