ผมลองต่อ Loadcell แล้วให้ขึ้นข้อมูลที่จอ lcd แล้วค่าไม่นิ่งครับ
อันนี้คือโค้ดที่ผมใช้ อยากทราบวิธีแก้อะครับ
// (c) Michael Schoeffler 2017, http://www.mschoeffler.de
#include <HX711_ADC.h> // https://github.com/olkal/HX711_ADC
#include <Wire.h>
#include <LiquidCrystal_PCF8574.h> // LiquidCrystal_I2C library
HX711_ADC LoadCell(4, 5); // parameters: dt pin, sck pin<span data-mce-type="bookmark" style="display: inline-block; width: 0px; overflow: hidden; line-height: 0;" class="mce_SELRES_start"></span>
LiquidCrystal_PCF8574 lcd(0x27); // 0x27 is the i2c address of the LCM1602 IIC v1 module (might differ)
void setup() {
LoadCell.begin(); // start connection to HX711
LoadCell.start(1000); // load cells gets 2000ms of time to stabilize
LoadCell.setCalFactor(422.6); // calibration factor for load cell => strongly dependent on your individual setup
lcd.begin(16, 2); // begins connection to the LCD module
lcd.setBacklight(127); // turns on the backlight
}
void loop() {
LoadCell.update(); // retrieves data from the load cell
int i = LoadCell.getData(); // get output value
lcd.setCursor(0, 0); // set cursor to first row
lcd.print("Weight[g]:"); // print out to LCD
lcd.setCursor(0, 1); // set cursor to secon row
lcd.print(i); // print out the retrieved value to the second row
}
เช็คว่ากำหนดค่า factor ถูก้องแล้ว
มีโคดตัวอย่างของที่ร้าน ในคอร์สเรียน Arduino Starter ที่หน้าเว็บครับ
ขอบคุณครับได้แล้วครับแล้วถ้าผมอยากจะให้ servo ทำงานหลังจากชั่งผมจะเขียนคำสั่งยังไง เช่น ให้น้ำหนัก 65 กรัม servo หมุน90 องศาอะครับ
#include <HX711_ADC.h> // https://github.com/olkal/HX711_ADC
#include <Wire.h>
#include <Servo.h>
#include <LiquidCrystal_PCF8574.h> // LiquidCrystal_I2C library
HX711_ADC LoadCell(4, 5); // parameters: dt pin, sck pin<span data-mce-type="bookmark" style="display: inline-block; width: 0px; overflow: hidden; line-height: 0;" class="mce_SELRES_start"></span>
LiquidCrystal_PCF8574 lcd(0x27); // 0x27 is the i2c address of the LCM1602 IIC v1 module (might differ)
Servo servo1;
Servo servo2;
int pos = 0;
void setup() {
LoadCell.begin(); // start connection to HX711
LoadCell.start(1000); // load cells gets 2000ms of time to stabilize
LoadCell.setCalFactor(416.0); // calibration factor for load cell => strongly dependent on your individual setup
lcd.begin(16, 2); // begins connection to the LCD module
lcd.setBacklight(127); // turns on the backlight
servo1.attach(9);
servo2.attach(10);
}
void loop() {
LoadCell.update();
int i = LoadCell.getData();
lcd.setCursor(0, 0); // set cursor to first row
lcd.print("Weight[g]:"); // print out to LCD
lcd.setCursor(0, 1); // set cursor to secon row
lcd.print(i); // print out the retrieved value to the second row
if(i>=64){
LoadCell.update();
int i = LoadCell.getData();
servo1.write(90);
delay(1000);
lcd.setCursor(0, 0); // set cursor to first row
lcd.print("Weight[g]:"); // print out to LCD
lcd.setCursor(0, 1); // set cursor to secon row
lcd.print(i); // print out the retrieved value to the second row
}
}
สำหรับการเขียนโปรแกรม มีแนะนำในคอร์ส Arduino Starter ที่หน้าเว็บด้านบนซ้าย ลองเล่นดูครับ
วางของแล้วค่าน้ำหนักไม่เปลี่ยนค่ะ