Advertisement
Guest User

Untitled

a guest
Nov 13th, 2020
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. #include "HX711.h"
  2.  
  3. #define DOUT 3
  4. #define CLK 2
  5.  
  6. HX711 scale;
  7.  
  8. float calibration_factor = -7050; //-7050 worked for my 440lb max scale setup
  9.  
  10. void setup() {
  11. Serial.begin(9600);
  12. Serial.println("HX711 calibration sketch");
  13. Serial.println("Remove all weight from scale");
  14. Serial.println("After readings begin, place known weight on scale");
  15. Serial.println("Press + or a to increase calibration factor");
  16. Serial.println("Press - or z to decrease calibration factor");
  17.  
  18. scale.begin(DOUT, CLK);
  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.  
  29. scale.set_scale(calibration_factor); //Adjust to this calibration factor
  30.  
  31. Serial.print("Reading: ");
  32. Serial.print(scale.get_units(), 1);
  33. Serial.print(" kg"); //Change this to kg and re-adjust the calibration factor if you follow SI units like a sane person
  34. Serial.print(" calibration_factor: ");
  35. Serial.print(calibration_factor);
  36. Serial.println();
  37.  
  38. if(Serial.available())
  39. {
  40. char temp = Serial.read();
  41. if(temp == '+' || temp == 'a')
  42. calibration_factor += 10;
  43. else if(temp == '-' || temp == 'z')
  44. calibration_factor -= 10;
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement