Go Down

Topic: Is a lookup table the best option? (Read 1 time) previous topic - next topic

Seán

Hello,

I have a group of data, in which a specific voltage relate to a specific weight, for example 2 volts is almost 1.5kg.

In my prgram, I have mapped the analog input reading, which reads the weight applied to the FSR, to the voltage (0 to 5000mV). So, now I am wondering, can I use a loopup table which will find a specific voltage, and then print out the correspinding weight?

I have never used lookup takes and would really like some advice, because I could completely be heading down the worng paths.

Here is what I have so far, which may make things a bit clearer ...but there is no table in it yet.

Code: [Select]

int analogPin = 0;
int fsrReading;
int fsrVoltage;
long forForce;

void setup()
{
  Serial.begin(9600);
  pinMode(analogPin, INPUT);
}

void loop()
{
  fsrReading = analogRead(analogPin);
  if(fsrReading == 0)
  {
    ;;
  }
  else
  {
    fsrReading = analogRead(analogPin);
 
    //Analog value ranges from 0 to 1023, or 1 to 5000mV
    fsrVoltage = map(fsrReading, 0, 1023, 0, 5000);
    Serial.println("The voltage is: ");
    Serial.println(fsrVoltage);
   
    delay(1000);
  }
}


Thanks in advance.

Seán
Ná bac le mac an bhacaigh is ní bhacfaidh mac an bhacaigh leat.

Graynomad

Is the relationship between the voltage and the weight linear? If so then you don't need a lookup table unless you really need to be fast.

How much resolution do you need? If you want 1 gram resolution over 10kgs the table will probably be too large.

______
Rob

Rob Gray aka the GRAYnomad www.robgray.com

Seán

Hello,

Thanks for the reply.

From tests I have done, the relationship seems to be linear, yes. As for the resolution, yea, I think 1 gram would be good, but they may settle for 10 gram steps.

Seán
Ná bac le mac an bhacaigh is ní bhacfaidh mac an bhacaigh leat.

wildbill


From tests I have done, the relationship seems to be linear, yes. As for the resolution, yea, I think 1 gram would be good, but they may settle for 10 gram steps.

In that case, find the minimum weight that gives an analog reading of 1024 and use map to get the weight. Of course, when the arduino reads 1024, it won't know actually what the weight is, just that it's the max readable.

Seán

But I am looking the program to tell me the weight in the range of 0 to 1023 (or 0 to 5V), so, if I get an analog reading of say, 738, the program will spit out the corresponding weight.

Will your method do that? maybe it's just because I am new, but I don't see how it would.

Seám

Ná bac le mac an bhacaigh is ní bhacfaidh mac an bhacaigh leat.

Go Up