风筝
发表于: 2019-8-20 07:14:24 | 显示全部楼层

在本篇文章中,您将了解称重传感器模块、其应用程序及其操作。此外,您将了解如何在Arduino中使用称重传感器模块。然后在了解了称重传感器的校准后,将制作一个可以测量重量的数字体重秤,精度为0.0001克,并且制作了一个测力计。


称重传感器基础知识

称重传感器是用于测量重量和力的电子传感器。当施加力时,其输出线上会出现毫伏级的弱电信号。事实上,称重传感器是一种将力转换为可测量的电输出的换能器。


称重传感器由金属芯和一组电阻组成,当施加力时,电阻会发生变形。但在移除力之后,它将返回其原始状态。这种材料的可逆性决定了称重传感器的质量和精度。称重传感器的等效电路如下:

Figure2-Load-cell-internal-circuite.jpg


称重传感器有4根电线:

●     红色线表示激励+

●     黑色线表示激励 -

●     白色线表示输出 -

●     绿色线表示输出+


所需的材料

●     Arduino UNO R3开发板

●     HX711秤重传感器

●     1602串行LCD模块

●     Arduino IDE

Loadcell.jpg


将称重传感器与Arduino连接

称重传感器产生的输出信号在毫伏范围内,因此我们需要一个放大器将信号转换为另一种电平信号,方便以后我们可以将其转换为数字信号并对其进行处理。为此,我们使用了HX711放大器传感器。 HX711放大器传感器包含一个HX711芯片,具有24位精度的模数转换功能。 HX711模块放大称重传感器的低压输出并将其发送到Arduino,以便Arduino最终根据该数据计算重量。

Untitled-1.jpg


电路连接

Figure-4-circuit1-1.png

注意:当您对称重传感器进行称重时,请注意称重传感器的侧面。通常,模块上有一个箭头,显示力方向。借助此箭头,您可以正确放置重量和称重传感器。


称重传感器校准

要使用称重传感器,首先需要校准它。为此,请在Arduino开发板上上传以下代码。等到读取消息显示在串行监视器上,然后在称重传感器上放置指定的重量物体。使用A键,您可以将calibration_factor增加一个单位,您可以使用Z键减小它以获得正确的重量。


代码

