HX711 Weight Sensor
The HX711 module uses a 24-bit high-precision A/D converter chip, designed specifically for high-precision electronic scales. It features two analog input channels and integrates a 128-fold programmable amplifier with internal gain. The input circuit can be configured to provide a bridge voltage in bridge sensor mode (such as pressure or weighing sensors). This makes it an ideal high-precision, low-cost sampling front-end module.
Module Source
Purchase Link:
https://item.taobao.com/item.htm?spm=a21n57.1.0.0.19a3523cagvNPv&id=611254073645&ns=1&abbucket=0
Baidu Netdisk Download Link:
https://pan.baidu.com/s/1V2NdHCmvusPDhBp00VvIvQ
Password: j2sh
Specifications
Operating Voltage:2.6V-5.5V
Operating Current:100~1500uA
ADC Accuracy: 24-bit
Output Method: Serial Output
Pin Count: 4 Pins
Hardware Connection
- Connect the module's VCC and GND to the 5V and GND of the development board to power the module.
- Then, connect the HX711 module's DT (data line) and SCK (clock line). DT connects to pin 2, and SCK connects to pin 3.
- Finally, connect the load sensor to the HX711 module's input terminals. This typically includes the E+, E-, A+, and A- interfaces, and the connections should be made as shown in the diagram.
Usage Method
Install Library
To use the HX711 module and load sensor (weighing sensor) for data communication with the development board, you will need to use a dedicated library provided by HX711, typically the "HX711 Arduino Library
".
Enter the code:
/******************************************************************************
* Test Hardware: LCSC ColorEasyDuino Development Board
* Version Number: V1.0
* Modified By: www.lckfb.com
* Modification Date: April 9, 2024
* Function Overview:
*****************************************************************************
* Open-source development board hardware and software information and related projects hardware and software information on official website
* Development board official website: www.lckfb.com
* Technical support resident forum, any technical problems are welcome at any time to exchange learning
* LCSC Forum: club.szlcsc.com
* Follow our Bilibili account: [立创开发板], stay toned to our latest news!
* We focus on cultivating Chinese engineers rather than profiting from board sales.
******************************************************************************/
#include "HX711.h"
// 为HX711定义数据接入点和时钟接入点
#define LOADCELL_DOUT_PIN 2
#define LOADCELL_SCK_PIN 3
//校准参数
//因为不同的传感器特性曲线不是很一致,因此,每一个传感器需要矫正这里这个参数才能使测量值很准确。
//当发现测试出来的重量偏大时,增加该数值。
//如果测试出来的重量偏小时,减小改数值。
//该值可以为小数
#define GapValue 208.05
HX711 scale;
void setup() {
Serial.begin(9600);
Serial.println("HX711 scale demo");
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
// 这里需要调整以匹配你的具体硬件设置
scale.set_scale(GapValue); // 这个校准因子是一个例子,你需要调整它
scale.tare(); // 重置秤,忽略已有的重量,仅测量后加上去的重量
}
void loop() {
if (scale.is_ready()) {
float weight = scale.get_units(5); //连续读取5次 或者可以用scale.get_units()获取单个测量值
Serial.print("Weight: ");
Serial.print(weight, 2); // 减小到两位小数
Serial.println(" g");
} else {
Serial.println("HX711 not ready");
}
delay(1000);
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
Usage Testing
Place a 200g weight for measurement. Note that you will need to adjust the calibration parameter GapValue until the measured weight is close to the actual weight. This will ensure accuracy when measuring other objects. The calibration parameter used in the example is based on my own testing results.