Leonardo and LM60

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=107
I 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.

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?

A quote from the datasheet (http://www.ti.com/lit/ds/symlink/lm60.pdf):

The nominal output voltage of the LM60/LM60-Q1 ranges from +174 mV to +1205 mV for a ?40 °C to +125 °C temperature range

So, no, -40°C is probably a value of 28 and +125°C is about 246 if your sensor perfectly calibrated and your power supply delivers perfect 5V. Both conditions are probably not set.

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.

Are these values already the averages you calculate or single readings?

Thank you for taking the time to reply.

Are these values already the averages you calculate or single readings?

The 125 and the 164 are already the averages of the 20 reads.

So I am not sure I understand, where does -40'C relate to a reading of about 28?

Thanks again.

So I am not sure I understand, where does -40'C relate to a reading of about 28?

According to the datasheet -40°C produces an output voltage of 174mV which translated to a reading of 28 on a 5V Arduino.

I have no explanation for the higher second reading. It's even the same ADC (Analog Digital Converter) in the Arduino doing the conversion, the six analog ins are just multiplexed. How do you power your setup?
You noticed that in your posted sketch you don't print the average value but the last reading?

How do you power your setup?

Via a USB cable connected directly to the computer. Then from 5v on the Arduino to the red +ve rail on the breadboard also the Gnd from the arduino to the -ve on the breadboard.

You noticed that in your posted sketch you don't print the average value but the last reading?

I thought I did. In the getVolts routing I do a

Serial.print("Input Value: ") ; Serial.print(inputValue);
Serial.print(" | Voltage: ") ; Serial.print(volts);

each time the routing is called. While debugging I did print each read and then printed the lines in the above code.

When the getTemp() routing is called I also print the value after my calculation.

Serial.print(" | Temperature: "); Serial.print(temp); Serial.println(" 'C");

In the loop() routine I simply print value from (sensor connected to A1 + sensor connected to A2) divided by 2.

What is puzzling is the metered reading from the 2 sensors is the same (620mV) but the reading from the ADC is so different.

Thanks again

Can you take a picture of your hardware setup? Maybe we find something there, although the probability is not so high.
And please try reading the values the other way around (A2 first, then A1), just an idea.

Well ... I must apologize for wasting your time. When you asked me to take a photo I cleaned up my board. I had 4x 595 shift registers with 32 leds and resistors etc sweeping like knight rider ..

On the one side of the board I had 1 sensor and on the other side I had placed the 2nd sensor. When I cleaned up the board and placed the sensors next to each other with nothing else on the board but the LM60s and the respective wires I got the readings I expected.

Not sure why this is the case but there you have it. In a project where I would mount the sensors permanently I wouldn't have all the other confusion with the other components.

Thank you so much for your assistance.