martinius96

HX711 - factor

Jun 14th, 2020 (edited)
1,354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //But me coffee: https://paypal.me/chlebovec
  2.  
  3. #include "HX711.h"
  4.  
  5. #define DOUT  3
  6. #define CLK  2
  7. HX711 scale;
  8.  
  9. float calibration_factor = -50.10; //KALIBRAČNÝ FAKTOR
  10. void setup() {
  11.   scale.begin(DOUT, CLK);
  12.   Serial.begin(115200);
  13.   Serial.println("HX711 calibration sketch");
  14.   Serial.println("Remove all weight from scale");
  15.   Serial.println("After readings begin, place known weight on scale");
  16.   Serial.println("Press + or a to increase calibration factor");
  17.   Serial.println("Press - or z to decrease calibration factor");
  18.  
  19.   scale.set_scale();
  20.   scale.tare(); //Reset the scale to 0
  21.  
  22.   long zero_factor = scale.read_average(); //Get a baseline reading
  23.   Serial.print("Zero factor: "); //This can be used to remove the need to tare the scale. Useful in permanent scale projects.
  24.   Serial.println(zero_factor);
  25. }
  26.  
  27. void loop() {
  28.   scale.set_scale(calibration_factor); //Adjust to this calibration factor
  29.   Serial.print("Reading: ");
  30.   Serial.print(scale.get_units(10), 2);
  31.   Serial.print(" g"); //Change this to kg and re-adjust the calibration factor if you follow SI units like a sane person
  32.   Serial.print(" calibration_factor: ");
  33.   Serial.print(calibration_factor);
  34.   Serial.println();
  35.  
  36.   if (Serial.available())
  37.   {
  38.   //LADENIE
  39.     char temp = Serial.read();
  40.     if (temp == '+' || temp == 'a')
  41.       calibration_factor += 0.1;
  42.     else if (temp == '-' || temp == 'z')
  43.       calibration_factor -= 0.1;
  44.   }
  45. }
Add Comment
Please, Sign In to add comment