Go Down

Topic: What is the proper way to map PT100 readings to 5V scale (Read 1 time) previous topic - next topic


I have this setup here (for more pictures):http://santiapps.com/?p=2483

Im using this code to map:

Code: [Select]

As I follow the analog readings with a voltmeter and onscreen, they look fine.  I measured the voltage and got:

2.90V for room temp water
2.75V for water cooler water
3.90V for office hot coffee

At least the linearity exists and it is correlated in the right direction.  The problem seems to be my mapping code.  From what I've read 1V = 205 and 5V=1023.  This code above I got from an online post and the OP mentions that he multiplies the 4/20 scale of -10 to 150C by 10 because map doesnt work well with floats.

The problem is that I was getting:

-27 for 2.90V for room temp water
-30 for 2.75V for water cooler water
-1.0 for 3.90V for office hot coffee

I modified the code to this:
Code: [Select]

and you can see the results here where I print out the analog value of 290 for room temp.  So as arduino maps the 290 analog value to a scale that starts at 205, it must give a negative value because it has to go back from 290 to 205.

How can I fix this?


"From what I've read 1V = 205 and 5V=1023."

Only true if Arduino's VCC is 5.0 volt. It might not be.
e.g. a Nano on USB supply has a VCC of ~4.6volt,
and there are 3.3volt Arduinos that output 1023 or 4095 at 3.3volt.
Then you need to use different values in 'map'.

Using 'float' for temp is also silly if you expand 818 (1023-205) to 2000 (-500 to +1500) when you have a temp resolution of 3-5C (± one A/D value).

RTDs are usually used with special preamp breakout boards, with buildin high resolution A/D.

Edit: I see that the code in the quote window is for an industrial 4-20mA sensor.
Post the datasheet. It must have a temperature/current table in the datasheet.


Well im using a plc from industrial shields and im pretty sure its antes Arduino mega inside a plastic box.  That should have a 5v VCC shouldnt It?

Plus the relation seems correct, wouldnt it be more a matter of incorrect mapping?  Iow, ...

oh ok so you mean that it might actually be less than 5v, maybe 4V, and so the lower range of 205 as the mapping code shows, might be wrong and therefore everything is outta wack.

Ok so Ill measure the vcc from the mcu at a 5v VDC pin...and yes, it measured 4.98V.  So how do I proceed to correct it?


If it's a 4-20mA sensor, then you should really use a ~128ohm (Mega) or 51ohm (Uno) load resistor and use 2.56volt Aref (Mega) or 1.1volt Aref (Uno). Not the 273ohm that I see on that link.
Using the buildin Aref voltages eleminates the need for a accurate/stable supply voltage.
Diagram and more info in post#5 here: http://forum.arduino.cc/index.php?topic=527359.0

Mapping values depend on which sensor you have.
You need to know at which temp the sensor outputs 4mA, and at which temp te sensor outputs 20mA.


Thanks wawa, what I have is supposed to be a 250Ω but it seems to be a 237Ω according to the multimeter.

This is the calculation Ive been trying to understand.

I was using a 250Ω resistor because 5v = 0.02A x R => 250Ω.
You say the 5V might be unsteady so I should use the Mega's internal 2.56V Aref such that:

2.56V = 0.02A x R => 128Ω

So thus far I have the mA out from the 4/20 running into the A0 pin of my mega and it is connected thru the 250Ω R to the GND.  You're saying I should simply replace the resistor and add the line:

Code: [Select]

Ok I added the line of code but have yet to change the resistor.  So far I have this result:


Ok I modified the code to this and changed out the resistor to a 120Ω which is the closest I can find.  Im getting the - values again

Code: [Select]
int sensorValue = 0;
int temperature = 0;
int ReceivedByte = 0;
float f1 = 0;
float t1 = 0;

void setup() {

void loop() {
  sensorValue = analogRead(A2);
  f1 = temperature; // Float conversion

Go Up