![Joy-it SEN-HX711 Скачать руководство пользователя страница 4](http://html1.mh-extra.com/html/joy-it/sen-hx711/sen-hx711_quick-start-manual_2027378004.webp)
3.3 Code example
In the following code example, your load cell will first be calibrated and
then repeatedly outputs the currently measured value.
For calibration you need a known weight. Ideally, it should be half of the
maximum measurement weight.
The constant Calibration_Weight must be adjusted with the weight you
use for calibration. The weight is specified in grams.
#include "HX711.h"
// HX711 circuit wiring
const
int
LOADCELL_DOUT_PIN =
2
;
const
int
LOADCELL_SCK_PIN =
3
;
const
int
Calibration_Weight =
1000
;
HX711 scale;
void
setup
() {
Serial.begin(
57600
);
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
scale.set_scale();
scale.tare();
Serial.println(
"Calibration"
);
Serial.println(
"Put a known weight on the scale"
);
delay(
5000
);
float
x = scale.get_units(
10
);
x = x / Calibration_Weight;
scale.set_scale(x);
Serial.println(
"Calibration finished..."
);
delay(
3000
);
}
void
loop
() {
if
(scale.is_ready()) {
float
reading = scale.get_units(
10
);
Serial.print(
"HX711 reading: "
);
Serial.println(reading);
}
else
{
Serial.println(
"HX711 not found."
);
}
delay(
1000
);
}