calibration and smoothing

hii.

im doing a project that connected with a load sensor. while im still new with this arduino thing i just wanna know did calibration and smoothing are the same thing? because i need to calibrate the scale that fluctuated and seemed like it doesn't work when i use the calibration code but when i use smoothing code, it works well like what i needed. so, are they just the same thing?

Probably not.

The calilbration will tell you the load sensor voltage /load constant. eg so many volts/newton

The smoothing algorithm takes the 'jitter' out of the readings and converts it to a steady value.

Allan

thanks for your info. but how do i calibrate the sensor scale then?

calibration and smoothing are the same thing?

No, smoothing is averaging (a moving average) so that little spikes up & down or noise is filtered/smoothed so the readings don't jump up & down as much. If your readings are stable you don't need smoothing.

If you want to measure your weight you usually don't need smoothing (unless your setup is noisy) but if you are measuring wind speed you usually want to smooth because the wind speed can change from moment-to-moment and it's hard to get a meaningful reading without smoothing/averaging.

Calibration is a correlation or accuracy adjustment. For example, if you are measuring weight 100 pounds might read 85 on the analog-to-digital converter so your software needs to make the conversion from a reading of 85 to 100. (Those are just random made-up numbers.)

Typically with a basic straight-line you'll calibrate the offset at zero and adjust the gain/multiplication at the maximum point or at the point of maximum "interest". If you imagine the equation of a line, [u]y=mx+b[/u]. x is the "raw" reading, y is the result you see, m is the slope of the line, and b is the offset.

awanisshahrin:
but how do i calibrate the sensor scale then?

Get a bunch of objects of known mass, and take a reading of (as allanhurst says) maybe volts and mass for each. Plot a graph of those pairs and establish the relationship. Code a function to convert any voltage into the correct mass.

Below is my code when i use calibration code. My project is about egg weighing. But with arduino i used voltage as weighing scale which is the highest 2.5 volts represents 120 grams and of course with a load sensor to detect the load with the analog input 512. After identifying the scale, the egg will be sort to their grades which are Grade 1 until Grade 6. For example 2.5 volts will be in Grade 1 and so on based on egg's weight.
So, i need to know did my code wrong when using the calibration? because the sensor is not constant and sometime it went more than 512. I need the reading to be constant and accurate. I have tried so many times with the coding.

const int analoginpin = A0;
int sensorValue = 0;
int led1 = 8;
int led2 = 9;
int led3 = 10;
int led4 = 11;
int led5 = 12;
int led6 = 13;
int a = 427; int b = 512; int c = 341; int d = 426; int e = 255;
int f = 340; int g = 169; int h = 254; int i = 83; int j = 168;
int k = 1; int l = 82; int m = 0;


void setup() {

  Serial.begin(9600);
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(led5, OUTPUT);
  pinMode(led6, OUTPUT);

}

void loop() {

  // return value & function call
  sensorValue = Calibrating();

  // calculate the voltage
  float voltage = sensorValue * (2.5 / 512.0);

  Serial.print("Sensor = ");
  Serial.print(sensorValue);
  Serial.print("\t Voltage = ");
  Serial.print(voltage);
  Grading(); // function call

}

