Advertisement
Guest User

Untitled

a guest
Apr 20th, 2018
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. /*
  2. Setup your scale and start the sketch WITHOUT a weight on the scale
  3. Once readings are displayed place the weight on the scale
  4. Press +/- or a/z to adjust the calibration_factor until the output readings match the known weight
  5. Arduino pin 6 -> HX711 CLK
  6. Arduino pin 5 -> HX711 DOUT
  7. Arduino pin 5V -> HX711 VCC
  8. Arduino pin GND -> HX711 GND
  9. */
  10.  
  11. #include "HX711.h"
  12.  
  13. HX711 scale(5, 6);
  14.  
  15. int DC = 9;
  16. float calibration_factor = 2230; // this calibration factor is adjusted according to my load cell
  17. float units;
  18. float ounces;
  19.  
  20. void setup() {
  21. Serial.begin(9600);
  22. Serial.println("HX711 calibration sketch");
  23. Serial.println("Remove all weight from scale");
  24. Serial.println("After readings begin, place known weight on scale");
  25. Serial.println("Press + or a to increase calibration factor");
  26. Serial.println("Press - or z to decrease calibration factor");
  27.  
  28. scale.set_scale();
  29. scale.tare(); //Reset the scale to 0
  30.  
  31. long zero_factor = scale.read_average(); //Get a baseline reading
  32. Serial.print("Zero factor: "); //This can be used to remove the need to tare the scale. Useful in permanent scale projects.
  33. Serial.println(zero_factor);
  34. }
  35.  
  36. void loop() {
  37.  
  38. scale.set_scale(calibration_factor); //Adjust to this calibration factor
  39.  
  40. Serial.print("Reading: ");
  41. units = scale.get_units(), 10;
  42. ounces = units * 0.035274;
  43. if (units < 0)
  44. {
  45. digitalWrite(DC, HIGH);
  46. } else if (units > 226) {
  47. digitalWrite(DC, LOW);
  48. }
  49.  
  50. Serial.print(units);
  51. Serial.print(" grams");
  52. Serial.print(" calibration_factor: ");
  53. Serial.print(calibration_factor);
  54. Serial.println();
  55.  
  56. if(Serial.available())
  57. {
  58. char temp = Serial.read();
  59. if(temp == '+' || temp == 'a')
  60. calibration_factor += 1;
  61. else if(temp == '-' || temp == 'z')
  62. calibration_factor -= 1;
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement