 Analog input .4v up to 1.9v - How to use - SOLVED

I understand how to use analog input if it ranges from 0v up to 5v, but how do i use a sensor that gives reading of 0.4v up to 1.9v ?

I have an old outside air temp probe that gives this range of values. I have recorded voltage values from 15 deg F (1.82v) up to 110 deg F (0.476v). I would like to be able to use this input into an analog in pin, and somehow map it in order to show the temperature.

Is this a double map, or do i convert digital back to analog, or what ?

What values do you see when you simply use analogRead() ? Do you want to know the actual voltage or just to react when it goes below/above/is in a particular range of values ?

pratto:
I understand how to use analog input if it ranges from 0v up to 5v, but how do i use a sensor that gives reading of 0.4v up to 1.9v ?

I have an old outside air temp probe that gives this range of values. I have recorded voltage values from 15 deg F (1.82v) up to 110 deg F (0.476v). I would like to be able to use this input into an analog in pin, and somehow map it in order to show the temperature.

Is this a double map, or do i convert digital back to analog, or what ?

since the range is 0.4v up 1.9v, assuming you are using an arduino Uno, you could use a voltage divider circuit to half the sensor input (ie to 0.2v up 0.8v) then use the arduino internal 1.1V reference voltage to still maximise the ADC range.

code would be something like this for an Arduino Uno:

int sensorValue = 0;

void setup() {

analogReference(INTERNAL); //to use Uno 1.1v ADC internal ref

Serial.begin(115200);
}
void loop() {

Serial.println(sensorValue);

delay(1000);

}

the link posted by UKHeliBob list the various internal references available depending on the board you are using.

hope that helps

ok. thanks for the replies. I hooked the probe up to A0 on my Mega, and the ground too. I uploaded the example serial print analog input.

for room temp at about 77, it shows values in the low 180’s. stable.

when i bumped it up to 90 deg., it dropped down into the 140’s. stable.

I read the link. it seems to be showing different reference voltages (or voltage references i guess) for various boards. I am using a MEGA 2560 R3.

If I follow what is happening now, a temp of 77 shows about .84v on the multimeter. and it registers in the low 180’s in Serial print. .84v/5v = .168 .168*1023 = 172, about what Serial print shows.

If I use a 2.56v reference i should get a value of about .84v/2.56v * 1023 = 336.

Rather than use a different reference or a voltage divider, can’t I just somehow map my values directly to the temperatures i know ? I mean if 77 deg = say 182 Serial, and 90 deg = 142, isn’t there a way to map these directly ? it looks linear to me. so above 90 should be valid, and below 77 should be valid.

it there is, i will put this thing back in the freezer and get better Serial numbers to fine tune it.

Rather than use a different reference or a voltage divider, can't I just somehow map my values directly to the temperatures i know ? I mean if 77 deg = say 182 Serial, and 90 deg = 142, isn't there a way to map these directly ? it looks linear to me. so above 90 should be valid, and below 77 should be valid.

You can use map() to do what you want but if you use a lower reference voltage you can almost certainly get better resolution. This is why I asked

Do you want to know the actual voltage or just to react when it goes below/above/is in a particular range of values ?

I guess i am confused about how to actually get it to show temperatures. do i have to say for each degree, if value = 142 then temp = 77.
if value = 155 then temp = 76.
do i have to do this maybe a hundred times ?

maybe you can tell, i have never done map or read temp before.

The map() function takes 5 parameters

map(value, fromLow, fromHigh, toLow, toHigh)

Parameters
value: the number to map.
fromLow: the lower bound of the value’s current range.
fromHigh: the upper bound of the value’s current range.
toLow: the lower bound of the value’s target range.
toHigh: the upper bound of the value’s target range.

So if you did

Then for any value of raeReading in the range 142 to 182 would cause the function to return a proportionate value in the range 90 to 77

Ahhh. a proportionate value. beautiful. I will work on it. thanks.

Sounds like you have a NTC thermistor, you will need the Steinhart-Hart equation to compute temperature from resistance.
Try the example in the thermistor library.

Or the thermistor library in the Arduino IDE library manager.

I'm with JCA34F. So far you are treating the sensor as if it is a mystery-sensor. That is not how to deal with a sensor.
So what sensor is it ? How many wires ? Does it have a name or number on it ? Can you show a picture of it ?

When it is indeed a mystery-box, then at least you could make a graph with temperatures and voltages, so we can see if it is linear. If it is linear then we have to find a way to determine if the output is ratiometric (relative to the power voltage).

I say there is a 95% chance that it is a NTC thermistor, either a bare NTC or in a circuit.

I checked the voltages (i don’t know what else to call it - i’m talking about the number i get from the serial read which is printed to the serial monitor) vs. temperatures using a 5v ref (i’m using a mega 2560), and they weren’t bad, but weren’t exactly accurate across the temp spectrum or stable.

so i used the analogReference(INTERNAL2V56); and checked again (using new numbers in the map). I have attached an image of the graph of voltages vs. temps. it is pretty linear. for each temp data point i read the voltage from the serial.

as you can see from the comments in my sketch, the reported temp matches my other temp measuring device well at the very low end and at the very high end, but is off by 7 degrees at 77 deg F. this room temp was verified by a third thermometer.

it is puzzling to me. it appears to be linear on the graph, but gets off in the middle of the range.
i looked at the link to the thermistor, and am not eager to go there.

attached is an image of the temp probe along with the 4 wires. yellow, black, red, green. this is part of a Davis Weather Wizard III.

This example code is in the public domain.
*/

unsigned int temp;

// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(57600);
analogReference(INTERNAL2V56);
}

void loop() {

temp = map(analogRead(A0),189, 740, 110, 15);   // ref 2.56v  ok at 110 deg
int sensorValue = analogRead(A0);               // 7 deg high at true 77
// ok at 10 deg
Serial.println(sensorValue);
Serial.print("Temp = ");
Serial.println(temp);
Serial.println("");
delay(2000);
}

i’m trying to figure out how to bow the map. Thank you.
Well, that seems to be linear. There could be noise. It could be less accurate at the lower and higher end of the scale, that is normal.
There seems to be a circuit inside the temperature probe to make a linear analog output.

Perhaps the temperature probe is not very accurate, and a few degrees inaccuracy might be normal.
Perhaps the main device has calculations to compensate for the non-linear behaviour at the end of the scale.

When the temperature probe has a fixed voltage output for a certain temperature then you should read it with a fixed voltage as reference (one of the Arduino internal voltages).
When the temperature probe has a voltage output that is relative with the power voltage, then you should read it with the 5V as reference (the default Arduino analog reference).

Reading 100mV to 800mV with a 5V range is okay. You could use the averate of 10 or 100 samples and still have enough resolution.

Can you open the temperature probe ?

With a DS18B20 you have a accuracy of ±0.5°C, without the need of precise voltages, without the need to tune a calculation.

the ends of the scales are dead on. it is only the middle that is in error. and too much error. when the temperature is 77 deg, and my contraption reads 84 deg, that is way too much error.

i’m not cutting the probe open. the weather station unit may have some correction circuit in it.

is there another way to map the output ? maybe i’ll just modify the output values in the middle region before they go to the mapping. i’m still thinking about what to do.

There are curve-fitting sites that produce a formula. I suggest you first get the best data points by taking the average of 100 or 1000 samples.

How I calculate a voltage with average is in my "averageRead.ino".

I ended up narrowing the data range. from 40 to 90 deg it is now within 1 deg of correct. Good enough for me. I live in Fla.

Thanks to all replyers, especially UKHeliBob.