Having Issues Getting Reading Off Ratiometric Temperature Sensor (AD22100) - Page 1
Forum section: electronics / beginners

author: Potomac
author_rank: Regular Contributor
timestamp: December 24, 2015, 08:19:15 am
content: I'm having trouble getting a simple reading off of a radiometric temperature sensor. It is the Analog Devices AD22100. Datasheet link isHEREThe 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 pinresult = 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 CelsiusSerial.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=ushttps://github.com/ianlokejj

author: AndyC_772
author_rank: Super Contributor
timestamp: December 24, 2015, 10:00:54 am
content: With any problem like this, the way to diagnose it is to be systematic. Find out at which point an error first occurs, then fix that. Repeat until no errors remain.In this case, the sequence would be something like:- measure the actual temperature of the sensor, using a separate, known good thermometer- work out the expected output voltage- measure the actual output voltage and compare it to the expected value- work out what value you'd expect to see from the ADC for that voltage- compare to the actual value you see from the ADCIf the value from the ADC is correct, then it must be a simple arithmetic error. If not, you have a hardware problem.

author: alsetalokin4017
author_rank: Super Contributor
timestamp: December 24, 2015, 11:20:59 am
content: Yes, the Data Sheet (Page 1) shows a 1k resistor in series and a 0.1 uF decoupling cap on the output leg to the ADC. Try putting these components in first, then see what you get.(Your link to the data sheet is malformed by the way.)http://www.analog.com/media/en/technical-documentation/data-sheets/AD22100.pdfAs far as I can tell you have implemented the transfer function correctly in your code (neglecting the supply voltage scaling factor.)TA= (Vout- 1.375V)/(22.5 mV/degC)But wait... your mapping may not be correct. The data sheet says"The output swings from 0.25 V at ?50°C to +4.75 V at +150°C using a single +5.0 V supply."So you may need to adjust the 5.0 value in this line of your code:result = analog_reading / 1024.0 * 5.0;It might be simpler if you use the arduino map() statement to convert your 1024 count ADC value to a voltage.Something likeint Iresult=0;Iresult = map(analogRead(A0),0,1023,250,4750); // since map() only does integer mathresult = Iresult/1000.0; //convert to float here

author: Potomac
author_rank: Regular Contributor
timestamp: December 26, 2015, 11:03:09 am
content: Hey andy, blueskull, and alsetalokin. 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.Nevertheless, I did add that 1k resistor and 0.1 uF capacitor that alsetalokin4017 pointed out from the data sheet.I'm also going to check out the code recommendation that alsetalokin suggested, just to see what results I get. Will report back.Quote