Load cell -- zeroing problem

can someone tell me how i can get my bowl to be my zero point on my load cell? my bowl weighs 0.147 kg and i found the analog reading is 96. I made a variable and set it to 96 and then subtracted 96 from the analog reading to give me 0 and then the analog reading is set to zero. but my problem is once i add something to the bowl the analog reading is still reading zero and will not change. can someone tell me what i may be doing wrong?

here is what i am getting:
analogValue: 0.00
load: -6.40610

any help would be appreciated! :slight_smile:

// Load cells are linear. So once you have established two data pairs, you can interpolate the rest.

// Step 1: Upload this sketch to your arduino board

// You need two loads of well know weight. In this example A = 10 kg. B = 30 kg
// Put on load A
// read the analog value showing (this is analogvalA)
// put on load B
// read the analog value B

// Enter you own analog values here
float loadA = 0.147; // kg
int analogvalA = 96;  // analog reading taken with load A on the load cell

float loadB = 0.321; //30; // kg
int analogvalB = 146; // analog reading taken with load B on the load cell

// Upload the sketch again, and confirm, that the kilo-reading from the serial output now is correct, using your known loads

float analogValueAverage = 0;

// How often do we do readings?
long time = 0; //
int timeBetweenReadings = 200; // We want a reading every 200 ms;
int zero = 96;


void setup() {
  Serial.begin(9600);
}

void loop() {
  int analogValue = analogRead(0);

  // running average - We smooth the readings a little bit
  analogValueAverage = 0.99*analogValueAverage + 0.01*analogValue;
  //analogValueAverage = analogvalA - zero; 

  // Is it time to print?
  if(millis() > time + timeBetweenReadings){
    float load = analogToLoad(analogValueAverage);
    double ounce = load * 35.274;

    Serial.print("analogValue: ");Serial.println(analogValueAverage);
    Serial.print("Ounce: ");Serial.println(ounce);
    Serial.print("             load: ");Serial.println(load,5);
    time = millis();
  }
}

float analogToLoad(float analogval){

  // using a custom map-function, because the standard arduino map function only uses int
  float load = mapfloat(analogval, analogvalA, analogvalB, loadA, loadB);
  return load;
}

float mapfloat(float x, float in_min, float in_max, float out_min, float out_max)
{
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

Hi,
Just a quick look, shouldn't this

analogValueAverage = analogvalA - zero;

be this

analogValueAverage = analogvalueAverage - zero;

To subtract the offset.

Tom... :slight_smile:

that makes sense, but unfortunately it still does not change.

Hi,
How does.

 analogValueAverage = 0.99*analogValueAverage + 0.01*analogValue;

Produce an average?

You need to put more serial.print in your program to trace you analog values.

Tom... :slight_smile:

the code i am using is from someone else i found posted on instructables. so the way i understand it is that it takes the average of the reading over a long period of time by using the current value * 0.99 + 0.01 * new value. so every time a new value is read in it is giving less and less influence on the overall value that is being kept where the number does not fluctuate as much.

analogValueAverage = 0.99analogValueAverage + 0.01analogValue;
analogValueAverage = ((analogValue -1) / analogValue) * analogValueAverage + (1/analogValue) * analogValue

example is analogValue = 100 so:
analogValueAverage = ((100 -1) / 100) * analogValueAverage + (1/100) * analogValue
0.99 0.01

Hi,
You need to put more serial.print statements in to check your variables as you calculate them.
Also

analogValueAverage = 0.99*analogValueAverage + 0.01*(float)analogValue;

Might help as analogValue is an int.

Tom... :slight_smile:

How did you connect the load cell to the Arduino.
Are you using an instrumentation amp between the load cell and the analogue input?
The output of a load cell has very little voltage variation, so small weights can't be measured directly with the A/D.
Leo..

Assuming that your system is giving you the correct weights WITHOUT your attempt to zero it....that is, did you do this: // Upload the sketch again, and confirm, that the kilo-reading from the serial output now is correct, using your known loads...

...then...

One way to learn how to properly zero your load cell is to develop a better understanding of what the mapFloat function is doing.

And one way to do THAT is to do some calculations by hand. For example, what does mapfloat(analogval, analogvalA, analogvalB, loadA, loadB) give you if analogval = 0? (A: a negative number) And if you multiply that result by 35.274, what do you get? (A: something close to -6.4) Does that make sense? (A: no) So do you think you should be "zeroing" your cell by subtracting 96 from the analogvalue? (A: no)

Well, what should you do?

One way to figure THAT out is to draw a graph on paper that shows what mapfloat does. The graph horizontal axis is for analog values and the vertical axis is for "load" or weight. Plot the two known points (analogvalA, loadA) and (analogvalB, loadB). Draw a straight line through them. That sloping line represents what mapFloat is giving you.

To check your hand calculations, where does the sloping line intersect the vertical axis? It ought to be close to the load value that you calculated for analogval = 0.

So, how to use that graph to figure out what to do?

Well, what you really want is for the entire sloping line to move up or down on the graph (without changing the slope) so that it intersects the horizontal axis at analogval=96, right? That is, if you get an analogval = 96, the weight should be zero, right?

With a little bit of thought, you ought to be able to pick the correct "out_min" and "out_max" values to achieve that... :wink:

PS: and, after you go through that educational exercise, you might realize what moving the line vertically means, and think of an even simpler way...