# How to get scaled 4-20mA temperature sensor signal in PLC



## Signode (Oct 9, 2016)

Hi;

I have installed a temperature and humidity sensor Autonics THD-R-C which gives 4-20mA signal out. The signal is connected with Fatek PLC’s analog input card. This is first time I am working with 4-20mA analog signal rather 0-10V for which I need some guideline to get the signals scaled.
According to manual of sensor, at -19.9C it gives 4mA and at 60C it gives 20mA. In PLC, the coding format is 14bit (0 – 16380). Now how do I scale the values to get exact temperature data in PLC?


----------



## MDShunk (Jan 7, 2007)

with the math instruction that will be:
((60 - -20) / (16380-0) *raw input value from your analog input) + -20

This is engineering units range max-engineering units range min, divided by input counts max-input counts min, times the actual input value, plus the min engineering units value. 

This is very typical scaling input math, unless the PLC brand happens to have a special scaling function. Know this math by heart if you're scaling inputs. 

In this instance, if your raw input value is 7477 (a number picked out of my butt), the scaled temperature would be:

((60 - -20) / (16380-0) * 7477) + -20 =
((80) / (16380) * 7477 ) -20 =
(0.004884 * 7477) -20 =
36.52 -20=
16.52 degrees C


----------



## splatz (May 23, 2015)

```
scaling factor = (high temp - low temp) / (high value - low value) 
               = (60-(-19.9)) / (16380 - 0) = 79.9/16380 =  0.00487789987
```
In plain language, a reading of zero corresponds to a temperature of -19.9C, and every uptick in the register value corresponds to an uptick of 0.00487789987 above that base temperature value. So 


```
Temperature = low temp base value + ( scaling factor * IO reading)
            = -19.9 + (0.00487789987 * IO Reading)
```
So for a reading of say 8190 which is right in the middle of the range of values


```
T = -19.9 + (8190 * 0.00487789987) = 20.0499999353
```
which is as you'd expect right in the middle of the range of temperatures. 

edit: See what happens when you **** around with forum formatting etc? @MDShunk beats you to the punch.


----------



## oliquir (Jan 13, 2011)

too bad not all plc have scaling function, in the ones i used the more (cheapo automationdirect click plcs) i just enter wanted scaled values into the analog card config!


----------



## MDShunk (Jan 7, 2007)

oliquir said:


> too bad not all plc have scaling function, in the ones i used the more (cheapo automationdirect click plcs) i just enter wanted scaled values into the analog card config!


Many do, but a lot of people are just used to doing the math in the logic. Makes it easier to do 3, 4, 5, 10 point scaling for slope compensation for less than perfect sensors.


----------



## splatz (May 23, 2015)

It is good to know the scaling math anyway. One example, I had a pressure transducer at the bottom of a pond to measure the pond level. The sensor was not exactly on the money according to its specs. 

I could not very well empty and fill the pond to calibrate my bottom of scale and top of scale current readings. I had to take depth measurements at different times, calculate the scaling, and extrapolate to adjust at the top and bottom of the scale.


----------



## MDShunk (Jan 7, 2007)

Things like pressure sensors will often not be at dead zero, even if you're holding them in your hand in free air. This gets worse as they age. Being able to tweak the math every once and again has value. If it's a pressure sensor for level measurement, the density of the product needs plugged in there, since inches of water column isn't necessarily inches of ketchup column, etc. If it's something like a dish bottom tank or cone bottom tank, you can't scale it in the analog input card anyhow. You have to do math in the logic.


----------



## Signode (Oct 9, 2016)

splatz said:


> ```
> scaling factor = (high temp - low temp) / (high value - low value)
> = (60-(-19.9)) / (16380 - 0) = 79.9/16380 =  0.00487789987
> ```
> ...



Thanks a lot. I have applied this math and got the results. But the temperature output after scaling is almost +4 of actual temperature. I can subtract -4 to get actual temperature but normally this difference should not happen.


----------