void Grading() {
  if (sensorValue >= a || sensorValue >= b) // represents egg weight above 85g up until 120g
  {

    Serial.println("\t  Grade = 1");
    digitalWrite(led1, HIGH);
    digitalWrite(led2, HIGH);
    digitalWrite(led3, HIGH);
    digitalWrite(led4, HIGH);
    digitalWrite(led5, HIGH);
    digitalWrite(led6, HIGH);

    delay(100);

    digitalWrite(led1, LOW);
    digitalWrite(led2, LOW);
    digitalWrite(led3, LOW);
    digitalWrite(led4, LOW);
    digitalWrite(led5, LOW);
    digitalWrite(led6, LOW);
  }
  else if (sensorValue >= c && sensorValue <= d) // represents egg weight between 75g-84.9g
  {

    Serial.println("\t  Grade = 2");
    digitalWrite(led1, HIGH);
    digitalWrite(led2, HIGH);
    digitalWrite(led3, HIGH);
    digitalWrite(led4, HIGH);
    digitalWrite(led5, HIGH);
    digitalWrite(led6, HIGH);

    delay(100);

    digitalWrite(led1, LOW);
    digitalWrite(led2, LOW);
    digitalWrite(led3, LOW);
    digitalWrite(led4, LOW);
    digitalWrite(led5, LOW);
    digitalWrite(led6, LOW);
  }
  else if (sensorValue >= e && sensorValue <= f) // represents egg weight between 65g-74.9g
  {

    Serial.println("\t  Grade = 3");
    digitalWrite(led1, HIGH);
    digitalWrite(led2, HIGH);
    digitalWrite(led3, HIGH);
    digitalWrite(led4, HIGH);
    digitalWrite(led5, HIGH);
    digitalWrite(led6, HIGH);

    delay(100);

    digitalWrite(led1, LOW);
    digitalWrite(led2, LOW);
    digitalWrite(led3, LOW);
    digitalWrite(led4, LOW);
    digitalWrite(led5, LOW);
    digitalWrite(led6, LOW);
  }
  else if (sensorValue >= g && sensorValue <= h)  // represents egg weight between 55g-64.9g
  {

    Serial.println("\t  Grade = 4");
    digitalWrite(led1, HIGH);
    digitalWrite(led2, HIGH);
    digitalWrite(led3, HIGH);
    digitalWrite(led4, HIGH);
    digitalWrite(led5, HIGH);
    digitalWrite(led6, HIGH);

    delay(100);

    digitalWrite(led1, LOW);
    digitalWrite(led2, LOW);
    digitalWrite(led3, LOW);
    digitalWrite(led4, LOW);
    digitalWrite(led5, LOW);
    digitalWrite(led6, LOW);
  }
  else if (sensorValue >= i && sensorValue <= j)  // represents egg weight between 45g-54.9g
  {

    Serial.println("\t  Grade= 5");
    digitalWrite(led1, HIGH);
    digitalWrite(led2, HIGH);
    digitalWrite(led3, HIGH);
    digitalWrite(led4, HIGH);
    digitalWrite(led5, HIGH);
    digitalWrite(led6, HIGH);

    delay(100);

    digitalWrite(led1, LOW);
    digitalWrite(led2, LOW);
    digitalWrite(led3, LOW);
    digitalWrite(led4, LOW);
    digitalWrite(led5, LOW);
    digitalWrite(led6, LOW);
  }
  else if (sensorValue >= k && sensorValue <= l)  // represents egg weight between 36g-44.9g
  {

    Serial.println("\t  Grade = 6");
    digitalWrite(led1, HIGH);
    digitalWrite(led2, HIGH);
    digitalWrite(led3, HIGH);
    digitalWrite(led4, HIGH);
    digitalWrite(led5, HIGH);
    digitalWrite(led6, HIGH);

    delay(100);

    digitalWrite(led1, LOW);
    digitalWrite(led2, LOW);
    digitalWrite(led3, LOW);
    digitalWrite(led4, LOW);
    digitalWrite(led5, LOW);
    digitalWrite(led6, LOW);
  }
  else if (sensorValue == m)  // no egg
  {

    Serial.println("\t  No egg");
    digitalWrite(led1, LOW);
    digitalWrite(led2, LOW);
    digitalWrite(led3, LOW);
    digitalWrite(led4, LOW);
    digitalWrite(led5, LOW);
    digitalWrite(led6, LOW);

    delay(100);
  }
}

int Calibrating() {

  int value;

  value = analogRead(analoginpin);

  if (value > m) { // record the maximum sensor value m=0
    m = value;
  }

  if (value < b) { // record the minimum sensor value b=512
    b = value;
  }
  
  return value;

}

DVDdoug:
No, smoothing is averaging (a moving average) so that little spikes up & down or noise is filtered/smoothed so the readings don't jump up & down as much. If your readings are stable you don't need smoothing.

