Arduino UNO calculations wrong

japie:
Hello,

I am trying to calculate a pressure value in Kpa from an automotive pressure sensor connected to an analog input via voltage divider.
Al is working very well, connected the sensor and started reading the analog value on every 100Kpa so I could create a decent calculation that converts my analog value to Kpa.
Strange thing is that my calculation works splendid in a spreadsheet or even in C on my i386 but is way off on the UNO

Ints are 16-bits on the UNO (-32,768 to +32,767), while they are 32-bits on x86 systems (-2,147,483,648 to +2,147,483,647). If you multiply 666 by 666 you get 443,556 which does not fit in an int type, and the truncated value (17,572) is then converted to floating point.

So you want to convert the values to at least long for the multiply:

    for(i=0; i<7; i++)  {
        int result = 0.00067*(((long)value[i])*((long)value[i]))+0.5*value[i]-33;
        printf("%d \n", result);
    }

Or do the whole calculation in floating point (which will be slightly slower on the Arduino):

    for(i=0; i<7; i++)  {
        int result = (int)(0.00067*(((double)value[i])*((double)value[i]))+0.5*value[i]-33.0);
        printf("%d \n", result);
    }