-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcalibrate.ino
59 lines (55 loc) · 1.24 KB
/
calibrate.ino
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
#include "HX711.h"
// HX711 circuit wiring
const int LOADCELL_DOUT_PIN = 2;
const int LOADCELL_SCK_PIN = 3;
HX711 scale;
String weight;
void setup() {
Serial.begin(57600);
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
// Initialization
scale.set_scale();
scale.tare();
Serial.println("Place a known weight on the scale and enter the weight value in grams.");
Serial.print("Enter weight value: ");
while (!Serial.available())
{
if (Serial.available())
{
weight = Serial.readString();
delay(500);
Serial.println(weight + " g.");
break;
}
}
}
void loop()
{
if (scale.is_ready())
{
long reading = scale.get_units(10);
double factor = 0;
for (int i = 0; i <= 10; i++)
{
Serial.print("HX711 reading: ");
Serial.println(reading);
Serial.print("Factor to enter into the set_scale: ");
if (i == 0)
{
factor = double(reading) / double(weight.toFloat());
}
else
{
factor = (factor + double(reading) / double(weight.toFloat())) / 2;
}
Serial.println(factor);
delay(1000);
}
}
else
{
Serial.println("HX711 not found.");
}
while (1)
{}
}