How to use a Weight Sensor / Load Cell + HX711 with an Arduino

//How to use a Weight Sensor / Load Cell + HX711 with an Arduino

Using a Load Cell to make a simple scale with an Arduino


All my content is free.

If you feel that my videos are helping and you would like to contribute, you can toss some coins in the Tip Jar via PayPal.

Select amount then click the “Donate” button.

Brainy-Bits Tip Jar Amount

We’ve all used a scale to determine the weight of something at some point in our lives.

Using a Load Cell or Weight sensor you can add this capability to your Arduino projects.

In this tutorial we will see how to connect, calibrate and display the weight on a small OLED display, and by using a rotary encoder we will be able to change the units from: grams, kg or pounds.

We will be using the HX711 ADC converter board to amplify the signal received from the weight sensor.  This amplifier enables the Arduino to detect the changes in resistance from the load cell.

Load Cell and HX711 INTRODUCTION


So what is a Load Cell?

They are many types of Load Cell, but today we will be using the straight bar type.

When pressure or a load is applied, the electrical resistance will change in response to this applied pressure and by taking this information and after some calibration we can determine the precise weight.

Load cell like this one come in different weight limits, the one we will be using today is rated up to 1KG, but you can get others that will support more weight if needed.

What about this HX711?


The changes in electrical resistance provided by the Load Cell need to be amplified so that they can be read by an Arduino.

That’s exactly what the HX711 board does.  It reads the information from the Load Cell, amplifies the signals and then sends it to the Arduino for processing.

Common Load cells have four-wire to connect the HX711 to a microcontroller like the Arduino.

  • Red (VCC)
  • Black (GND)
  • Data
  • Clock

To connect the HX711 to the Arduino you only need 2 pins (Clock and Data).

On the opposite side you can see the connection for the Load cell.

We will be using a simple Arduino library to communicate with the HX711 that provides a calibration and Tare (reset) feature to easily determine the weight of an object.


The bar type we are using has different screws holes on the bottom and the top.

To it up as a scale, you attach the bottom left or right screw holes to a table or stable object, and then attach a piece of platic or any other material to serve as the scale to put objects on, to the top opposite screw holes.

*Each bar type has an arrow that indicate the direction of deflection and should be positioned the correct way for your project.

You can see a simple setup here:


This setup is for using the Load Cell has a simple scale, but you could also connect it the detect deflection between two object if you wanted.


Arduino Load Cell Schematic

The connections for this tutorial are pretty straightforward:

The 5V and GND of the UNO is connected to each modules VCC and GND.

Since the OLED display uses I2C we are using pins A4 (SDA), A5 (SCL) on the UNO to connect it.

The rotary encoder is connected to these pins: CLK to pin 2, DT to pin 3 and SW to pin 4.

The HX711 is connected to: DATA to pin 4 and CLOCK to pin 5.

Depending on the HX711 your purchase it may have different connections:  If it has color designation, then connect the corrresponding wires from the Load Cell to the HX711.

In my case my HX711 had these connections:

E+ : Connected to RED of the Load Cell
E- : Connected to BLACK

A- : Connected to GREEN
A+ : Connected to WHITE

B- : no connections
B+ : no connections


We are using a library written for the HX711 to communicate with the Arduino, you can find a link to download the library at the bottom of this page.

The first code is used to get the calibration factor for a particular Load cell, this will have to be run for each Load Cell you own, since each one is a little different.

The second code uses that calibration factor to print out the correct weight on the OLED display.

As always for more information please have a look at the tutorial video.

/* Calibration sketch for HX711 */
#include "HX711.h"  // Library needed to communicate with HX711
#define DOUT  6  // Arduino pin 6 connect to HX711 DOUT
#define CLK  5  //  Arduino pin 5 connect to HX711 CLK
HX711 scale(DOUT, CLK);  // Init of library