本篇文章的代码使用的是HX711库

  1. /*
  2. *  HX711 Calibration
  3. */
  4. /*
  5. Setup your scale and start the sketch WITHOUT a weight on the scale
  6. Once readings are displayed place the weight on the scale
  7. Press +/- or a/z to adjust the calibration_factor until the output readings match the known weight
  8. */

  9. #include "HX711.h"
  10. #define DOUT  4
  11. #define CLK  5
  12. HX711 scale(DOUT, CLK);

  13. float calibration_factor = 2230; // this calibration factor must be adjusted according to your load cell
  14. float units;
  15. void setup }()
  16.   Serial.begin(9600);
  17.   Serial.println("HX711 calibration sketch");
  18.   Serial.println("Remove all weight from scale");
  19.   Serial.println("After readings begin, place known weight on scale");
  20.   Serial.println("Press + or a to increase calibration factor");
  21.   Serial.println("Press - or z to decrease calibration factor");

  22.    scale.set_scale(calibration_factor); //Adjust to this calibration factor
  23.   scale.tare();  //Reset the scale to 0

  24.   long zero_factor = scale.read_average(); //Get a baseline reading
  25.   Serial.print("Zero factor: "); //This can be used to remove the need to tare the scale. Useful in permanent scale projects.
  26.   Serial.println(zero_factor);
  27. {
复制代码

set_scale();函数将用于刻度校准的calibration_factor设置为所需的值,tare(); 函数将其设置归零。

get_units(); 函数读取重量,如果小于零,则认为是零。


测量物体的重量

电路连接

FigureCircuit2.png

代码

  1. /*
  2. *  Digital Weighing Scale with Load Cell
  3. *  by Hanie kiani
  4. *  https://electropeak.com/learn/   
  5. */

  6. #include "HX711.h"  //You must have this library in your arduino library folder
  7. #include <LiquidCrystal.h>
  8. LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
  9. #define DOUT  4
  10. #define CLK  5

  11. HX711 scale(DOUT, CLK);

  12. float calibration_factor = 2230; // this calibration factor is adjusted according to my load cell
  13. float units;

  14. void setup() {
  15.   lcd.begin(16,2);
  16.   Serial.begin(9600);  
  17.   Serial.println("Press T to tare");
  18. scale.set_scale(calibration_factor); //Adjust to this calibration factor
  19.   scale.tare();
  20. }

  21. void loop() {
  22.   
  23. units = scale.get_units(), 5;
  24.   if (units < 0)
  25.   {
  26.     units = 0.00;
  27.   }
  28.   lcd.setCursor(0,0);
  29.   lcd.print("Weight: ");
  30.   lcd.setCursor(8,0);
  31.   lcd.print(units,5); //displays the weight in 4 decimal places only for calibration
  32.   lcd.setCursor(14,0);
  33.   lcd.print("grams");

  34.   if(Serial.available())
  35.   {
  36.     char temp = Serial.read();
  37.     if(temp == 't' || temp == 'T')
  38.       scale.tare();  //Reset the scale to zero      
  39.   }
  40. }
复制代码

制作一个测力计

您也可以使用称重传感器模块测量以牛顿为单位的力。为此,您可以在开发板上应用适当的calibration_factor后上传以下代码,并通过对称重传感器施加不同的力来查看结果。


将称重传感器放在平坦的表面上。 然后用手向传感器施加一个力。 您可以看到当您施加更大的力时,LCD上会显示更大的数字。


代码

  1. /*
  2. *  Digital Force Gauge with Loa d Cell
  3. *  by Hanie kiani
  4. *  https://electropeak.com/learn/
  5. */

  6. #include "HX711.h"  //You must have this library in your arduino library folder
  7. #include <LiquidCrystal.h>
  8. LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
  9. #define DOUT  4
  10. #define CLK  5
  11. HX711 scale(DOUT, CLK);

  12. float calibration_factor = 1; // this calibration factor is adjusted according to my load cell
  13. float units;

  14. void setup() {
  15.   lcd.begin(16,2);
  16.   Serial.begin(9600);  
  17.   Serial.println("Press T to tare");
  18. scale.set_scale(calibration_factor); //Adjust to this calibration factor
  19.   scale.tare();
  20. }


  21. void loop() {
  22.   
  23. units = scale.get_units(), 5;
  24.   if (units < 0)
  25.   {
  26.     units = 0.00;
  27.   }
  28.   lcd.setCursor(0,0);
  29.   lcd.print("Force: ");
  30.    Serial.print("Force: ");
  31.   lcd.setCursor(8,0);
  32.   lcd.print(units,5); //displays the weight in 4 decimal places only for calibration
  33.    Serial.print(units,5);
  34.   lcd.setCursor(14,0);
  35.   lcd.print("N");
  36.   Serial.print("N ");
  37. Serial.println();
  38. delay(2000);
  39.    
  40.    
  41.   if(Serial.available())
  42.   {
  43.     char temp = Serial.read();
  44.     if(temp == 't' || temp == 'T')
  45.       scale.tare();  //Reset the scale to zero      
  46.   }
  47. }
复制代码

以上就是本篇文章的全部内容。接下来,您可以做更多的尝试,例如通过在电路中添加电位器和旋转编码器,使用户可以更改测量单位。如果遇到问题,请随时在本帖下面进行回复。

跳转到指定楼层
byz1996
发表于: 2019-8-25 17:02:01 | 显示全部楼层

您好 这个校准的程序 要上传验证时 出现杂散问题 stray '\302' in program 怎么解决呀
回复

使用道具 举报

byz1996
发表于: 2019-9-18 15:38:10 | 显示全部楼层

总是提示我 HX711 scale(DOUT, CLK); 这句代码 302错误 有非法字符 我已经重新手敲也是这样
回复

使用道具 举报

仇梏
发表于: 2021-4-5 13:40:30 | 显示全部楼层

将(DOUT, CLK)删除,库函数里只有HX711 scale;,库函数默认DOUT链接Uno的3脚,CLK连2脚
回复

使用道具 举报

仇梏
发表于: 2021-4-5 13:40:51 | 显示全部楼层

byz1996 发表于 2019-9-18 15:38
总是提示我 HX711 scale(DOUT, CLK); 这句代码 302错误 有非法字符 我已经重新手敲也是这样 ...


将(DOUT, CLK)删除,库函数里只有HX711 scale;,库函数默认DOUT链接Uno的3脚,CLK连2脚
回复

使用道具 举报

ric
发表于: 2022-4-2 18:57:36 | 显示全部楼层

scale.set_scale(calibration_factor);一直报错是怎么回事
显示error: request for member 'set_scale' in 'scale', which is of non-class type 'HX711()'
感谢大佬提点
回复

使用道具 举报

风筝
发表于: 2022-4-6 08:48:25 | 显示全部楼层

ric 发表于 2022-4-2 18:57
scale.set_scale(calibration_factor);一直报错是怎么回事
显示error: request for member 'set_scale' in ...

没有相应的库文件呢
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题 700 | 回复: 1479



手机版|

GMT+8, 2024-3-29 08:18 , Processed in 0.108233 second(s), 9 queries , Gzip On, MemCache On. Powered by Discuz! X3.5

YiBoard一板网 © 2015-2022 地址:河北省石家庄市长安区高营大街 ( 冀ICP备18020117号 )

快速回复 返回顶部 返回列表