Diffrent arduinos read diffrent values from sensor (TMP36)

Hello. I have a program that reads temperature from a TMP36 temperature sensor. The problem is I have tried 3 diffrent arduinos and they all read diffrent temperature. One of the arduinos is an Arduino Uno R3 from arduino.org and the other two are chinease copies of Uno R3. The .org Uno R3 reads the most legit temperature (26°C), the second reads 16°C and the third reads 9°C. All in the same room with the same sensor.

Could it be a quality issue with the copies?
If so, can I somehow calibrate it or compensate for the margin of error so I get true results?

Here is my code if that helps

int tempPin = A5;

void setup() {
  
  Serial.begin(9600);
  pinMode(tempPin,INPUT);

}

void loop() {
  int tempSensorVal = analogRead(tempPin);
  float voltage = (tempSensorVal / 1024.0) * 5.0;
  float temperature = (voltage - .5) * 100;
  Serial.println(temperature);

}

Thanks in advance

How much difference between readings?

Try taking a few reading and averaging them.

Weedpharma

weedpharma:
How much difference between readings?

Try taking a few reading and averaging them.

Weedpharma

Okay I have taken some avrage readings now, the .org Uno reads for avrage 153, one copy reads an avrage of 144 and the other copy reads 147

153 = 0.7470703125 V = 24.70703125 °C
144 = 0.703125 V = 20.3125 °C
147 = 0.7177734375 V = 21.77734375 °C

The calculations assume that your AREF voltage is 5.0V. Have you tried measuring it at the AREF pin?

johnwasser:
153 = 0.7470703125 V = 24.70703125 °C
144 = 0.703125 V = 20.3125 °C
147 = 0.7177734375 V = 21.77734375 °C

The calculations assume that your AREF voltage is 5.0V. Have you tried measuring it at the AREF pin?

Sorry but I have no idea what measuring with the AREF pin means?

Another problem I have found is, I have a button connected to the arduino too, and when I press it the value from the TMP36 increases? The button and the sensor is not connected to eachother in any way except they are connected to the same arduino.
For example, if normal value from the sensor is 139, it's 142 when pressing the button.

Edit, the button problem was solved by using an external power suply (9V battery to VIN and GND).

accelgronvall:
Sorry but I have no idea what measuring with the AREF pin means?

Connect a good DC voltmeter between a GND pin and the pin marked AREF (next to the GND pin next to Pin 13). If the voltage there is not exactly 5.0V you will get wrong answers when your sketch assumes the value is 5.0V.

AREF is the reference voltage used by the analogue to digital converter. If it is different on each board, the result will be different.

Weedpharma

johnwasser:
Connect a good DC voltmeter between a GND pin and the pin marked AREF (next to the GND pin next to Pin 13). If the voltage there is not exactly 5.0V you will get wrong answers when your sketch assumes the value is 5.0V.

weedpharma:
AREF is the reference voltage used by the analogue to digital converter. If it is different on each board, the result will be different.

Weedpharma

Aha I see, thank you guys