i am using HX711 module to get value from load cell.my projects is a tensile strength testing machine,which will increase the load gradually and break at its maximum capacity.therefore i need the maximum value at which the specimen breaks.and use that value in the code to calcuate the tensile strengh of the specimen using the formula(tensile strength=load/cross section area of specimen). Please help me with this and if possible ,i will be very gratefull if anyone can help me with the code too. Thank you
We won't write the code for you, since we are not a free coding service, but I will try to give you some hints, how you can do it.
Timing of measurements: The measurements themselves can be done with one of the HX711 libraries, that are available on the web, but you may want to time them to get more regular measurements. This can be done in a non-blocking coding style like in the
BlinkWithoutDelayexample, that comes with the Arduino IDE. It involves the
millis()function to measure the time since the last measurement and act accordingly. This is explained many times troughout the web and on this site.
Saving the data and finding the maximum: This depends on what else you want to do with the data.
Saving all data for later processing: You might want to save all data (the load curve) for later use. In this case you have to define an array of appropriate length (the length depends on the duration and frequency of the measurement). Also define a position variable or pointer, that marks the current position in this array. Everytime when you do a measurement, you save the result to the array element at the saved position and increment the position variable after that. After the end of the measurement, you declare a value variable with the value of the first array element. Then you loop through all the following elements (
for(int i=1;i<array_length;i++)). Inside the loop you calculate and save the maximum of 2 numbers: The value of the current array element and the saved variable. This can be done with
saved_value = max(saved_value, array[i]);. When the loop is finished, you will have the maximum value in the
No saving of data: You can also calculate a flying maximum without saving all data. Declare a variable (
max_value), that will hold the maximum value, and set it to zero. Then, everytime when you do a measurement, you execute
max_value = max(current_value, max_value);which calculates the maximum of the two numbers (current measurement and the previously calculated maximum). At the end of the measurement you will have the absolute maximum in the
Sensing the end of measurement: You need to sense the end of the measurement (when the specimen breaks) (though this can be done manually if you like). For this I would suggest to calculate the speed in which the load changes. During the measurement the load will increase slowly. In the moment of breaking the load will decrease very fast. The speed between two load measurments is calculated by
(value(x) - value(x-1))/measurement_interval. You can define a threshold of negative speed, so that every speed below it (faster negative decrease of load) will be sensed as breaking of specimen. You can check this on every measurement with a simple
ifstatement, or you can calculate the speed over more than 2 consecutive measurements. That depends on the actual speed of load change and the frequency of load measurements.
Calculating the tensile strength: This is just writing your formula into the code using the variable names, that you used in the previous code. Be sure to use the correct variable type for your needs. Most likely you would want to use
Getting input from user: This depends largely on your planned means of interaction with the user. Is the Arduino connected to a PC and you use a serial terminal program? Then you can use this for user input (You might want to look at the
SerialEventexample of the Arduino IDE, which shows how to work with messages and delimiter characters). Do you want to add a keypad and a LCD display? There are library available for these too, so it should not be very difficult to learn how to use then to get user input.