## MDShunk (Jan 7, 2007)

Signode said:


> Thanks a lot. I have applied this math and got the results. But the temperature output after scaling is almost +4 of actual temperature. I can subtract -4 to get actual temperature but normally this difference should not happen.


You should have zero and span pots in the temperature transmitter. You need to calibrate your transmitter. Plus or minus 4 is pretty good, out of the box. Many low end temperature probes are only spec'd to be good for plus or minus 2 anyhow. Calibration is a normal part of instrumentation. It would be a little unusual for your plus 4 measurement to be linear through the whole range, so subtracting 4 in the logic (while tempting) will likely make other parts of the range all goofed up. 


By the way, make sure the instrument you're using for "actual temperature" isn't the one that 's off. It should be calibrated twice as good as the tolerances for the transmitter(s) you're calibrating with it.


----------



## splatz (May 23, 2015)

Signode said:


> Thanks a lot. I have applied this math and got the results. But the temperature output after scaling is almost +4 of actual temperature. I can subtract -4 to get actual temperature but normally this difference should not happen.


This happens to me a lot - the sensors are not that accurate and I need to make adjustments. 

If you are consistently off by 4 degrees, you can just adjust the base value. 

If you are further off at one end of the scale or the other, my way is to adjust the scaling factor, and then possibly the base value. 

The scaling factor is easy to adjust. You only need two calibration measurements, *as far apart as you can in the operating range*. You can measure either the register value at these two points, or the actual current in the loop - answer will be the same. The scaling factor will be 


```
(high point register value - low point register value) / ( high point temp - low point temp)
or 
(high point current - low point current) / ( high point temp - low point temp)
```
If you are able to take your low temperarure calibration reading at the low end of the scale - in this case -19.9C - you can use your actual measurement to set the base value. 

If not you, can determine the base value with more algebra: 


```
Calibration Reading Temp = adjusted base value + ( adjusted scaling factor * Calibration Register Value) 

Calibration Temp - ( adjusted scaling factor * Calibration Register Value) = adjusted base value
```
but if you've had enough math and rather not do more, you can just modify the program with the adjusted scaling factor, run the program, see how far off you are with one more measurement, and adjust the base value based on that measurement.


----------



## MDShunk (Jan 7, 2007)

I'm incredibly resistant to making changes in the logic to accommodate the calibration. I'd favor using the zero and span pots where they exist.


----------



## splatz (May 23, 2015)

MDShunk said:


> I'm incredibly resistant to making changes in the logic to accommodate the calibration. I'd favor using the zero and span pots where they exist.


That's a good point - I think anyone would agree, if the sensor allows for calibration it's much better to calibrate the sensor than modify the program. Most of what I have to work on is sealed, factory calibrated, no adjustments.


----------



## Signode (Oct 9, 2016)

splatz said:


> That's a good point - I think anyone would agree, if the sensor allows for calibration it's much better to calibrate the sensor than modify the program. Most of what I have to work on is sealed, factory calibrated, no adjustments.



The sensor dont have calibration option. Its factory sealed.
If i subtract "4" to get right value, but the difference increases with temperature increase.


----------



## oliquir (Jan 13, 2011)

Signode said:


> The sensor dont have calibration option. Its factory sealed.
> If i subtract "4" to get right value, but the difference increases with temperature increase.


a lot of sensors must be calibrated via hart protocol, sensors with zero and span potentiometers are becoming obsolete


----------



## splatz (May 23, 2015)

Signode said:


> The sensor dont have calibration option. Its factory sealed.
> If i subtract "4" to get right value, but the difference increases with temperature increase.


That means you have to adjust the scaling factor, not just the base value. 

Give us two actual readings, one as low as possible, one as high as possible, along with the actual temperature, we can work out the adjustment.


----------



## Signode (Oct 9, 2016)

splatz said:


> That means you have to adjust the scaling factor, not just the base value.
> 
> Give us two actual readings, one as low as possible, one as high as possible, along with the actual temperature, we can work out the adjustment.



