Advertisement
pleasedontcode

Load Cell Setup rev_01

Mar 18th, 2024
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: Load Cell Setup
  13.     - Source Code compiled for: Arduino Mega
  14.     - Source Code created on: 2024-03-18 21:58:39
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Impact force sensor with high sample rate using a */
  21.     /* load cell and a HX711 amplifier */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24. /****** DEFINITION OF LIBRARIES *****/
  25. #include <HX711.h>
  26. #include <EasyButton.h>
  27.  
  28. /****** FUNCTION PROTOTYPES *****/
  29. void setup(void);
  30. void loop(void);
  31.  
  32. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  33. const uint8_t HX711_PushButton_PIN_D2 = 2;
  34. const uint8_t HX711_DOUT = 3;
  35. const uint8_t HX711_CLK = 4;
  36.  
  37. /****** DEFINITION OF LIBRARIES CLASS INSTANCES *****/
  38. HX711 hx711;
  39. EasyButton button(HX711_PushButton_PIN_D2);
  40.  
  41. void setup(void)
  42. {
  43.   // put your setup code here, to run once:
  44.  
  45.   hx711.begin(HX711_PushButton_PIN_D2, HX711_DOUT); // Initializing HX711
  46.  
  47.   // Calibrating the HX711
  48.   hx711.tare(10);
  49.   hx711.set_scale();
  50.  
  51.   pinMode(HX711_PushButton_PIN_D2, INPUT_PULLUP);
  52.  
  53.   button.begin(); // Initiating the EasyButton instance
  54. }
  55.  
  56. void loop(void)
  57. {
  58.   // put your main code here, to run repeatedly:
  59.  
  60.   button.read(); // Refreshing the state of the button instance
  61.  
  62.   long force = hx711.get_units(10); // Read force value in units
  63.  
  64.   if (force > 100) {
  65.     // Perform impact force handling here
  66.     // ...
  67.   }
  68. }
  69.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement