A way to make the program to refer to a table or graph

I am new to arduino, so I am here to ask some advice on how to approach this task I have at hand.

Right now, I have a graphene CVD system, where the pressure of the system plays the key role in the graphene growth. I am trying to use the arduino to take in the analog signal from the pressure gauge ( KJLC 275i ) and convert the analog input value into pressure information. The manual provided a table to map the input voltage values to pressure values.

With my knowledge on the arduino and basic programming, the only thing I can come up with is to have a bunch of 'if' statements doing:

If the analog input is within this range, then interpolate the discrete values from the table to get me a pressure values in between.

I think it will work, but I am sure there is more efficient way of doing the same thing. Argh, with 31 points from the table, I would have to have at least 30 'if' statements, which can be messy!

A link to the pressure sensor might help, but as long as it's a linear responding analog voltage then it should not be a big deal converting the reading to any internal scaling you require in your program. Reading a analog input pin results in a integer value that can range from 0-1023 counts. From the sensor datasheet it should give you the measurement voltage range Vs pressure range. So for an example lets assume one has a pressure sensor that measures from 0-200 kilopascal of pressure and sends a corresponding voltage output of 0-5vdc.

A arduino converts a 0-5vdc analog voltage to a integer value of 0-1023. So then one can use the arduino mapping function as such:

int scaledReading;
int rawReading;
rawReading = analogRead(pin#);
scaledReading = map(rawReading, 0,1023,0,200);

Then you have a variable named scaledReading that can range in value from 0-200 to utilize in your program.

Again a link to your specific pressure sensor would be required to make this all accurate, but hopefully you get the concept?

Lefty

http://www.lesker.com/NewWeb/Gauges/pdf/manuals/KJLC%20275i%20Series%20manual%20v102%20050415.pdf

NOT a linear mapping. It’s some kind of exponential S-curve.

With an array you can do piece-wise linear interpolation:

struct point {float pressure; int reading} table[] = {
{0.0001, (0.375/5.0)*1023},
{0.001,  (0.412/5.0)*1023},
{0.01,   (0.465/5.0)*1023},
{0.1,     (0.515/5.0)*1023}
}

value = analogRead(0);
float result;

for (int i=1; i< sizeof table / sizeof table[0]; i++)
    {
    if (value > table[i-1].reading ** value < table[i].reading)
         {
         result = table[i-1].pressure + ...  // Do the linear interpolation here.
         break;
         }
    }

NOT a linear mapping. It's some kind of exponential S-curve.

With an array you can do piece-wise linear interpolation:

That's where multiMap was created for - http://arduino.cc/playground/Main/MultiMap - (also deliverable in float ;)

robtillaart:

NOT a linear mapping. It's some kind of exponential S-curve.

With an array you can do piece-wise linear interpolation:

That's where multiMap was created for - http://arduino.cc/playground/Main/MultiMap - (also deliverable in float ;)

Excellent! That will do the piece-wise linear interpolation.

What's really needed is an integer to float mapping but that should not be too hard to make from the Float version.

Oh my~! :astonished: Thank you all, guys! All of your info are right on the dot for what I want to do. I have the code written. Now, I would need to test this with the system. Again, THANK YOU!!