Hi;

As per your instruction, I have collected the data which is as following;

Minimum temperature (Measured by an external device) = 17.3c
Analog input in PLC = 9360 (confirmed by Fatek and SLC 5/05)

Maximum temperature (Measured by an external device) = 52.6c
Analog input in PLC = 14600 (confirmed by Fatek and SLC 5/05)


----------



## splatz (May 23, 2015)

Signode said:


> Hi;
> 
> As per your instruction, I have collected the data which is as following;
> 
> ...


OK so the adjusted scaling factor - 


```
( high point temp - low point temp) / (high point register value - low point register value)

= (52.6 - 17.3) / (14600 - 9360) 

= 0.00673664122
```


----------



## Signode (Oct 9, 2016)

Hi;


After applying scale factor 0.00673664122, there is a big error (temp was around 27 but PLC calculated around 53). So by manually applying scale factor, i found that the reading is almost ok with scale factor 0.0043770005.


----------



## splatz (May 23, 2015)

@Signode, there must be some mistake in my calculation, I can't do this kind of thing right on my phone! I will look at it full size this morning hopefully be more helpful.


----------



## Rora (Jan 31, 2017)

Sensor regulates 4 mA at -19.9 C, 20 mA at 60 C, but you're missing an entire step at the ADC on the PLC by assuming the mA range that is associated with the register. It is probably 0 to 20 mA, but it may be, say, 0 to 24 mA (to account for low/~3.5 mA and high/~21.5+ mA alarms, complete failure/0 mA). Best bet is to find the PLC analog input specification or source current until you hit 16,380 on the register, assuming it reads 0 out of 16,380 with no current. Just something that might explain incorrect readings.

There's a few steps to calculate the temperature... first, determine current with (ADC max current * (register value/16,380)) = current. Next, correlate current to percentage with (current - 4 mA) / 16 mA = percentage. Correlate percentage with temperature with ((max temp - min temp) * percentage) + min temp = temp... be sure to include double negatives for negative min temps.

Example, ADC max current = 24 mA, reading 8,190 on the register:

24 mA (8190/16380) = 12 mA
(12 mA - 4 mA) / 16 mA = 0.5 or 50%
((60 - (-19.9)) * 0.5) + (-19.9) = 20.05 C

This checks out with 20.05 C being 50% between 19.9 C and 60 C. You shouldn't need to trim the transmitter current for setup from factory new, that's for when it drifts and doesn't transmit 4 mA at -19.9 C or 20 mA at 60 C. If you set it up right and the reading seems wrong, you'd need a better temperature measurement standard in order to trim the transmitter current until it matches the measurement from your better standard.


----------



## splatz (May 23, 2015)

@Signode - actually maybe it's something else. Using your sample readings, I got the same result. I graphed it to check. There is a fantastic online graphing calculator at 

https://www.desmos.com/calculator 

