This circuit is designed to read data from three HX711 weighing sensor modules connected to load cells and an ESP32 microcontroller. The ESP32 reads the data from each HX711 module, converts it to grams, and prints it to the serial monitor. Additionally, the ESP32 connects to a WiFi network to potentially send data to a remote server.
HX711 Weighing Sensor Module
ESP32 (30 pin)
Load Cell - Red/white/black/green
/*
* This Arduino Sketch is for an ESP32 microcontroller that reads data from
* three HX711 weighing sensor modules connected to load cells. The data
* from each HX711 module is read, converted to grams, and printed to the
* serial monitor. In addition, the ESP32 connects to a provided internet
* network. The program should always start to tare, getting the 3 scales
* to a zero value before providing the readings.
*/
#include "HX711.h"
#include <WiFi.h>
#include <FirebaseESP32.h>
// Pin definitions for HX711 modules
#define LOADCELL_DOUT1 32
#define LOADCELL_SCK1 33
#define LOADCELL_DOUT2 25
#define LOADCELL_SCK2 26
#define LOADCELL_DOUT3 13
#define LOADCELL_SCK3 27
// WiFi credentials
#define WIFI_SSID "SmartMeds"
#define WIFI_PASSWORD "SmartMeds"
// Calibration factors for each scale
#define CALIBRATION_FACTOR1 2280.0
#define CALIBRATION_FACTOR2 2280.0
#define CALIBRATION_FACTOR3 2280.0
// Create HX711 objects
HX711 scale1;
HX711 scale2;
HX711 scale3;
void setup() {
Serial.begin(115200);
// Initialize HX711 modules
scale1.begin(LOADCELL_DOUT1, LOADCELL_SCK1);
scale2.begin(LOADCELL_DOUT2, LOADCELL_SCK2);
scale3.begin(LOADCELL_DOUT3, LOADCELL_SCK3);
// Set calibration factors
scale1.set_scale(CALIBRATION_FACTOR1);
scale2.set_scale(CALIBRATION_FACTOR2);
scale3.set_scale(CALIBRATION_FACTOR3);
// Tare scales to zero
scale1.tare();
scale2.tare();
scale3.tare();
// Connect to WiFi
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
}
void loop() {
// Read and print data from each HX711 module
if (scale1.is_ready()) {
float weight1 = scale1.get_units();
Serial.print("Scale 1: ");
Serial.print(weight1);
Serial.println(" g");
} else {
Serial.println("Scale 1 not found.");
}
if (scale2.is_ready()) {
float weight2 = scale2.get_units();
Serial.print("Scale 2: ");
Serial.print(weight2);
Serial.println(" g");
} else {
Serial.println("Scale 2 not found.");
}
if (scale3.is_ready()) {
float weight3 = scale3.get_units();
Serial.print("Scale 3: ");
Serial.print(weight3);
Serial.println(" g");
} else {
Serial.println("Scale 3 not found.");
}
delay(2500); // Wait for 2 seconds before next read
}
This code initializes the HX711 modules, sets their calibration factors, tares the scales, and connects the ESP32 to a WiFi network. In the main loop, it reads the weight data from each HX711 module and prints it to the serial monitor.