TMP36: Why do analogRead() values differ between Uno and Yun

I've got a TMP36 with all 3 pins plugged directly into A0, A1 and A2 (where A0 is HIGH and A2 is LOW). I then perform analogRead() on A1 to get the sensor value.

When the sensor is on my Uno board, the sensor value is: 147 (equates to 21C)
When the sensor is on my Yun board, the sensor value is: 175 (equates to 35C)

Both boards are powered by a USB cable, directly from my laptop. In each case, the sensor has been left to cool down to room temperature after touching it.

The reading on the Uno board seems correct for the current temperature in the room.

Why is the analog reading on the Yun board not similar to that of the Uno board? The difference is skewing the temperature by quite a lot.

Thanks for the help.

Tom

Can you check the voltage the sensor is getting with a DMM?

photomoose:
I've got a TMP36 with all 3 pins plugged directly into A0, A1 and A2 (where A0 is HIGH and A2 is LOW). I then perform analogRead() on A1 to get the sensor value.

Do you really connect the power pins of the sensor to data pins of the Arduino?
I'd connect them to Gnd and Vcc (or 3.3V), supplied by the boards.

Why is the analog reading on the Yun board not similar to that of the Uno board? The difference is skewing the temperature by quite a lot.

See above. Also the reference voltage (Aref) of both boards may be different.

Do the readings differ when you connect an analogue voltage (potentiometer...) or the sensor output to analogue pins of both boards, at the same time?

I've managed to get my multimeter across the pins.

Uno
Sensor pin 1: 4.88V
Sensor pin 2 (output): 0.68V
Calculated voltage based on analogRead(): 0.68V (matches actual voltage)
Calculated temperature: 19.8C (correct temperature)
Voltage from 5V pin: 4.88V (matches pin 1 on sensor)

Yun
Sensor pin 1: 4.54V
Sensor pin 2 (output): 0.70V
Calculated voltage based on analogRead(): 0.77V (differs from actual voltage)
Calculated temperature: 26.6C (incorrect temperature)
Voltage from 5V pin: 4.53V (nearly matches pin 1 on sensor)

These voltages were taken using the GND pin as ground.

OK, I think I've fixed it.

  1. Plugging the sensor legs directly into A0, A1 and A2 didn't give accurate readings (I only did this for simplicity and because I read it elsewhere). I get more accurate results if I use the breadboard and connect pins 1 and 3 of the sensor to 5V and GND.

  2. Given the 5V pin actually outputs 4.54V, I had to adjust my formula for calculating the temperature. (An analog read of 1023 now represents 4.54V and not 5V). As a result, the formula for calculating the temp is now:

float GetTemperature() {
  int sensorVal = analogRead(TEMP_PIN);
  
  float tempVoltage = (sensorVal / 1024.0) * [s]5.0[/s] [b]4.54[/b];
  return (tempVoltage - 0.5) * 100;
}

Thanks for your help and replies.

Can you use 3v3 as reference voltage ? Then supply voltage variations doesn't alter readings.