(One of those things an old dog like me can't believe how easy some things have gotten.) 

Anyway here's the graphs ... based on the two test points you gave me, the sensor is way off the factory spec.


----------



## Rora (Jan 31, 2017)

I've only given a cursory read of the calculations provided, but am I wrong to say that we aren't including the zero extraction (-4 mA)? It's not a simple high/low register to high/low temperature correlation, as is the case for 0-10V inputs...

Assuming that's already been covered, are the inputs set up correctly in the PLC to 1-5V (assuming the 4-20 mA runs through 250 ohm resistor at the PLC).


----------



## splatz (May 23, 2015)

Rora said:


> I've only given a cursory read of the calculations provided, but am I wrong to say that we aren't including the zero extraction (-4 mA)? It's not a simple high/low register to high/low temperature correlation, as is the case for 0-10V inputs.


You can calculate the slope / scaling factor from the two points without calculating the zero. With the scaling factor correct, you can make a single adjustment based on any point and everything should come back into line. 

I think the OP is getting conflicting readings, I'd plot a bunch of readings before I went any further just to avoid chasing my tail if something's way off here.


----------



## Instrumentation (Mar 11, 2018)

MDShunk said:


> with the math instruction that will be:
> ((60 - -20) / (16380-0) *raw input value from your analog input) + -20
> 
> This is engineering units range max-engineering units range min, divided by input counts max-input counts min, times the actual input value, plus the min engineering units value.
> ...



Do you have any suggested reading material that covers exactly how to handle rotary encoder scaling? I had a few issues with it in a DL-06 PLC and I was not entirely sure how to scale it correctly. The count was being recorded in BCD and then placed into memory with double words, if that makes any sense.


----------



## gpop (May 14, 2018)

Signode said:


> Hi;
> 
> I have installed a temperature and humidity sensor Autonics THD-R-C which gives 4-20mA signal out. The signal is connected with Fatek PLC’s analog input card. This is first time I am working with 4-20mA analog signal rather 0-10V for which I need some guideline to get the signals scaled.
> According to manual of sensor, at -19.9C it gives 4mA and at 60C it gives 20mA. In PLC, the coding format is 14bit (0 – 16380). Now how do I scale the values to get exact temperature data in PLC?



which Fatek PLC’s analog input card. I dont use fatek but looking at a few online they come in many different flavors. Are you sure that you have a 4-20ma input card (maybe programmable or have jumpers).

To tired to run the maths to see if you are using a 0-20ma input card


----------



## Rora (Jan 31, 2017)

splatz said:


> You can calculate the slope / scaling factor from the two points without calculating the zero. With the scaling factor correct, you can make a single adjustment based on any point and everything should come back into line.
> 
> I think the OP is getting conflicting readings, I'd plot a bunch of readings before I went any further just to avoid chasing my tail if something's way off here.


This is very true, however the scaling factor was determined without extracting the zero. 4 mA is the zero on the transmitter, but 4 mA may not be 0 in the PLC register. Looking at Fatek's AIO specifications, they list -5 to 5V, -10 to 10V, 0 to 10V, and 0 to 5V... for this scaling factor to work, it would need 1-5V in order to correspond to 4-20 mA through 250 ohm resistor without any zero offset.

This goes into a perhaps bigger issue of the input setting on the PLC (i.e., 0-5V, 0-10V, 1-5V). The scaling factor used assumes this the PLC input is correctly set to 1-5V. OP will need to provide us with what is available and what will be used before we can properly calculate a scaling factor.


----------



## gpop (May 14, 2018)

ok i think i have worked this out.

You have a 4-20ma sensor hooked to a 0-20ma analog card

I still come up with a problem where the scale does not work even when corrected. its close by no peanut

How did you get the temp for the examples you posted. Was it against a cailbrated piece of equipment or a TC plugged into a meter?


----------



## Signode (Oct 9, 2016)

Dear All;


Thanks a lot for spending time. Yes! there is some mistake elsewhere. Lets give me time to have a deep look at entire network then will let you know. 

I will use SLC 5/05 with analog input card 1746-NIO4V to check the network. Previously i worked with FATEK PLC with analog input card.


----------



## gpop (May 14, 2018)

You can hook up a 4-20ma sensor to a 0-20ma card you just have to compensate for the 4ma diffrence.


----------



## Signode (Oct 9, 2016)

Hi;


I am really sorry for my mistake which has made this thread long. Dont know how i did that blunder mistake. 
Yes, the PLC card is scaled as 0-20mA = 0-16380 rather 4-20mA.
Following is the link for literature of FATEK PLC expansion board FBs-B4AD; 


http://www.esea.cz/support/fatek/FBs Datasheet/cat_B4AD_en.pdf



But SPLATZ, for me your formula doesnt work.



splatz said:


> ```
> scaling factor = (high temp - low temp) / (high value - low value)
> = (60-(-19.9)) / (16380 - 0) = 79.9/16380 =   0.00487789987
> ```
> ...



You can simulate the formula and can find the mistake because after applying formula, if input RAW value is 3276, the out temperature should be -19.9 and for 16380, the temp should be 60.
I have used following formula in PLC which is working correctly;


Out Temp = (((InRAW - InRAWMin) / (InRAWMax - InRAWMin)) X (EUMax - EUMin)) + EUMin


Say the input RAW value is 11300 in PLC then;
29 = (((11300 - 3276) / (16380 - 3276)) X (60 - -19.9)) + -19.9


Please make me correct if mistaking.


----------



## splatz (May 23, 2015)

@gpop - nicely done! 
@Signode - number one, if you have it working, don't worry about it, but... 

That formula was based on 4-20 rather than 0-20. When you use a 4-20 sensor on a 0-20 input, the register value at 4ma will be 


```
(4/20)*16380 = 3276
```
The scaling factor you caculate from your two test values makes sense with a 4-20 sensor on a 0-20 input. The scaling factor *based on the spec values, using a 0-20ma input,* would be 


```
(60 - (-19.9)) / (16380 - 3276) = .0061
```
Now the scaling factor based on your *readings* does not change, 


```
(52.6 - 17.3) / (14600 - 9360) = .0067
```
now that's more like it they are pretty close! 

The zero adjust (y intercept) based on the specs 


```
= 60 - (.0061)*16380 = -39.92
```
The zero adjust based on your readings 


```
= 52.6 - (.0067)*14600 = -45.22
```
So the formula by your readings would be 


```
Temp = ( .0067 * RegisterValue ) - 45.22
```
The formula by the spec would be 


```
Temp = ( .0061 * RegisterValue ) - 39.92
```
I can check my work makes sense real easily with the online graphing calculator at http://www.desmos.com/calculator


----------



## gpop (May 14, 2018)

As a side note i know its common pratice to round a number in the plc as it makes very little diffrence in real life but when calculating scales its better to do the maths with real numbers.

14 bit is 16383

The sensor claims a accruacy of 0.8 degrees over its range. As its a pt100 and a anaolog converter it should be able to do this which is why im wondering why it is off compaired to your readings with a second temp sensor.


----------



## paulengr (Oct 8, 2017)

As far as BCD encoding goes, the posting with double words and the like doesn't make a lot of sense. BCD by itself is base-10 numbers stuffed into each nibble in a byte. A nibble is 4 bits. So conventionally if we had say the number 22 decimal, that would be:
00010110 in binary (16+4+2=22) and an 8 bit byte can store the numbers 0 through 255. But in BCD format, we treat every 4 bits separately so knowing that "2' in binary is 0010 (in a nibble), the number would be 0010,0010 (adding the comma for clarity). A BCD byte can only store the numbers 0 to 99. Nibbles 1010 to 1111 (10-15 decimal) are invalid. If we just assumed that this is a binary number, we'd get 34 decimal which is wrong. Back when we didn't exactly have standards for doing things sometimes you'd see BCD logic gates and BCD arithmetic going on but it's not very efficient either in terms of speed or memory so pretty quickly the world standardized on binary arithmetic as the way to do everything. BCD at this point is mostly just a painful historical issue. The first thing to do with BCD is to convert it to binary so that you can actually use the result in the normal way.



The conversion is pretty simple. Shift the BCD number 4 digits to the right (divide by 16, drop fractions) and multiply by 6, then subtract this from the original BCD number to convert to binary. So starting with 34, shifting it to the right 4 bits (divide by 16) gives us just the top 4 bits or 0010 or 2. Multiplying by 6 gives us 12. Subtracting this from the incorrect binary value of 34 gives us 34-12 = 22, exactly the result we are looking for. The trick here is that shifting part. Microprocessors typically have a special set o logic gates called "barrel shifter" for doing this operation, because it is a really common thing to do. Multiplying and dividing by powers of 2 basically takes almost no calculations at all compared to general purpose multipliers and dividers which are far more complicated to implement in hardware. So in a PLC you need to look for a bit shifting instruction first to do that step. If you don't have one then use a division command. Remember we want an integer result that is NOT rounded (truncation only) so if you are forced to use a general purpose division command where you have to divide by 16 instead of right shifting 4 bits, be very careful that it gives you the correct result that you need. Also be careful to avoid the "arithmetic shift". That one does something called sign extension. This is unsigned math here.



Now if you have two bytes which is what it sounds like you are dealing with, the second byte will be the hundreds and thousands places in the BCD number. So simply do the above conversion twice and multiply the second number by 100 and add. So if we had BCD 1022, the bytes would be 16 and 34. Shifting by 4, multiplying by 6, and subtracting gives us 10 and 22. So then we calculate 10*100+22 = 1022, the correct result in decimal (binary arithmetic).


The alternative if the math here seems way too complicated is the lookup table. Simply create a table in memory with 170 entries (only 99 are used). Put the correct decimal number in the entries in the table so entries 0 to 9 are 0, 1, 2...9. Then starting at entry 16 put in the numbers 10 to 19, then at 32 put in the numbers 20 to 29, and so forth every 16 entries until you get to 99. Then you can simply lookup the converted number by using your BCD input number as an index into the table. This takes up a lot more memory, it's probably just about as fast if not faster, and avoids doing division or bit shifting if you're struggling on getting that working correctly. You CAN theoretically create a much larger table and convert say up to 9999 in one go at it and with today's monster PLC memories that might make sense except you'd want to program a routine to fill in the table and never do all that by hand, but just reading each byte and multiplying by 100 is so simple there's not much point in doing all that.


Going from decimal to BCD is much more complicated. The algorithm to do it is called the "double dabble" algorithm. It is so complicated that frankly, the table look up method (in reverse) is a lot more efficient.


If you really want to dig into all this stuff, Knuth created a great series of text books called the "Art of Computer Programming" which contains all the details of the various algorithms out there and is the go-to source for this kind of information, although Knuth is an IT professor so his code is going to be similar to C instead of ladder logic or instruction list.


----------



## paulengr (Oct 8, 2017)

The way I always do conversions is I start with knowing 4 pieces of information:
The raw (input) low and high values, the "engineering unit" low and high values. These can be reversed too but basically I need to know the pairs (low, low; and high, high). If you don't know or are unsure of what you are dealing with if you can simulate an analog input (inject 4 mA and 20 mA for instance) and read the raw values in the PLC, you can just use those. This is actually a calibrated result so it's a bit better than a textbook answer.


There are tons of small 4-20 mA simulators on the market. You really only need 4 and 20 mA output so if you are paying more than $20 for one, you got ripped off. The cheap ones are about the size of a pack of cigarettes and have a couple alligator clips on them that fit in almost any tool pouch or box. You can also make your own fairly inexpensively with a battery, a voltage regulator, and some resistors but it's usually not worth the effort/money. This is a $20 one that is actually a good one (full scale):


https://www.amazon.com/Generator-DR..._rd_t=40701&psc=1&refRID=7KAC4DM4CAZ04B84XS8S


Now moving on to the conversion, first lets convert it to standard math terms:
x1=raw low
x2=raw high
y1=engineering unit low
y2=engineering unit high


There is a good reason for doing this and not just because you might remember seeing this in school. It is really helpful to get away from terms like "current" and "engineering units" when you're doing the math. If you don't, chances are you'll just confuse yourself and swap numbers somewhere. I've made this mistake countless times myself.



Remember that "low" and "high" are just pairs of values here. You can have reverse scaling too where as the raw input goes up, the scaled output goes down. Just be careful of your signs and what you are calling everything. It's helpful to write it down on a table (x1, x2, y1, y2) before you start to avoid mistakes.


ALSO one more thing...we don't actually need the EXACT low and high values here. All we need is two pairs of numbers spaced far enough apart to get most of the range in. Say the input is 0 to 10 V. Well I can get a 0 V source really easy (short the input) but unless you have a precision power supply the 10 V might be a bit tricky to get. So use a 9 V battery and check the output with your multimeter and read the raw number input on the PLC. If you do this remember in this case we have 2 conversions. First we have to convert temperature to Volts. This is just looking up numbers in the sensor data (temperature low, zero volts, temperature high, 10 Volts) and then running the calculation (y = m*x + b) to calculate the temperature at whatever the 9 Volt battery puts out. Then we can take the two temperatures (for 0 Volts and our calculated "9 Volt" temperature) as engineering units and the PLC measured raw values to run the conversion a second time to finally calculate our scaled PLC output value. Like I said a little extra step but it let's us get away with the tools we have at hand (a battery laying in the battery box in the truck or stolen out of a meter) instead of whining because we don't have a fancy $3,000 Fluke toy to do something $25 in cheap tools that don't need $300 calibration stickers can do.


Now on to the math...




The standard scaling formula is y=m*x+b which you might remember from school. All we need is the scaling factor (m) and the offset (b). First calculate m:
m=(y2-y1) / (x2 - x1)


That's the famous "rise over run" formula. If we treat the x and y values as coordinates on a graph then the "rise" is the difference in the y values and the "run" is the difference in the x values, and the slope of the line between those two coordinates is rise / run. You can chart it in a spreadsheet or something but to me that just makes it more complicated to figure out. Just make sure you keep track of which one is which (writing down x1, x2, y1, y2) when you start and do the math and you won't go wrong.



Now we need the offset. This is where the original formula missed, and it is a COMMON MISTAKE. Missing the offset adds a 20% error to 4-20 mA loops if the PLC input is say 0-20 mA or uses a precision resistor to scale to 1-5 V or 2-10 V. Run the formula in reverse to calculate b:


b = y - (m*x)


y and x here are either the PAIR x1 and y1, or the PAIR x2 and y2 (lows or highs) but do NOT mix them up! It is helpful if one of the values is already a zero so for instance if y1 (the engineering unit low) is a zero then we simply get b = -m * x1.


So if our input low is say 4000 and our input high is 20000 (I think the CompactLogix PLC uses these values) and the output is say -32 F to 212 F then we'd calculate as follows:


(212 - (-32) / (20000-4000) = 244 / 16,000 = 0.0152 = m
b = 212 - 0.0152 * 20000 = -92
b = -32 - 0.0152 * 4000 = -93 (rounding error just a little bit here)


I showed both points of the b=y-(m*x) formula here just to show that it works.


Now i we had say 12,000 which is dead center in the range we can sort of intuitively figure out that that's the same as 244 / 2 - 32 = 122 - 32 = 90 F. So let's check that...


12000 * 0.0152 - 92 = 90.4 F. Pretty close and the difference is just some rounding in the slope (m).


I've used the same math to tutor middle school kids on the "linear equation" and they get it right away. The teacher kept trying to talk about y-intercepts and all kinds of other goofy ways instead of just sticking with the simple basic formula which made it much more confusing to them.


Also notice that your raw inputs to the PLC were 0 mA and 20 mA but your actual temperature sensor outputs were 4 mA and 20 mA, NOT all the way to zero. It's important to remember to figure out what the correct inputs and outputs are and if you're not sure, just hook up a loop simulator and test it. Especially when you only have 10% (nonprecision) resistors and such to work with, it's very helpful to do this and simply calibrate away most of your error. The result will be under 1% error almost every time.


----------



## Signode (Oct 9, 2016)

Dear Friends;


After having successful simulation (by the help of you people) in LAB, I am going to install the sensors in our corrugator plant to see;


Outside department temperature.
Inside department temperature.
Humidity %


Will come back if face any problem. Thanks a lot for your co-operation.


----------



## Signode (Oct 9, 2016)

Hi Friends;


I have installed the sensors in department and data logging has started. Thanks a lot to spend time for me.


----------