void setup() {
  scale.set_scale();  // Start scale
  scale.tare();       // Reset scale to zero

void loop() {
  float current_weight=scale.get_units(20);  // get average of 20 scale readings
  float scale_factor=(current_weight/0.145);  // divide the result by a known weight
  Serial.println(scale_factor);  // Print the scale factor to use
/* Arduino Scale using HX711 and Load Cell
Created by Yvan /

This code is in the public domain...

You can: copy it, use it, modify it, share it or just plain ignore it!

#include "U8glib.h"   // Library for Oled display
#include "HX711.h"    // Library for Load Cell amplifier board

volatile boolean TurnDetected;  // variable used to detect rotation of Rotary encoder
volatile int Rotary_Flag=0;     // flag to indicate rotation as occured

// Rotary Encoder Module connections
#define RotaryCLK 2   // Rotary encoder CLK pin connected to pin 2 of Arduino
#define RotaryDT 3    // Rotary encoder DT pin connected to pin 3
#define RotarySW 4    // Rotary encoder Switch pin connected to pin 4

// HX711 Module connections
#define CLK 5   // CLK of HX711 connected to pin 5 of Arduino
#define DOUT 6  // DOUT of HX711 connected to pin 6 of Arduino

int reset_screen_counter=0;      // Variable used to decide what to display on Oled
volatile int current_units=0;    // Used to select which measuring unit to use (KG,Grams,Pounds)
float unit_conversion;           // Used to convert between measuring units
int decimal_place;               // how many decimal number to display

HX711 scale(DOUT, CLK);  // Init of the HX711

U8GLIB_SSD1306_128X32 u8g(U8G_I2C_OPT_FAST);	// Init of the OLED

// Interrupt routine runs if Rotation detected from Rotary encoder
void rotarydetect ()  {
Rotary_Flag=1; // Set Rotary flag from 0 to 1

// Used to change the measurement units (0=grams, 1=KG, 2=pounds)
void change_units ()  { 
  if (current_units == 0) current_units=1;
  else if (current_units == 1) current_units=2;
  else if (current_units == 2) current_units=0;

// Run at Startup and when Resetting with Rotary encoder switch
void startupscreen(void) {
  do {
    u8g.drawStr( 0, 10, "Clear Scale");
    u8g.drawStr( 0, 28, "Click to zero...");
  } while( u8g.nextPage() );

// Reset Scale to zero
void tare_scale(void) {
  scale.set_scale(-1073000);  //Calibration Factor obtained from calibration sketch
  scale.tare();             //Reset the scale to 0  

// Start Displaying information on OLED
void start_scale(void) {
  char temp_current_units[15];  // Needed to store String to Char conversion
  String KG="KG";
  String GRAMS="GRAMS";
  String LBS="POUNDS";
  if (current_units == 0) {                     // 0 = grams
    GRAMS.toCharArray(temp_current_units, 15);  // Convert String to Char for OLED display
    unit_conversion=1000;                        // conversion value for grams
    decimal_place=0;                            // how many decimal place numbers to display
  } else if (current_units == 1) {              // 1 = Kilograms
    KG.toCharArray(temp_current_units, 15);
  } else {                                      // else 2 = Pounds
    LBS.toCharArray(temp_current_units, 15);
      do {
        u8g.drawStr( 0, 10, temp_current_units);  // Display the current measurement unit
        u8g.setPrintPos(38, 28);
        u8g.print(scale.get_units(3)*unit_conversion, decimal_place);  // Display the average of 3 scale value reading
      } while( u8g.nextPage() );

void setup(void) {
  // Set pinmode for Rotary encoder pins

  // Attach interrupt 0 (Pin 2 on UNO) to the Rotary Encoder
  attachInterrupt (0,rotarydetect,RISING);   // interrupt 0 always connected to pin 2 on Arduino UNO

  // Rotate screen 180 degrees on OLED, if required

  // Set color of OLED to Monochrome

  // Select font to use

  String start_count_string="Starting up....";  // Message to display at Startup
  char start_count[15];  // Used to String to Char conversion
  // Loop to display counting dots
  for (int x=12; x < 16; x++) {  // Select the first 12 to 16 character of String
    start_count_string.toCharArray(start_count, x);
    do {
      u8g.drawStr( 0, 10, "ARDUINO SCALE");
      u8g.drawStr( 0, 28, start_count);
    } while( u8g.nextPage() );
    delay(500);  // Delay between dots

void loop(void) {
// If Switch is pressed on Rotary Encoder
  if (!digitalRead(RotarySW)) {       // Check to see which action to take
    if(reset_screen_counter == 1) {   
      tare_scale();                   // 1 = zero and start scale
    } else {
      if(reset_screen_counter == 2) { // 2 = Scale already started so restart from begining

// If Rotation was detected
  if (Rotary_Flag == 1) {
    change_units();  // change the measuring units
    Rotary_Flag=0;   // reset flag to zero

// If system was just started display intro screen  
  if (reset_screen_counter == 0) {    
  reset_screen_counter=1;  // set to 1 and wait for Rotary click to zero scale
// if zero (tare) of scale as occured start display of weight
  if (reset_screen_counter == 2) {

Copy and Paste the above code/sketch in your Arduino IDE software.

Donwload the HX711 library here:

By | 2018-08-23T16:19:02-04:00 July 30th, 2018|Tutorials|


  1. Jon April 25, 2020 at 10:58 pm - Reply


    When I upload your code to my Uno, nothing happens. Anyone else have this issue?

    • Jon Houle April 28, 2020 at 2:51 pm - Reply

      I was able to get things working by changing the code a little bit. But now, the rotary encoder does nothing when I click it. The screen stays on: “Clear Scale Click to zero…”. Any advice?

  2. CJ April 2, 2020 at 8:51 am - Reply

    ‘HX711:: HX711(int, int)’ error fixed by turning HX711 scale (DOUT, CLK); // Init of the HX711 to HX711 scale; // Init of the HX711

  3. rony February 20, 2020 at 5:59 am - Reply

    Hello,how are you?
    I connect everything same as you,but I don’t get the right value, I got the value like a random value,and when I press on it,the value on my monitor doesn’t change,how I can know if the load c ell or hx711 is malfunction.please help me

  4. Danang Bagas February 18, 2020 at 7:12 am - Reply

    My Rotary Encoder was not run when i pressed, can you help me sir ?

  5. djokimus December 23, 2019 at 8:56 am - Reply

    Hello Friend

    have you found a solution to this eror

    no matching function for call to ‘HX711 :: HX711 (int, int)’

    i have the same problem and it reports eror in line

    HX711 scale (DOUT, CLK); // Init of the HX711

    if you can help me
    thanks in advance

    • Danang BagasWicaksono February 18, 2020 at 7:15 am - Reply

      // HX711 Module connections
      const int DOUT = 6;
      const int CLK = 5;

      • Danang BagasWicaksono February 18, 2020 at 7:17 am - Reply


        HX711 scale; // Init of the HX711

  6. vctmasters September 18, 2019 at 4:58 pm - Reply

    any way to change the pins that SCL SDA run on?

  7. J-something August 21, 2019 at 11:50 am - Reply

    compilation terminated.

    exit status 1
    HX711.h: No such file or directory

    please help.

    [email protected]

  8. chani June 29, 2019 at 7:56 pm - Reply

    exit status 1
    no matching function for call to ‘HX711:: HX711(int, int)’ I’m getting this error. please, anyone can give me the idea of how to resolve this issue. send me to my Gmail account. [email protected]

    • Ed October 15, 2019 at 1:07 am - Reply

      @J something
      Install the library

  9. chanakya June 29, 2019 at 7:55 pm - Reply

    exit status 1
    no matching function for call to ‘HX711:: HX711(int, int)’ I’m getting this error. please, anyone can give me the idea of how to resolve this issue. send me to my Gmail account. [email protected]

    • David October 20, 2019 at 7:21 am - Reply

      hey did you fixt it?

  10. teja April 11, 2019 at 3:32 pm - Reply

    compilation terminated.

    exit status 1
    Error compiling for board Arduino/Genuino Uno.

    please help with this

    • osama al- mohaia July 15, 2019 at 11:20 pm - Reply

      me also have this problem
      Do you solve it?
      please reply

  11. Roussel March 18, 2019 at 2:39 am - Reply

    Hi the fonction scale.get_units(20)

    Give à big délay for answer

  12. thach January 4, 2019 at 10:02 pm - Reply

    Hello !! you can help me. I need code load cell 100 kg. If you have please send @ My gmail. [email protected] thank you. I will donate you.

    • s February 11, 2020 at 10:38 am - Reply

      You can use multiple load cell, but it must be balanced

Leave A Comment