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

``````float loadA = 10; // kg

float loadB = 30; // kg

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() {

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

// Is it time to print?

Serial.print("analogValue: ");Serial.println(analogValueAverage);
time = millis();
}
}

// using a custom map-function, because the standard arduino map function only uses int
}

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
float loadB = 30; // kg
``````

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
``````

float loadB = 30; // kg

``````

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:
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