Advertisement
Toxicl16

Untitled

Jul 2nd, 2019
108
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <HX711_ADC.h> // https://github.com/olkal/HX711_ADC
  2. #include <Wire.h>
  3. #include <LiquidCrystal_I2C.h> // LiquidCrystal_I2C library
  4.  
  5. //Initialize the pins for the motor
  6. #define ENABLE 9
  7. #define DIRA 10
  8. #define DIRB 11
  9.  
  10. HX711_ADC LoadCell(4, 5); // parameters: dt pin, sck pin<span data-mce-type="bookmark" style="display: inline-block; width: 0px; overflow: hidden; line-height: 0;" class="mce_SELRES_start"></span>
  11. LiquidCrystal_I2C lcd(0x27,16,2); // 0x27 is the i2c address of the LCM1602 IIC v1 module (might differ)
  12. void setup() {
  13. LoadCell.begin(); // start connection to HX711
  14. LoadCell.start(2000); // load cells gets 2000ms of time to stabilize
  15. LoadCell.setCalFactor(400); // calibration factor for load cell => strongly dependent on your individual setup
  16. lcd.begin(); // begins connection to the LCD module
  17. lcd.backlight(); // turns on the backlight
  18. //---set pin direction for motors
  19. pinMode(ENABLE, OUTPUT);
  20. pinMode(DIRA, OUTPUT);
  21. pinMode(DIRB, OUTPUT);
  22. }
  23. void loop() {
  24. LoadCell.update(); // retrieves data from the load cell
  25. float i = LoadCell.getData(); // get output value
  26. lcd.setCursor(0, 0); // set cursor to first row
  27. lcd.print("Weight[g]:"); // print out to LCD
  28. lcd.setCursor(0, 1); // set cursor to secon row
  29. lcd.print(i); // print out the retrieved value to the second row
  30. if (i > 13.00) { // weight is greater than 13g
  31. digitalWrite(ENABLE, HIGH);
  32. digitalWrite(DIRA, HIGH);
  33. digitalWrite(DIRB, LOW);
  34. } else {
  35. digitalWrite(ENABLE, LOW);
  36. digitalWrite(DIRA, HIGH);
  37. digitalWrite(DIRB, LOW);
  38. }
  39. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement