Having Issues Getting Reading Off Ratiometric Temperature Sensor (AD22100)

I’m having trouble getting a simple reading off of a radiometric temperature sensor. It is the Analog Devices AD22100. Datasheet link is here - http://www.analog.com/media/en/technical-documentation/data-sheets/AD22100.pdf

The trouble seems to have to do with my code. The sensor seems to be functioning and the wiring is done correctly. I think the issue code stems from either the syntax or the way I handle the transfer function listed on page 6 of the AD22100 datasheet. The transfer function they give is as follows:

VOut = (V+/5 V) × [1.375 V +(22.5 mV/°C) × TA]

I wrote up this little bit of code to read the temp off the serial monitor. But I’m getting values of about 77 degree fahrenheit (25 celsisus) in a room that is not even close to that warm. More like the 60s with the window open.

Let me know if I did anything wrong in relation to the transfer function part or syntax?

Would be greatly appreciated.

int temperature_sensor = A0;
int analog_reading;
float get_temperature;
float result;

void setup(void) {
 
  Serial.begin(9600);
  Serial.println();
     
}


void loop(void) {
  analog_reading = analogRead(temperature_sensor);      // Read the value from the sensor pin
  result = analog_reading / 1024.0 * 5.0;              // Map the 10-bit (1024 levels) quantized sensor reading to its voltage value (between 0v to 5v)
  result = (result - 1.375) / 0.0225;                 // Obtain the temperature in Celsius
  Serial.print(result);
  Serial.println();
   
  delay(100);
}

P.S. Poached some of the code from this helpful webpage that turned up in a Google search.

http://webcache.googleusercontent.com/search?q=cache:ozAHh_KTGDIJ:www.ianloke.com/+&cd=15&hl=en&ct=clnk&gl=us

moderator: removed some —

What a strange temperature sensor that is. It is not even accurate. If you would use a DS18B20, you don't have all those analog troubles.

The output voltage depends on the 5V ?
If you power the Arduino via the usb connector, the 5V could vary for example between 4.5 and 5.0V.
The 3.3V pin is more stable, but the AD22100 must have at least 4.0V.

You have to know the actual voltage of the 5V pin.
That is not easy. If you have an Arduino Uno, the ATmega328P microcontroller can measure its own VCC, but that depends on the internal voltage reference of the ATmega328P. If you use that, the resulting temperature would also depend on the internal voltage reference. That would make it more or less useless.

Perhaps if you power the Arduino with an external power supply of at least 7.5V, then the 5V pin is more stable (it actual voltage depends on the voltage regulator).

My conclusion: get rid of that sensor. It's output depends on the actual voltage of the 5V pin, and that 5V voltage depends on other things, so any accuracy is not possible.

I might miss something here. The Arduino uses the 5V as voltage reference by default. Perhaps that would eliminate the changes in the 5V for the sensor. I'm not sure if that would change the calculation.

A trick needed for this sensor seems to be (from datasheet p.1.)
This is accomplished by using the ADC’s +5 V power supply as a reference to both the ADC and the AD22100 eliminating the need for and cost of a precision reference (see Figure 2).

so you must use analogReference(EXTERNAL) so both the ADC and the sensor use the same reference voltage. and of course wire it accordingly

TIP: using CTRL-T in the IDE does auto format the code

The term is "ratiometric," not "radiometric." Look it up. It's a good thing.

You do NOT have to know the reference voltage (provided, as Mr T says, you drive the sensor and the ADC with the same voltage). FWIW, wheatstone bridges can be used as ratiometric devices, too.

Typical error between 0 deg C and 25 deg C is less than 0.5 deg C. That's not bad, and it doesn't require 750 ms to take a reading nor a bunch of code like the DS18B20.

Just this (to get deg F):

tF=0.39101*analogRead(pinTmpF)-78.0

Oops: I see you got the spelling right in the title, but not your post.

Hey koepel, robtillaart, and dave. Thanks for the quick responses!

I think I made a mistake about my temperature estimate in the room. It has actually been quite warm here on the east coast USA due to El Nino.

While it's true that the temp outside is about 21 celsius (70 Fahrenheit) during the day and my window is open, the central corridor heat in my building is still on, and I think the room actually does get up to 27 celsius (80 Fahrenheit). Ambient central heat from the hallway seeps into my apartment. I confirmed this with a thermometer today. So blame this El Nino weather for causing this doubt. I must have just gotten used to the heat and think it's "room temperature" in my head. It's actually quite hot in here.

Nevertheless, I'm going to check out that DS18B20 that koepel suggested. Just ordered on Digikey, along with some other popular temp sensors. (LM35 and TMP36) That voltage spec seems like a serious flaw.

I'm also going to try out the so analogReference(EXTERNAL) code recommendation from robtillaart, and see what empirical results I get.

The LM35 and TMP36 are analog temperature sensor that do need a good voltage reference. Most start using those, but then move to the digital DS18B20.
The DS18B20 needs libraries. Use the Library Manager in the Arduino IDE to install OneWire and DallasTemperature. The OneWire has already examples for the DS18B20, but the DallasTemperature makes it easier to use.

That's not all. I also use the forward voltage of a diode (1N4148) to get the temperature at about 2 degrees accuracy. If you have an Arduino Uno, the ATmega328P has a temperature sensor inside. That is like the "cpu temperature" of a computer, and not very useful to measure the ambient temperature.

potomac:
That voltage spec seems like a serious flaw.

What do you mean?