Example Code for Arduino-Quick Start Example
Last revision 2026/01/18
Hardware Preparation
- DFRduino UNO R3 x 1
- IO Expansion Shield for Arduino V7.1 x 1
- Weight Sensor Kit x 1
- DFRduino UNO R3 + IO sensor expansion board V7.1 (as calibration object, ~50g)
Software Preparation
- Arduino IDE
- Download and install the DFRobot HX711 I2C Library. (About how to install the library?)
Wiring Diagram

Other Preparation Work
- Assemble the kit and remove the objects on the sensor (if it comes with an additional tray, you can keep the tray)
- Connect the sensor correctly according to the wiring diagram, and upload the sample code. After the upload is successful, open the serial monitor and adjust the baud rate to 9600
- Ensure no objects are placed on the sensor before calibration
Sample Code
#include <DFRobot_HX711_I2C.h>
//DFRobot_HX711_I2C MyScale(&Wire,/*addr=*/0x64);
DFRobot_HX711_I2C MyScale;
float Weight = 0;
void setup() {
Serial.begin(9600);
while (!MyScale.begin()) {
Serial.println("The initialization of the chip is failed, please confirm whether the chip connection is correct");
delay(1000);
}
//// Set the calibration weight when the weight sensor module is automatically calibrated (g)
MyScale.setCalWeight(50);
// Set the trigger threshold (G) for automatic calibration of the weight sensor module. When only the weight of the object on the scale is greater than this value, the module will start the calibration process
// This value cannot be greater than the calibration weight of the setCalWeight() setting
MyScale.setThreshold(30);
// Obtain the calibration value. The accurate calibration value can be obtained after the calibration operation is completed
Serial.print("the calibration value of the sensor is: ");
Serial.println(MyScale.getCalibration());
MyScale.setCalibration(MyScale.getCalibration());
delay(1000);
}
void loop() {
Weight = MyScale.readWeight();
Serial.print("weight is: ");
if(Weight > 0.5){
Serial.print(Weight, 1);
}
else{
Serial.print(0, 1);
}
Serial.println(" g");
delay(1000);
}
Result
- Press the cal button on the board, the indicator next to cal button will light up, at this time it enters the state of waiting for calibration
- Put the DFRduino UNO R3 + IO sensor expansion board V7.1 on the scale within 5s, the cal light will go out after placing the object for 1s, at this time it enter the calibration state. When the calibration is completed, the indicator light will flash three times and go out
- The serial monitor will display the weight value of the object, e.g., "weight is: 50.0 g"
Additional Information
- It is recommended to use 100g-500g objects for calibration in actual use, the data will be more accurate
- If there is no object placed within 5S after pressing the cal key, the indicator light will continue to light for 5S and then go out after 5S. This calibration is invalid
- When opening the serial monitor, the arduino will automatically reset and clear, so you must strictly follow the above steps
Was this article helpful?
