Guest User

Untitled

a guest
Mar 24th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. #include "HX711.j"
  2.  
  3.  
  4. #define DOUT  3
  5. #define CLK  2
  6.  
  7. HX711 scale(DOUT, CLK);
  8.  
  9. //Change this calibration factor as per your load cell once it is found you many need to vary it in thousands
  10. float calibration_factor = -96650; //-106600 worked for my 40Kg max scale setup
  11.  
  12. //=============================================================================================
  13. //                         SETUP
  14. //=============================================================================================
  15. void setup() {
  16.   Serial.begin(9600);
  17.   Serial.println("HX711 Calibration");
  18.   Serial.println("Remove all weight from scale");
  19.   Serial.println("After readings begin, place known weight on scale");
  20.   Serial.println("Press a,s,d,f to increase calibration factor by 10,100,1000,10000 respectively");
  21.   Serial.println("Press z,x,c,v to decrease calibration factor by 10,100,1000,10000 respectively");
  22.   Serial.println("Press t for tare");
  23.   scale.set_scale();
  24.   scale.tare(); //Reset the scale to 0
  25.  
  26.   long zero_factor = scale.read_average(); //Get a baseline reading
  27.   Serial.print("Zero factor: "); //This can be used to remove the need to tare the scale. Useful in permanent scale projects.
  28.   Serial.println(zero_factor);
  29. }
  30.  
  31. //=============================================================================================
  32. //                         LOOP
  33. //=============================================================================================
  34. void loop() {
  35.  
  36.   scale.set_scale(calibration_factor); //Adjust to this calibration factor
  37.  
  38.   Serial.print("Reading: ");
  39.   Serial.print(scale.get_units(), 3);
  40.   Serial.print(" kg"); //Change this to kg and re-adjust the calibration factor if you follow SI units like a sane person
  41.   Serial.print(" calibration_factor: ");
  42.   Serial.print(calibration_factor);
  43.   Serial.println();
  44.  
  45.   if(Serial.available())
  46.   {
  47.     char temp = Serial.read();
  48.     if(temp == '+' || temp == 'a')
  49.       calibration_factor += 10;
  50.     else if(temp == '-' || temp == 'z')
  51.       calibration_factor -= 10;
  52.     else if(temp == 's')
  53.       calibration_factor += 100;  
  54.     else if(temp == 'x')
  55.       calibration_factor -= 100;  
  56.     else if(temp == 'd')
  57.       calibration_factor += 1000;  
  58.     else if(temp == 'c')
  59.       calibration_factor -= 1000;
  60.     else if(temp == 'f')
  61.       calibration_factor += 10000;  
  62.     else if(temp == 'v')
  63.       calibration_factor -= 10000;  
  64.     else if(temp == 't')
  65.       scale.tare();  //Reset the scale to zero
  66.   }
  67. }
Add Comment
Please, Sign In to add comment