Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to Integrate HX711 with ESP32 and Azure SDK C for Weight Capture? #2652

Open
vinugeorge175 opened this issue Oct 8, 2024 · 0 comments
Open
Labels

Comments

@vinugeorge175
Copy link

I'm working on a project where I need to capture the weight from an HX711 load cell connected to an ESP32 board and integrate the data with Azure IoT Hub using the Azure SDK for C.

I have already configured the iot_configs.h file correctly with the necessary Azure IoT settings.
The goal is to send the weight data captured from the HX711 sensor to Azure IoT Hub.
I’ve successfully connected the HX711 to the ESP32 and can read the weight, but I'm struggling to combine this with the Azure SDK C code to send the weight_In_g data as telemetry to Azure IoT central. Could anyone guide integrating the weight capture program with Azure SDK C? Any code examples or references would be greatly appreciated.

Hardware:
ESP32
HX711

Software:
Azure IoT Central
Arduino IDE Code

//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 03_Load_Cell_Sensor_5kg_Calibration
// In this step, the calibration value will be stored in the ESP32 flash memory.
// The calibration value in this step will be used in the next step.

//----------------------------------------Including the libraries.
#include "HX711.h"

//----------------------------------------Defines the connected PIN between HX711 and ESP32.
#define LOADCELL_DOUT_PIN 5
#define LOADCELL_SCK_PIN 18
//----------------------------------------

// Predefined calibration factor (set to 382 as per your requirement)
#define CALIBRATION_FACTOR 382

// Bool variable to display the weighing results.
bool show_Weighing_Results = false;

int weight_In_g; // Int variable to hold the value of the weighing results in units of grams (g).
float weight_In_oz; // Float variable to hold the value of the weighing results in units of ounce (oz).

// Initialize the HX711 library as LOADCELL_HX711.
HX711 LOADCELL_HX711;

//________________________________________________________________________________VOID SETUP()
void setup() {
// put your setup code here, to run once:

Serial.begin(115200);
Serial.println();
delay(2000);

Serial.println("Setup...");
delay(1000);

Serial.println();
Serial.println("Do not place any object or weight on the scale.");
delay(1000);

Serial.println();
Serial.println("LOADCELL_HX711 begin.");
LOADCELL_HX711.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);

// Set the predefined calibration factor directly
LOADCELL_HX711.set_scale(CALIBRATION_FACTOR);
delay(1000);

// Tare the scale
LOADCELL_HX711.tare();
Serial.println("Scale has been tared.");

show_Weighing_Results = true;
Serial.println();
Serial.println("The scales are ready to use.");
}
//________________________________________________________________________________

//________________________________________________________________________________VOID LOOP()
void loop() {
// put your main code here, to run repeatedly:

//----------------------------------------The condition for printing the results of weighing objects on the serial monitor after the calibration process is complete.
if (show_Weighing_Results == true) {
if (LOADCELL_HX711.is_ready()) {
// The value 10 in get_units(10) means getting the average value of 10 readings.
// For more details see in File -> Examples -> HX711 Arduino Library -> HX711_full_example

  // Get the reading of the object's weight in grams (g).
  weight_In_g = LOADCELL_HX711.get_units(10); 

  // Get the reading of the object's weight in ounces (oz).
  weight_In_oz = float(weight_In_g) / 28.34952;
  
  Serial.print("Weight : ");
  Serial.print(weight_In_g);
  Serial.print(" g");
  Serial.print(" | ");
  Serial.print(weight_In_oz, 2);
  Serial.println(" oz");
} else {
  Serial.println("HX711 not found.");
}

}
//----------------------------------------

delay(1000);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant