Go Down

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

wildbill

Given that the response appears to be linear and assuming that when weight is 0, analogread returns 0 and when weight is 1500g, you're getting 2v, we can extrapolate and calculate that a weight of 3750 will give 5v. The voltage is an irrelevance however, you can just map analogread from 0 to 1024 to 0 to 3750 to get the corresponding weight in grams.

Caveats - Does no weight actually give zero reading? Is it linear enough for the accuracy you want? Are the things you're weighing all <= 3750g?

Seán

Ah, okay, I'm with you now!

Yea, when there is no weight applied, I get 0 in the analogRead. I haven't applied enough weight to to get a maximum reading, but I have done a number of points in between, and the graph is linear.

Again, thanks!

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

johnwasser

Code: [Select]

const int OneKilo = 327;  //  analogRead() value for a one kilogram test weight, determined experimentally
const int TwoKilos = 561;  // analogRead() value for a two kilogram test weight, determined experimentally
const int countsPerKilo = TwoKilos - OneKilo;

int grams(int analogValue)
   {
   analogValue -= (OneKilo - countsPerKilo);  // Remove any offset from 0 weight = 0 volts
   return ((analogValue * 1000) / countsPerKilo);  // Convert voltage to grams
   }
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

wildbill


The possible downside is that it is integer and maybe you need decimal/floating point?

Given the hardware he has, integer will be fine as long as he's working in grams - it'll only resolve down to a resolution of ~4g.

Seán

Yea, I am using map now, and is working fine.

Much thanks.

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

Go Up