Hello, I have a project and in this project, I want to find the center of gravity by making the connection as shown in the figure with 4 load cells that I will place on the bottom of a box. How can I write the code required for this project?
I moved your topic to an appropriate forum category @utkumco1.
In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.
This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.
Thanks in advance for your cooperation.
"Ground" perfectly level...????
Probably best to start with learning how to code for one hx711 and move up.
make a drawing, what you try to build.
Say your load cells are at the 4 corners (A,B,C,D) of a homogeneous plate โ a rectangle area of width W and length L, laying flat, at rest (only gravity applies on the load cells)
Lets define a cartesian coordinate system in A, then you have the positions of the corners :
- Load cell A at (0, 0)
- Load cell B at (L, 0)
- Load cell C at (0, W)
- Load cell D at (L, W)
With code, you can measure the forces exerted on those load cells, let's call them FAโ for the force in A, FBโ in B, FCโ in C and FDโ in D and let the total force be Ftotalโ = FAโ + FBโ + FCโ + FDโ
You can find the coordinates of the of the projection of the Center of Gravity (cog ) into the plate with the formulas
Xcog = L * (FBโ + FDโ) / Ftotalโ
Ycog = W * (FCโ + FDโ) / Ftotalโ
make sure you use the right International System of Units : Newtons for the forces and meters for W and L
#include "HX711.h"
#define LOADCELL_DOUT_PIN_1 3
#define LOADCELL_SCK_PIN_1 2
#define LOADCELL_DOUT_PIN_2 5
#define LOADCELL_SCK_PIN_2 4
#define LOADCELL_DOUT_PIN_3 7
#define LOADCELL_SCK_PIN_3 6
#define LOADCELL_DOUT_PIN_4 9
#define LOADCELL_SCK_PIN_4 8
HX711 scale1;
HX711 scale2;
HX711 scale3;
HX711 scale4;
void setup() {
Serial.begin(9600);
scale1.begin(LOADCELL_DOUT_PIN_1, LOADCELL_SCK_PIN_1);
scale2.begin(LOADCELL_DOUT_PIN_2, LOADCELL_SCK_PIN_2);
scale3.begin(LOADCELL_DOUT_PIN_3, LOADCELL_SCK_PIN_3);
scale4.begin(LOADCELL_DOUT_PIN_4, LOADCELL_SCK_PIN_4);
scale1.set_scale();
scale2.set_scale();
scale3.set_scale();
scale4.set_scale();
scale1.tare();
scale2.tare();
scale3.tare();
scale4.tare();
}
void loop() {
float weight1 = scale1.get_units(10);
float weight2 = scale2.get_units(10);
float weight3 = scale3.get_units(10);
float weight4 = scale4.get_units(10);
float totalWeight = weight1 + weight2 + weight3 + weight4;
float x_center = (weight1 * -x1 + weight2 * x2 + weight3 * -x3 + weight4 * x4) / totalWeight;
float y_center = (weight1 * -y1 + weight2 * y2 + weight3 * y3 + weight4 * -y4) / totalWeight;
Serial.print("Total Weight: ");
Serial.println(totalWeight);
Serial.print("X Center: ");
Serial.println(x_center);
Serial.print("Y Center: ");
Serial.println(y_center);
delay(1000);
}
Do you think this code could work?
it would not even compile, so no
(but the idea is there)
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
