Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: Real-time Force
- - Source Code compiled for: Arduino Uno
- - Source Code created on: 2024-01-05 00:54:37
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* My project involves connecting one end of a sample */
- /* to a load cell and the other end to the shaft, */
- /* moving the motor backward to make it break. I want */
- /* to see the force generated in the load cell in */
- /* real time. */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <Arduino.h>
- #include <EasyButton.h>
- #include <HX711.h>
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void measureForce(void);
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t PUSH_BUTTON_PIN = 2;
- const uint8_t LOAD_CELL_DATA_PIN = A0;
- const uint8_t LOAD_CELL_CLOCK_PIN = 3;
- /****** DEFINITION OF LIBRARY CLASS INSTANCES*****/
- EasyButton pushButton(PUSH_BUTTON_PIN);
- HX711 loadCell;
- /****** SYSTEM REQUIREMENTS *****/
- // SYSTEM REQUIREMENT 1: Real-time force measurement
- const float LOAD_CELL_CALIBRATION_FACTOR = 420.0983; // Calibration factor for load cell
- void setup(void)
- {
- // Initialize Serial for debugging purposes
- Serial.begin(115200);
- // Initialize the push button
- pushButton.begin();
- // Set up the button callbacks
- pushButton.onPressed([]() {
- Serial.println("Button pressed");
- });
- pushButton.onSequence(2, 1500, []() {
- Serial.println("Double click");
- });
- // Enable interrupt if supported
- if (pushButton.supportsInterrupt()) {
- pushButton.enableInterrupt([]() {
- pushButton.read();
- });
- Serial.println("Button will be used through interrupts");
- }
- // Set up the load cell
- loadCell.begin(LOAD_CELL_DATA_PIN, LOAD_CELL_CLOCK_PIN);
- loadCell.set_scale(LOAD_CELL_CALIBRATION_FACTOR);
- loadCell.tare();
- }
- void loop(void)
- {
- // Measure and print force in real-time
- measureForce();
- // Add delay if needed for real-time measurement
- // delay(100); // Adjust the delay time according to the desired update rate
- }
- void measureForce(void)
- {
- float force = loadCell.get_units();
- Serial.print("Force: ");
- Serial.print(force);
- Serial.println(" units");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement