Hello everyone,
I’m trying to build a digital scale that will upload data to a database so I can monitor the stock levels of a specific part over time. I’m using four 50kg load cells, an HX711, and an ESP32-S3 DevKitC-1.
I assembled everything following the diagram below, where you can see both the theory and an actual photo of the setup, including all the connections.
However, the readings are very strange. I ran some tests I found in other posts, and one of them was to measure the resistance between the wires of the load cells. Here are the results, using a multimeter set to 20k ohms:
Top left
20k - 1.97 (black-white)
20k - 0.98 (black-red)
20k - 0.98 (red-white)
Bottom left
20k - 1.97 (black-white)
20k - 0.98 (black-red)
20k - 0.98 (red-white)
Bottom right
20k - 1.97 (black-white)
20k - 0.98 (black-red)
20k - 0.98 (red-white)
Top right
20k - 1.97 (black-white)
20k - 0.98 (black-red)
20k - 0.98 (red-white)
From what I understood in another post, the red wire should be the one connected to E+ E- A+ A-.
I’ve redone all the connections between the load cells, and also between the HX711 and the ESP32, but I still can’t figure out what’s going on. I’ll also share the code I’m using. I’m begging for any help to get this project working.
Top Right is the A+, Botom Right E+, Botom Left A-, Top Left E-
I've tried to power the sistem with a apple charger and the usb port from my laptop.
It is my first project, plz hope u understand.
If you need any additional information, photos, or anything else, just let me know and I’ll be glad to share it right away.
Code: #include <HX711_ADC.h>
#include <WiFi.h>
#include <WebServer.h>
// Pinos HX711
const int DOUT_PIN = 5;
const int SCK_PIN = 15;
HX711_ADC scale(DOUT_PIN, SCK_PIN);
// Wi-Fi
const char* ssid = "MYWIFINAME";
const char* password = "MYWIFIPASS";
// Fator de calibração (ajuste depois)
const float calibrationFactor = 1.0;
WebServer server(80);
float currentWeight = 0;
// HTML que será servido em "/"
const char indexPage[] PROGMEM = R"rawliteral(
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Balança em Tempo Real</title>
<style>
body { font-family: sans-serif; text-align: center; margin-top: 50px; }
#weight { font-size: 4em; color: #007bff; }
</style>
</head>
<body>
<h1>Leitura da Balança</h1>
<div id="weight">--.- g</div>
<script>
async function updateWeight() {
try {
const resp = await fetch('/reading');
const data = await resp.json();
document.getElementById('weight').textContent = data.weight.toFixed(2) + ' g';
} catch (e) {
document.getElementById('weight').textContent = 'Erro';
}
}
// Atualiza a cada 200 ms
setInterval(updateWeight, 200);
// Primeiro fetch imediato
updateWeight();
</script>
</body>
</html>
)rawliteral";
void handleRoot() {
server.send_P(200, "text/html", indexPage);
}
void handleReading() {
// Retorna JSON com peso atual
String json = String("{\"weight\":") + String(currentWeight, 2) + "}";
server.send(200, "application/json", json);
}
void setup() {
Serial.begin(115200);
// Inicia e tara a balança
scale.begin();
Serial.println("Tareando sensor...");
delay(2000);
scale.start(2000, true);
Serial.println("Tare feita!");
// Conecta Wi-Fi
Serial.print("Conectando a ");
Serial.print(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.printf("\nConectado! IP: %s\n", WiFi.localIP().toString().c_str());
// Rotas
server.on("/", HTTP_GET, handleRoot);
server.on("/reading", HTTP_GET, handleReading);
server.begin();
}
void loop() {
// Atualiza o sensor
scale.update();
// Obtém leitura bruta e aplica fator de calibração
currentWeight = scale.getData() / calibrationFactor;
// Atende clientes web
server.handleClient();
}