Using the HX711 breakout with Arduino involves wiring up the breakout to your Arduino-compatible microcontroller with a strain gauge, installing the Adafruit_HX711 library, and running the provided example code.
Wiring
Wire as shown for a 5V board like an Uno. If you are using a 3V board, like an Adafruit Feather, wire the board's 3V pin to the breakout VIN.
Here is an Adafruit Metro wired up to the breakout with a strain gauge:
- Strain gauge power to breakout E+ (red wire)
- Strain gauge ground to breakout E- (black wire)
- Strain gauge positive to breakout A+ (green wire)
- Strain gauge negative to breakout A- (white wire)
- Board 5V to breakout VIN (red wire)
- Board GND to breakout GND (black wire)
- Board D2 to breakout DATA (blue wire)
- Board D3 to breakout SCK (yellow wire)
Library Installation
You can install the Adafruit_HX711 library for Arduino using the Library Manager in the Arduino IDE.
Click the Manage Libraries ... menu item, search for Adafruit_HX711, and select the Adafruit HX711 library:
There are no additional dependencies for the library.
#include "Adafruit_HX711.h"
// Define the pins for the HX711 communication
const uint8_t DATA_PIN = 2; // Can use any pins!
const uint8_t CLOCK_PIN = 3; // Can use any pins!
Adafruit_HX711 hx711(DATA_PIN, CLOCK_PIN);
void setup() {
Serial.begin(115200);
// wait for serial port to connect. Needed for native USB port only
while (!Serial) {
delay(10);
}
Serial.println("Adafruit HX711 Test!");
// Initialize the HX711
hx711.begin();
// read and toss 3 values each
Serial.println("Tareing....");
for (uint8_t t=0; t<3; t++) {
hx711.tareA(hx711.readChannelRaw(CHAN_A_GAIN_128));
hx711.tareA(hx711.readChannelRaw(CHAN_A_GAIN_128));
hx711.tareB(hx711.readChannelRaw(CHAN_B_GAIN_32));
hx711.tareB(hx711.readChannelRaw(CHAN_B_GAIN_32));
}
}
void loop() {
// Read from Channel A with Gain 128, can also try CHAN_A_GAIN_64 or CHAN_B_GAIN_32
// since the read is blocking this will not be more than 10 or 80 SPS (L or H switch)
int32_t weightA128 = hx711.readChannelBlocking(CHAN_A_GAIN_128);
Serial.print("Channel A (Gain 128): ");
Serial.println(weightA128);
// Read from Channel A with Gain 128, can also try CHAN_A_GAIN_64 or CHAN_B_GAIN_32
int32_t weightB32 = hx711.readChannelBlocking(CHAN_B_GAIN_32);
Serial.print("Channel B (Gain 32): ");
Serial.println(weightB32);
}
Upload the sketch to your board and open up the Serial Monitor (Tools -> Serial Monitor) at 115200 baud. In the loop, the readings on channel A and channel B are printed out. As you bend, twist and put pressure on the strain gauge, you'll see the values change.
Page last edited January 22, 2025
Text editor powered by tinymce.