Hello, I am new to programming Arduino. I am trying to build a refrigeration monitor. I am using a 0-5 vdc pressure sensor on analog input 0. I need to read the pressure input, find the two values in the table that the reading falls between and call out the temperature reading. The table is basically a pressure to temperature table. find pressure reading in chart and cross over to find corresponding temperature. I was going to do calculations, but the formula is way to complex and involved, hence the cross reference table. I have the analogRead mapped from 0-1023 to 0-500 PSI. I am having trouble taking the value, say 34.7 and getting the temperature from the table. 34.7-35.6 is the range for a cross reference of 1 deg. I would need to get the value, scan the table to find out where it falls between the two values (interpolate ?) and then retrieve the temperature value for further processing. Thanks in advance for any help, Nik

P.S. I have attached the pressure to temperature chart for reference.

Maybe if you post the chart somebody will see a simple way to implement it?

How many temperature steps do you need to deal with? I the number is not too large (say 50 or so) you could create an array and map the values from analogRead() to index into the array.

I posted the chart with my initial post (Advantage engineering.pdf)

I took the Value from the sensor via analogRead (A0) as an int.

Then i made a float (voltage) = sensorValue * (500.0/1023.0) to get it as a decimal number.

Now I need to figure out how to take that value (34.8 for example) and figure out how to scan the table under the R404A column to see where it falls so I can get the temperature value from the left column. I will probably need only 51 values in the table (0-50 degrees.) I do not think an array index can be a float variable.

I was going to do calculations, but the formula is way to complex and involved,

I doubt that. If you post the formula for the pressure-temperature relationship (or a link to it), I'll be happy to write the one or two lines to compute it.

You haven't told us how quickly you need to find the values. If just monitoring something and don't need to do something in the next 5 milliseconds, just search the table linearly.

nikbatten:
I posted the chart with my initial post (Advantage engineering.pdf)

I had not noticed that - I try to avoid downloading PDFs.

I don't think you have said what refrigerant you are using so I will assume R-22 which is the first column.

The range of pressures is from 0.6 to 50. If I pick a pressure - say 15.2 I can read off a temperature of -24.4C, and 16.5 gives me -23.3. Am I interpreting the table properly?

You have not told us how the analogRead() values 0-1023 relate to those pressure values. Knowing that seems to be essential. I don't see any value in using floating point values - they are less precise and the calculations are a lot slower.

Can you produce a graph from the table for your chosen refrigerant and post a picture of it. That will illustrate the relationship more clearly. The PDF you posted is just an image and I cannot extract the numbers from it.

Robin2:
I don't think you have said what refrigerant you are using so I will assume R-22 which is the first column.

In Reply 3 he said it is R-404a. Because I am really nice (or really bored, you guys can pick), I graphed the R-404a column. As you can see, the trendline is almost perfect with a third order polynomial:

y = 0.0002x^3 + 0.0336x^2 + 2.7693x + 73.666

I don't know how well Arduino does with powers but surely this calculation shouldn't take too long...

Are you sure that the calculations are of any worth to your project? IMO a pressure difference is related to a temperature difference, so that you'll have to measure absolute temperatures as well?

nikbatten:
I posted the chart with my initial post (Advantage engineering.pdf)

I took the Value from the sensor via analogRead (A0) as an int.

Then i made a float (voltage) = sensorValue * (500.0/1023.0) to get it as a decimal number.

Now I need to figure out how to take that value (34.8 for example) and figure out how to scan the table under the R404A column to see where it falls so I can get the temperature value from the left column. I will probably need only 51 values in the table (0-50 degrees.) I do not think an array index can be a float variable.

Thank, Nik

You can only get 1 of 1024 readings from analog and every one of those has a corresponding pressure.
So all you need is an array with 1 value for every possible read in order, the pressure value will be in the read value position.

There is no need to compare and interpolate when you use the analog read value directly as an array index, answer is right there!

Now you need to learn about PROGMEM to store and read table values from flash memory unless your Arduino has 8K RAM or more. PROGMEM learning will pay for itself, an Uno/Nano/Micro/Mini has 32K of flash and most programs don't fill 8K of that... put all your constant text and data there and you can write "bigger" sketches.