If you want to measure your weight you usually don't need smoothing (unless your setup is noisy) but if you are measuring wind speed you usually want to smooth because the wind speed can change from moment-to-moment and it's hard to get a meaningful reading without smoothing/averaging.

Calibration is a correlation or accuracy adjustment. For example, if you are measuring weight 100 pounds might read 85 on the analog-to-digital converter so your software needs to make the conversion from a reading of 85 to 100. (Those are just random made-up numbers.)

Typically with a basic straight-line you'll calibrate the offset at zero and adjust the gain/multiplication at the maximum point or at the point of maximum "interest". If you imagine the equation of a line, [u]y=mx+b[/u]. x is the "raw" reading, y is the result you see, m is the slope of the line, and b is the offset.

yes i understand this. but i cant imagine how to do with the code. need some help.

awanisshahrin:
yes i understand this. but i cant imagine how to do with the code. need some help.

I told you: take readings for a whole lot of items of known mass (better yet, certified by the "egg commission" or whatever) and plot those. I'd do that in a separate program for simplicity. Then establish the relationship.

Then code a simple function in your main sketch to return mass=f(reading), which with luck will be a straight line and the y-offset and the slope are the parameters you put in the function, as DVDdoug said.

Every-now-and-then (every day, every week, who knows?) re-run the calibrate sketch and change the values in the main sketch if necessary.

manor_royal:
I told you: take readings for a whole lot of items of known mass (better yet, certified by the "egg commission" or whatever) and plot those. I'd do that in a separate program for simplicity. Then establish the relationship.

Then code a simple function in your main sketch to return mass=f(reading), which with luck will be a straight line and the y-offset and the slope are the parameters you put in the function, as DVDdoug said.

Every-now-and-then (every day, every week, who knows?) re-run the calibrate sketch and change the values in the main sketch if necessary.

can you check my code i put above? if u don't mind.

awanisshahrin:
can you check my code i put above? if u don't mind.

Explain in words how you think calibration() is doing any calibration.

And I'm at work now, busy day ahead, so may not be responding.

Do you have a link to your load sensor?

If you could get 0-1.1V range out of it then use the internal 1.1V reference, you could achieve 100% improvement in precision. The readings would also be more accurate and stable when using the internal reference.

How accurate, precise and stable do you need your readings?

dlloyd:
Do you have a link to your load sensor?

If you could get 0-1.1V range out of it then use the internal 1.1V reference, you could achieve 100% improvement in precision. The readings would also be more accurate and stable when using the internal reference.

How accurate, precise and stable do you need your readings?

dlloyd:
Do you have a link to your load sensor?

If you could get 0-1.1V range out of it then use the internal 1.1V reference, you could achieve 100% improvement in precision. The readings would also be more accurate and stable when using the internal reference.

How accurate, precise and stable do you need your readings?

Linked on the analog input A0 only.
I want it to be accurate not more than 0.01 volt. It means when the reading is 2.5 volt so it can't be less to 2.48 volt. It must be 2.49 volt. But what I got is not what I want.

I meant if you could post the web address where you purchased the load sensor or if you could let us know the part number?

dont know where my senior purchased. it's a custom made sensor he said.

Calibration isn't just limited to correlation accuracies of voltage measurements from sensors.

In general, as in the case for RF transmit powers, calibration would necessitate the use of external reliable sources of power sources and power sensors that enable frequency response and temperature correction data to be ascertained with a high degree of accuracy. Otherwise, if unreliable sensors are used, then, all attempts of calibration would be futile due to nonlinearities from the power sources and/or sensors which result in large deviations from expected performance. In other words, the choice of signal generator is just as important as the sensor component.

In addition, the environment temperature should not change by more than 1° between calibration and measurement.

Hmm. Load sensor custom, "He said" is this a work project ?

One clue is you say readings go above 512 which suggests the load sensor doesn't limit out at 2.5v as you think relative to you setting it to 512.