arduino - Arduino 上的重量读数为 404.6kg
问题描述
我正在使用下面的代码对我的 Arduino 进行编程以制作体重秤。当秤上没有重量时,它的读数为-404.6kg。当我增加重量时,增加是正确的,即当我增加 3kg 时增加是 3kg,依此类推,请参见屏幕截图。我想在我的代码中添加一行,将 404.6kg 添加到称重传感器读数中。我该怎么做?
#include "HX711.h"
#define LOADCELL_DOUT_PIN 23
#define LOADCELL_SCK_PIN 22
HX711 scale;
float calibration_factor = -20600;
void setup() {
Serial.begin(9600);
// Serial.println("HX711 calibration sketch");
// Serial.println("Remove all weight from scale");
// Serial.println("After readings begin, place known weight on scale");
// Serial.println("Press + or a to increase calibration factor");
// Serial.println("Press - or z to decrease calibration factor");
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
scale.set_scale();
scale.tare(); //Reset the scale to 0
long zero_factor = scale.read_average(); //Get a baseline reading
Serial.print("Zero factor: "); //This can be used to remove the need to tare the scale.
Serial.println(zero_factor);
}
void loop() {
scale.set_scale(calibration_factor); //Adjust to this calibration factor
Serial.print("Reading: ");
Serial.print(scale.get_units(), 1);
Serial.print(" Kgs"); //Change this to kg and re-adjust the calibration factor if you follow SI units like a sane person
Serial.print(" calibration_factor: ");
Serial.print(calibration_factor);
Serial.println();
delay(1000);
if(Serial.available())
{
char temp = Serial.read();
if(temp == '+' || temp == 'a')
calibration_factor += 10;
else if(temp == '-' || temp == 'z')
calibration_factor -= 10;
}
}
解决方案
看起来您需要在calibration_factor
此处调整变量。我查看了芯片的库,在标题 [1] 的顶部看到了这条评论:
Setup your scale and start the sketch WITHOUT a weight on the scale
Once readings are displayed place the weight on the scale
Press +/- or a/z to adjust the calibration_factor until the output readings match the known weight
并在稍后的代码中定义它:
float calibration_factor = 2125; //-7050 worked for my 440lb max scale setup
所以看起来你应该调整这个值,直到你得到一个正确校准和归零的读数。
编辑:我找到了一个教程[2],它更多地讨论了如何校准传感器,它还建议通过反复试验来找到正确的数字。我不知道calibration_factor的单位是什么,或者数字本身代表什么——但调整它应该可以满足你的需求。
祝你好运!
[1] 我在哪里看到评论: https ://gist.github.com/matt448/14d118e2fc5b6217da11
[2] 在此处查找有关校准传感器的部分: https ://circuits4you.com/2016/11/25/hx711-arduino-load-cell/
推荐阅读
- c# - 将唯一值从 EF 插入数据库
- python - 使用条件从 df 创建列表
- python - 如何在不更改自动立即字段的情况下更新字段?
- visual-studio-2017 - 无法安装 Microsoft Analysis Sevrices Projects 扩展 vs2017
- neo4j - 如果 CASE 在 Cypher 中是这样那样,我如何添加另一个 MATCH 条件
- python - 将 python 模块的终端输出打印到 tkinter 标签中
- javascript - 由于错误,我的 Vue 应用程序无法安装:未捕获的 DOMException:无法在“元素”上执行“setAttribute”:“)”不是有效的属性名称
- azure-devops - 列出 ADO 的所有用户权利
- flyway - FlywayException:不支持的数据库:MariaDB 10.4
- css - 如何修复 svg CSS 动画?