This project demonstrates how to interface an HX711 24-bit ADC with an STM32F103C6 microcontroller for precise weight measurements using a strain gauge load cell. The system reads the raw data from the load cell, converts it into a calibrated weight value, and outputs the result in real-time via UART. A full Proteus simulation setup is included for validation.
Strain gauge load cells operate on the principle that a strain gauge deforms under load, changing its electrical resistance. This change is proportional to the applied force. The HX711 amplifier converts this small analog signal into a high-resolution digital value that the STM32 can process.
STM32CubeMX Setup- MCU Selection: STM32F103C6 (72 MHz clock)
- GPIO Configuration:
-
PA1 configured as Input (HX711 DATA - DT)
-
PA2 configured as Output Push-Pull (HX711 CLOCK - SCK)
- TIM1 Configuration:
-
Used for microsecond delays required by the HX711 communication protocol.
-
Prescaler: 72-1 (1 µs tick)
-
Counter Period: 65535
- UART1 Configuration:
-
Baud Rate: 9600
-
Word Length: 8 bits
-
Parity: None
-
Stop Bits: 1
- Generate initialization code in STM32CubeIDE.
Key Functions
- HX711 Initialization & Calibration
-
void hx711_init(...);
→ Initializes GPIO pins for communication with the HX711 module and prepares it for data acquisition.-
void hx711_tare(...);
→ Sets the current reading as the zero-point (offset), canceling out the weight of the container.-
void hx711_calibration(...);
→ Calculates the scale factor by comparing readings between no load and a known reference weight.
- Weight Data Acquisition
-
int32_t hx711_value_ave(...);
→ Reads the raw, averaged 24-bit ADC value from the HX711 to reduce noise.-
float hx711_weight(...);
→ The primary function to get the final weight. Applies the calibration scale factor and offset to the raw value and returns the result in grams (or other units).
- Power Management
Required Components:
- STM32F103C6 microcontroller
- HX711 Breakout Module (simulated)
- Virtual Terminal (UART)
- DC Voltmeter (to simulate the load cell's analog output)
Connections:
- HX711: DT → PA1, SCK → PA2
- UART1: PA9 (TX) → Virtual Terminal RX
- Simulation Tip: The load cell is simulated using a variable voltage source connected to the HX711's analog inputs. The voltage (e.g., 0-5V) corresponds to a simulated weight range (e.g., 0-5 kg).
Steps:
- Load the.hex file compiled from CubeIDE.
- Run the simulation.
- Adjust the simulated voltage source to represent changes in weight.
- Observe the real-time weight output on the Virtual Terminal.
If you have any questions or suggestions don't hesitate to leave a comment below
Comments