b. 임베디드/아두이노

[아두이노] HX711 로드셀을 이용한 무게측정하기

로봇쟁이 2018. 8. 2. 09:32

HX711은 로드셀을 회로적으로는 휘스톤 브릿지를 이용하여 ADC 데이터로 변환해주는 IC입니다.
연결방법은 로드셀의 색깔대로 연결하면 되고 HX711 드라이버는 이렇게 보통 생겼습니다.




로드셀과 연결하는 방법은


Excitation+ (E+) or VCC 는 빨강
Excitation- (E-) or ground 는 검정
Output+ (O+), Signal+ (S+)+ or Amplifier+ (A+) 는 흰색
O-, S-, or A- 는 초록 아니면 파랑

간혹 E+ E- A- A+ B- B+ 이렇게 핀으로 나와 있는 드라이버가 있습니다.
해당 드라이버는 아래처럼 연결하면 됩니다







해당 라이브러리를 사용하여 아래에 있는 코드를 적용하시면 좀 더 정확한 데이터를 받아 볼수 있습니다.



HX711-master.zip

 

1
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "HX711.h"
 
#define DOUT  5
#define CLK  4
 
HX711 scale(DOUT, CLK);
 
float calibration_factor = -12170//=100g
float output;
int readIndex;
float total=0;
float average=0;
float average_last=0;
const int cycles=20;
float readings[cycles];
 
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.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: ");
     output=scale.get_units(), 2;
     Serial.print(output);
     
     total = total - readings[readIndex];
     readings[readIndex] = scale.get_units(), 2;
     total = total + readings[readIndex];
     readIndex = readIndex + 1;
     
     if (readIndex >= cycles) {
          readIndex = 0;
     }
     average = total / cycles;
     
     average=scale.get_units(), 2;
     
     
     if((average_last>average+0.03 || average_last<average-0.03)){
          if (average<0.06) {
               average=0;
          }
          Serial.print("\tFilter: ");
          Serial.print(average);
          average_last=average;
     }
     else{
          Serial.print("\tFilter: ");
          Serial.print(average_last);
     }
     Serial.print(" g"); 
     Serial.print(" calibration_factor: ");
     Serial.print(calibration_factor);
     Serial.println();
     
     if(Serial.available()) {
          char temp = Serial.read();
          if(temp == '+' || temp == 'a')
               calibration_factor += 10;
          else if(temp == '-' || temp == 'z')
               calibration_factor -= 10;
     }
}
cs



저는 미세무게를 측정하기 위해서 100g짜리 로드셀로 실험해보니 잘 동작하는걸 확인하였습니다. 


참 쉽죠? 


반응형