Calibration code help with Arduino due and INA125P

I am trying to compile a code that will calibrate and read a Honeywell load cell (model 31). I'm using a breadboard setup with a INA125P amplified and Arduino due. Below are the error codes I am receiving and the calibration code itself.

Potentiometer: In function 'void loop()'
Potentiometer:17: error: 'Lb' was not declared in this scope
Serial.print(Lb);
^
Potentiometer:18: error: 'calibration_factor' was not declared in this scope
Serial.print(calibration_factor);
^
Potentiometer:24: warning: unused variable 'temp'
char temp = Serial.read();
^
Potentiometer:25: error: 'temp' was not declared in this scope
if(temp == '+')
^
'Lb' was not declared in this scope

Below is the calibration code I am trying to run but am having trouble.

int sensorValue = analogRead(A0);

void setup()
{
// put your setup code here, to run once:

// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}

void loop() {
// put your main code here, to run repeatedly:

// read the input on analog pin 0:
Serial.print(analogRead(A0));
Serial.print(Lb);
Serial.print(calibration_factor);
// print out the value you read:
Serial.println(sensorValue);

if(Serial.available())

char temp = Serial.read();
if(temp == '+')
  calibration_factor += 20;
else if (temp == '-')
  calibration_factor -= 20;

// delay in between reads for stability
delay(1000);
}

I do not find Lb defined in the snippet of code you posted. Would it be too much trouble to fix the errors in your code first, before worrying about the calibration code?

Paul

Im new to coding. How would I define Lb?

That would be based on it's usage.
Paul

Lb is for pounds, which is the reading the loadcell will give.

The output from reading a load cell is usually an int. Did you write the program or just copy part of the program and miss the part that defines the variables?
Paul

The original code I used for a potentiometer. I was trying to edit it to be able to work with the load cell setup I have.

I have another calibration code for a Teensy 4.1 and HX711, which works fine.

I have not been able to work out the errors for the current one iv provided.

I have also tried to define the variable but just receive more errors. Maybe I just don't quite know what I'm doing. Again I'm a complete beginner to coding.

If you are so new to coding, how did you manage with the first program? Perhaps you should start over with that program. Have you tried using the load cell example programs? Do they work?
Paul

I got lucky with the two other programs. Yes, Iv tried other load cell example programs. Most of them are written for a Arduino Nano. They did not work. So far iv worked out a couple of the error codes. Iv narrowed it down to the ones below.

Potentiometer: In function 'void loop()':
Potentiometer:25: warning: unused variable 'temp'
char temp = Serial.read();
^
Potentiometer:26: error: 'temp' was not declared in this scope
if(temp == '+')
^
'temp' was not declared in this scope

1 Like

Find C++ documentation and review what "scope" means. When a variable is defined within a function, it BELONGS to that function and can be used in NO other function. It will disappear when that function ends.
Paul

I worked out the errors but I am not getting a serial monitor reading. The code is below,

int sensorValue = analogRead(A0);
int Lb = 0;
int calibration_factor = 100000;

void setup()
{
// put your setup code here, to run once:

// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}

void loop() {
// put your main code here, to run repeatedly:
Serial.print ("Reading: ");
// read the input on analog pin 0:
Serial.print(analogRead(A0));
Serial.print("Lb");
Serial.print("calibration_factor ");
// print out the value you read:
Serial.print(sensorValue);
Serial.println();
// delay in between reads for stability
delay(1000);

Unless you put the sensorValue=analogRead(A0); in a code function that will be executed, you will not get anything in sensorValue.
Make it the same as where you print the value returned by analogRead.
More over, the value you are getting is a only a number, it is NOT pounds. You have to compute that.
Paul

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.