~~NOCACHE~~ ====== LamaPLC: HX711 24-bit analog-to-digital converter (ADC) ====== {{ :sensor:hx_711_1.png?180|HX711 24-bit analog-to-digital converter (ADC) }} The HX711 is a widely used, low-cost 24-bit analogue-to-digital converter (ADC) integrated circuit with an internal amplifier, specifically designed to interface directly with bridge sensors such as load cells and strain gauges. It is a popular component for DIY and commercial weighing-scale projects using microcontrollers such as Arduino and Raspberry Pi. **Key Features** * **High Resolution:** It provides 24-bit resolution, enabling precise measurement of small voltage changes. * **Integrated Amplifier (PGA):** Features an on-chip, low-noise Programmable Gain Amplifier (PGA) with selectable gains of 32, 64, or 128 to amplify very small signals from load cells. * **Dual Input Channels:** Two selectable differential input channels (Channel A and Channel B). Channel A is programmable to 128 or 64, while Channel B has a fixed gain of 32. * **Simple Interface:** Uses a simple two-wire serial interface (clock and data lines) that is easy to use with most microcontrollers and does not require complex programming of internal registers. * **Integrated Components:** Includes an on-chip power supply regulator for the load cell and ADC's analogue supply, an internal oscillator, and a power-on-reset circuit, minimising the need for external components. * **Selectable Data Rate:** The output data rate can be set to either 10 samples per second (SPS) or 80 SPS. * **Power Efficiency:** Operates over a wide supply voltage range (2.6V to 5.5V) and has low power consumption, including a power-down mode of less than 1µA. * **Communication:** The HX711 does not use a standard, named communication protocol such as I²C or SPI. Instead, it uses a custom 2-wire serial interface consisting of a Data line (DT) and a Clock line (SCK). **Applications** The primary application of the HX711 is to build precise weight and force measurement systems. * **Weighing Scales:** Used in commercial and kitchen scales to provide accurate weight readings. * **Industrial Control:** Integrated into automation systems to monitor and control the weight of objects in manufacturing processes. * **IoT Projects:** Serves as a sensor node in smart home or environmental monitoring systems (e.g., smart pet feeders, beehive monitoring). ==== HX711 with a load cell ==== {{ :sensor:hx_711_2.png|HX711 with a load cell}} Using the HX711 with a load cell is a common method for building digital scales or force measurement systems due to its simplicity, low cost, and high precision. The process involves correctly wiring the load cell's four wires to the HX711 board, connecting the board to a microcontroller, using a library, and performing a simple calibration. The HX711 is purpose-built to interface with **Wheatstone bridge**s, which are the internal circuits of load cells and strain gauges. It provides the necessary excitation voltage to power the bridge and precisely measures the resulting minute differential voltage changes. **Wiring the Components** A standard four-wire load cell uses a color-coded system to identify the wires for excitation voltage and the output signal. **Load Cell to HX711 Connections** {{:sensor:load_cell_wiring.png|Load Cell to HX711 Connections}} Connect the load cell wires to the corresponding terminals on the HX711 board: * **Red Wire (E+):** Connect to HX711's E+ terminal (Excitation Positive). * **Black Wire (E-):** Connect to HX711's E- terminal (Excitation Negative). * **Green Wire (A+):** Connect to HX711's A+ terminal (Signal Positive). * **White Wire (A-):** Connect to HX711's A- terminal (Signal Negative). {{page>:tarhal}} ==== HX711 module board pinout ==== The HX711 module is a 24-bit ADC meant for weight scales, serving as an interface between a load cell (bridge sensor) and a microcontroller. It usually features two pin sets: one for connecting the load cell (input) and another for the microcontroller (output). ^Pin Label^Name^Description^Typical Wire Colour| ^E+|Excitation Positive|Positive supply to the load cell.|Red| ^E-|Excitation Negative|Ground/Negative supply to the load cell.|Black| ^A-|Channel A Negative|Negative differential signal input from the load cell.|White| ^A+|Channel A Positive|Positive differential signal input from the load cell.|Green| ^B-|Channel B Negative|Secondary input channel (lower priority/gain).|—| ^B+|Channel B Positive|Secondary input channel (lower priority/gain).|—| ^Vcc|Supply Voltage|Power supply for the module (**2.7V to 5.5V**).|—| ^GND|Ground|Common circuit ground.|—| ^DT / DAT|Data Out|Serial data output to the microcontroller.|—| ^SCK / CLK|Serial Clock|Clock signal input from the microcontroller.|—| **Key Connection Notes** * **Microcontroller Pins:** The DT and SCK pins can be connected to any digital GPIO pins on your Arduino or ESP32; they do not require specific hardware SPI pins. * **Channel A vs. B:** Channel A is the primary input and supports a gain of 128 or 64. Channel B is for a second load cell and has a fixed gain of 32. * **Voltage Logic:** If you are using a 3.3V microcontroller (like an ESP32), ensure the module is powered appropriately. While many modules work at 3.3V, some "green" boards require a 5V supply to properly excite the load cell. * **Drift Prevention:** For the best accuracy, keep the load cell wires short and use a stable power source, as the HX711 is extremely sensitive to voltage fluctuations. ==== Arduino & HX711 ==== To get started, you'll need the HX711 Arduino Library by bogde, which is the community standard. You can install it directly via the Arduino Library Manager. **Software Setup and Calibration** You will need a library to easily communicate with the HX711 using your microcontroller. The **HX711 library** by Bogdan Necula is a popular, well-maintained option available in the Arduino Library Manager. * **Upload Calibration Code:** Use example code from the library to get the raw readings. With the load cell unloaded, record the "tare" value. * **Apply Known Weight:** Place an object of a known weight (e.g., a 100g calibration weight) on the load cell and record the new raw reading. * **Calculate the Calibration Factor:** The calibration factor is calculated using the formula: //Calibration Factor = (Raw Reading with Weight - Tare) / Known Weight.// * **Update Code:** Update your main program with this calibration factor using the //scale.set_scale(calibration_factor)// function in the library. The scale is now ready to provide accurate weight measurements. **Wiring Diagram** ^HX711 Pin^Arduino Pin| ^VCC|5V (or 3.3V)| ^GND|GND| ^DT (Data)|D3| ^SCK (Clock)|D2| **Basic Reading & Calibration Code** This script initialises the scale, "tares" it (sets it to zero), and reads the weight. #include "HX711.h" // Pin definitions const int LOADCELL_DOUT_PIN = 3; const int LOADCELL_SCK_PIN = 2; HX711 scale; void setup() { Serial.begin(57600); Serial.println("Initializing the scale..."); scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN); // --- CALIBRATION --- // 1. Upload this code with scale.set_scale() empty or set to 1. // 2. Put a known weight (e.g. 100g) on the scale. // 3. Divide the raw reading by the known weight to find this factor. scale.set_scale(2280.f); // Replace 2280.f with your calculated calibration factor scale.tare(); // Reset the scale to 0 Serial.println("Scale ready!"); } void loop() { if (scale.is_ready()) { long reading = scale.get_units(10); // Average of 10 readings Serial.print("Weight: "); Serial.print(reading); Serial.println(" g"); } else { Serial.println("HX711 not found."); } delay(1000); } **Critical Tips** * **The Calibration Factor:** Every load cell is physically different. If your readings are off by a lot, use the Calibration Tutorials to find your specific value. * **Baud Rate:** Many HX711 examples use 57600 baud. Ensure your Serial Monitor matches the //Serial.begin()// value, or you will see gibberish. * **Drift:** Cheap load cells drift with temperature. If accuracy degrades over time, consider the [[ads|ADS1220]] we discussed earlier; it includes an internal temperature sensor to help you compensate. ===== Sensor topics on lamaPLC ===== {{topic>sensor}} \\ {{tag>HX711 HX-711 analog-to-digital ADC converter load_cell Wheatstone_bridge weight sensor communication arduino code}} This page has been accessed for: Today: {{counter|today}}, Until now: {{counter|total}}