ESP32 Load Cell Weighing System with SD Card Logging
In this project, we’ll build a precise digital weighing system using the ESP32 microcontroller, an HX711 amplifier, a 5kg load cell, an SD card reader for data logging, and three buttons for functionality control. This project is perfect for creating a small-scale, accurate weighing system that can store measurement data for later analysis.
Components Required:
- ESP32
- HX711 load cell amplifier
- 5kg load cell
- SD card module
- Three push buttons
- Jumper wires
- Breadboard or PCB
Circuit Diagram
Below is the circuit diagram of the setup, showing how the components are connected to the ESP32.
Code Breakdown
The ESP32 reads the load cell values through the HX711 module and converts them into weight units. The data is displayed on a serial monitor and stored on the SD card for later use. Below is a sample code to help you get started.
////////////////////////////////////
#include “HX711.h”
#include <SD.h>
#include <SPI.h>
#define LOADCELL_DOUT_PIN 4
#define LOADCELL_SCK_PIN 5
HX711 scale;
#define chipSelect 5
void setup() {
Serial.begin(115200);
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
if (!SD.begin(chipSelect)) {
Serial.println(“SD Card initialization failed!”);
return;
}
Serial.println(“SD Card initialized.”);
}
void loop() {
if (scale.is_ready()) {
long reading = scale.read();
float weight = reading / 100.0; // Convert to weight based on calibration
Serial.print(“Weight: “);
Serial.println(weight);
logWeight(weight);
} else {
Serial.println(“Waiting for scale to be ready…”);
}
}
void logWeight(float weight) {
File dataFile = SD.open(“weights.txt”, FILE_WRITE);
if (dataFile) {
dataFile.println(weight);
dataFile.close();
Serial.println(“Weight saved.”);
} else {
Serial.println(“Error opening file for writing.”);
}
}
/////////////////////////////////////
Adding Buttons to Control
You can easily modify the code to include the tare, save, and clear functions using the three buttons. Each button will be mapped to a specific GPIO pin on the ESP32 and will trigger the corresponding action.
Applications:
- DIY kitchen scale
- Inventory weight tracking system
- Small-scale weighing for research purposes
Conclusion:
This ESP32-based weighing system is highly accurate and can be tailored to different weight limits by using different load cells. Adding data logging functionality makes it a practical tool for long-term monitoring.