Advertisement
gabbyshimoni

basicLoadCellExample

Apr 17th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. #include <HX711_ADC.h>
  2.  
  3. HX711_ADC LoadCell(4, 5); //HX711 constructor (dout pin, sck pin):
  4.  
  5. void setup() {
  6.   Serial.begin(9600); delay(10);
  7.   LoadCell.begin();
  8.   long stabilisingtime = 2000; // tare preciscion can be improved by adding a few seconds of stabilising time
  9.   LoadCell.start(stabilisingtime);
  10.   if (LoadCell.getTareTimeoutFlag()) {
  11.     Serial.println("Tare timeout, check MCU>HX711 wiring and pin designations");
  12.   }
  13.   else {
  14.     LoadCell.setCalFactor(1.0); // user set calibration value (float)
  15.     Serial.println("Startup + tare is complete");
  16.   }
  17.   LoadCell.setCalFactor(-400); // change this number based on your calibration test
  18. }
  19. void loop() {
  20.   LoadCell.update();
  21.   float loadVal = LoadCell.getData();
  22.   Serial.print("Load_cell output val: ");
  23.   Serial.println(loadVal);
  24.   delay(100);
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement