0

I want to measure atmospheric temperature with an Arduino. The sensor I am using is an LMT84.

After uploading the following code to the Arduino board I am getting very high temperatures in the serial window.

I am unable to understand what the error in my code is. I've connected a 0.1 μF cap between Vcc and ground, and the data pin is connected to A1 on the Arduino.

Please check the following code:

const int sensor = A1; // assigning analog pin A1 to variable 'sensor'
float tempc;  // variable to store temperature in degree Celsius
float vout;   // temporary variable to hold sensor reading
float vout1;  // temporary variable to hold sensor reading

void setup()
{
  Serial.begin(9600);
  pinMode(sensor, INPUT); // configuring pin A1 as input
}

void loop()
{
  vout = analogRead(sensor);
  vout1 = (vout * 500) / 1023;
  tempc = vout1; // storing value in degrees Celsius
  Serial.print("LMT84 temp=");
  Serial.print(tempc);
  Serial.println();

  delay(1000);
}

The serial window shows these values:

LMT84 temp=168.13
LMT84 temp=168.13
LMT84 temp=168.64
LMT84 temp=168.89
LMT84 temp=168.13

1 Answer 1

2

The Arduino uses an analog voltage as reference. It is default set to the Vcc of the microcontroller, which is about 5 V for an Arduino Uno. The function analogReference can be used to set something else as reference.

When that reference is not precisely 5.0 V, it is impossible to measure a voltage in a accurate way. It is almost never precisely 5.0 V. When using the USB connector to power the Arduino board, it might be somewhere between 4.5 and 5.0 V.

The Arduino Uno has an internal voltage reference of 1.1 V. That is better than using the default 5 V. The actual voltage can be 1.0 to 1.2 V, you have to put the actual value in your sketch.

The LMT84 has an output of 1034 mV at 0°C and 476 mV at 100°C. That means your calculation is not correct. In the datasheet are two ways to calculate the temperature, an accurate formula and a simple calculation.

You can avoid all these problems with a temperature sensor that has a digital interface to the Arduino board. For example the DS18B20. That is a cheap and accurate temperature sensor.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.