Load Sensor 50 Kg

Good morning everybody I'm having some Issues trying to undertand this code:

float loadA = 10; // kg
int analogvalA = 200; // analog reading taken with load A on the load cell

float loadB = 30; // kg
int analogvalB = 600; // 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;

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;

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

    Serial.print("analogValue: ");Serial.println(analogValueAverage);
    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;
}

The issue part is this

float loadA = 10; // kg
int analogvalA = 200; // analog reading taken with load A on the load cell
float loadB = 30; // kg
int analogvalB = 600; // analog reading taken with load B on the load cell

Did't know where the value of 200 and 600 is obtained and I suppouse the load sensor of this proyect was of 40 Kg ; 10 kg is exitation (+) and 30 is exitation (-) I think...

It seems to me that they are numbers for a calibration test.

You test the device with two known masses, see what analog reading you get, and then edit the sketch to put the numbers which you obtained from your test on your hardware into those variables. The sketch will then interpolate between them somehow.

3SPIN3T3:
The issue part is this

float loadA = 10; // kg

int analogvalA = 200; // analog reading taken with load A on the load cell
float loadB = 30; // kg
int analogvalB = 600; // analog reading taken with load B on the load cell




Did't know where the value of 200 and 600 is obtained and I suppouse the load sensor of this proyect was of 40 Kg ; 10 kg is exitation (+) and 30 is exitation (-) I think...

Those values are the calibration values obtained using loadA (10kg) and loadB (30kg). Since strain gauges are linear devices, they behave linearly, thus indicating that changes in weights/loads would reflect a linear change in the analog readings. This would also imply that you can map/distribute the load range along the analog range.

You can upload the code to the Arduino prior to calibration. Initially, you just need to connect your load cell amplifier circuit to arduino, put the 2 known weights and get their analog readings. In your circuit, you can modify the gain of the amplifier in order to maximize the analog scale, preferrably near the limits but excluding the limit values (0 and 1023). So in your calibration test, you can initially use a KNOWN load (example: 1kg) for the lower limit calibration and put it on the load cell. the analog value that you will read will be used here:
float loadA = 1; // your known load (in kg)
int analogvalA = xxx //replace the analog value

NOTE: do not upload the modified code yet, you need to have the analog readings for the upper limit too.

for your upper limit calibration, you will need another KNOWN weight, heavier than the first one (ex: 20kg). Get the analog value and replace the value here:
float loadB = 20; // kg
int analogvalB = xxxx; // analog reading taken with load B on the load cell

You may upload the final code then, it will yield a calibrated map of the weights along the analog scale. Please note that it would be better to use a known load (regardless of how light it is, as long as you can get readings) for the lower limit instead of using zero (no load) though it would give 0 reading too, this would somehow be less accurate. :slight_smile: The only thing that may be hard to do here is to acquire test loads with known weight, as these are usually available only in laboratories/machine shops. One workaround for this is to get a calibrated weighing scale/balance and get the actual weights of the test loads that you want to use. Another note, though your sensor has a 50kg capacity, you can use a known load that is lower than the maximum capacity of the beam for your upper limit calibration. It would still be accurate.

Thanks this information is really helpfull!!
Now I had another question a dummy question... jeje

it is possible make with this sensor Load Cell from SparkFun make a Luggage scale?? something like this

Sparkfun’s load cell is a cantilever type, which requires top loading instead of using the principle that the spring scale works. however, you can make something like this:

where the weight ouput will be displayed on LCD instead of having a dial which will rotate in response to the weight.

But if you insist of designing a spring scale-type, you may still do so, you just need to find a way how to make the load cell work by hanging loads instead of putting something on top. Though your project would tend to be less compact that way. :slight_smile:

By the way, if you want higher resolution weighing scale, try looking on HX711 module. That one is specifically designed for load cells. I have tried it, as well as the INA122 and INA125. Using HX711 is much better, as for my opinion, of course. But calibrating is difficult, unlike on using INA's :slight_smile: