HX711 Calibration For Arduino - Gists · GitHub

Skip to content Search Gists Search Gists All gists Back to GitHub Sign in Sign up Sign in Sign up Dismiss alert {{ message }}

Instantly share code, notes, and snippets.

@matt448 matt448/hx711_calibration.ino Last active March 13, 2023 16:56 Show Gist options
  • Star (10) You must be signed in to star a gist
  • Fork (2) You must be signed in to fork a gist
  • Embed Select an option
    • Embed Embed this gist in your website.
    • Share Copy sharable link for this gist.
    • Clone via HTTPS Clone using the web URL.

    No results found

    Learn more about clone URLs Clone this repository at <script src="https://gist.github.com/matt448/14d118e2fc5b6217da11.js"></script>
  • Save matt448/14d118e2fc5b6217da11 to your computer and use it in GitHub Desktop.
Code Revisions 8 Stars 10 Forks 2 Embed Select an option
  • Embed Embed this gist in your website.
  • Share Copy sharable link for this gist.
  • Clone via HTTPS Clone using the web URL.

No results found

Learn more about clone URLs Clone this repository at <script src="https://gist.github.com/matt448/14d118e2fc5b6217da11.js"></script> Save matt448/14d118e2fc5b6217da11 to your computer and use it in GitHub Desktop. Download ZIP HX711 Calibration for Arduino Raw hx711_calibration.ino This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters
/*
Started with example code written by Nathan Seidle from SparkFun Electronics and added
LCD output with gram and ounce values.
Setup your scale and start the sketch WITHOUT a weight on the scale
Once readings are displayed place the weight on the scale
Press +/- or a/z to adjust the calibration_factor until the output readings match the known weight
Arduino pin 6 -> HX711 CLK
Arduino pin 5 -> HX711 DOUT
Arduino pin 5V -> HX711 VCC
Arduino pin GND -> HX711 GND
The HX711 board can be powered from 2.7V to 5V so the Arduino 5V power should be fine.
The HX711 library can be downloaded from here: https://github.com/bogde/HX711
*/
#include <LiquidCrystal.h>
LiquidCrystal lcd(51, 50, 49, 48, 47, 46);
#include "HX711.h"
#define DOUT 5
#define CLK 6
HX711 scale(DOUT, CLK);
float calibration_factor = 2125; //-7050 worked for my 440lb max scale setup
float units;
float ounces;
void setup() {
Serial.begin(9600);
// set up the LCD's number of columns and rows:
lcd.begin(20, 4);
lcd.setCursor(0, 0);
lcd.print("HX711 calibration");
Serial.println("HX711 calibration sketch");
Serial.println("Remove all weight from scale");
Serial.println("After readings begin, place known weight on scale");
Serial.println("Press + or a to increase calibration factor");
Serial.println("Press - or z to decrease calibration factor");
scale.set_scale();
scale.tare(); //Reset the scale to 0
long zero_factor = scale.read_average(); //Get a baseline reading
Serial.print("Zero factor: "); //This can be used to remove the need to tare the scale. Useful in permanent scale projects.
Serial.println(zero_factor);
}
void loop() {
scale.set_scale(calibration_factor); //Adjust to this calibration factor
Serial.print("Reading: ");
units = scale.get_units(), 10;
if (units < 0) {
units = 0.00;
}
ounces = units * 0.035274; //Convert grams to ounces
Serial.print(units);
Serial.print(" grams");
Serial.print(" calibration_factor: ");
Serial.print(calibration_factor);
Serial.println();
lcd.setCursor(0, 1);
lcd.print("Grams: ");
lcd.print(units);
lcd.setCursor(0, 2);
lcd.print("Ounce: ");
lcd.print(ounces);
lcd.setCursor(0, 3);
lcd.print("Calbr: ");
lcd.print(calibration_factor);
if(Serial.available())
{
char temp = Serial.read();
if(temp == '+' || temp == 'a')
calibration_factor += 1;
else if(temp == '-' || temp == 'z')
calibration_factor -= 1;
}
}
@huykhoiha Copy link

huykhoiha commented Aug 2, 2017

Could you attach the diagram or schematic for this project. I would be grateful if you could share it, thank you sir .

Uh oh!

There was an error while loading. Please reload this page.

@Koktung Copy link

Koktung commented Sep 26, 2017

May I know how you deal with the condition of load cell reading keep fluctuate?

Uh oh!

There was an error while loading. Please reload this page.

@matt448 Copy link Author

matt448 commented Feb 14, 2018

The schematic can be found on Sparkfun's website: https://learn.sparkfun.com/tutorials/load-cell-amplifier-hx711-breakout-hookup-guide

Uh oh!

There was an error while loading. Please reload this page.

@matt448 Copy link Author

matt448 commented Feb 14, 2018

For the fluctuations I think one strategy could be to take several readings over a short period of time and average them. Something else to consider is that the fluctuation is happening at less than one gram. You could just round to the nearest gram and the readings would be more stable.

Uh oh!

There was an error while loading. Please reload this page.

@muliahanif Copy link

muliahanif commented Jan 28, 2019

how can we get the value 0.035274? its mean 1 gram?

Uh oh!

There was an error while loading. Please reload this page.

@Cutie95 Copy link

Cutie95 commented Feb 12, 2019

Hi. Currently, I had set up a weighing system where it's set to zero when there is no weight on the load cell. However, the weighing system is placed in the open-air environment where it might consist of some dirt and animals (such as kittens, dog or rats) above the weighing system which caused the system to be incorrect. May I know how to code the load cell to subtract the weight on the weighing system to auto-calibrate periodically it?

Uh oh!

There was an error while loading. Please reload this page.

@sravyasona Copy link

sravyasona commented Jun 30, 2019

no matching function for call to 'HX711:: HX711(int, int)'. please help me with this issue.

Uh oh!

There was an error while loading. Please reload this page.

@jay58 Copy link

jay58 commented Jul 18, 2019

just call: HX711 scale; instead of HX711 scale(DOUT, CLK)

Uh oh!

There was an error while loading. Please reload this page.

@AndreasAsiikkis Copy link

AndreasAsiikkis commented Aug 8, 2019

Hi,

I am having the same problem as sravyasona. I am using 2 load cells for my project so my code looks like this at the start:

#include<LiquidCrystal.h> #include <HX711.h> #define RST 10 #define DOUT 22 #define CLK 24 #define DOUT1 46 #define CLK1 48

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

int serial_in; HX711 scale(DOUT, CLK); HX711 scale1(DOUT1, CLK1);

The error that shows up is : no matching function for call to 'HX711::HX711(int, int)'

Any help would be appreciated. I have not much experience with arduino. Thanks, Andreas

Uh oh!

There was an error while loading. Please reload this page.

@sravyasona Copy link

sravyasona commented Aug 8, 2019 via email

Call HX711 scale; instead of HX711 scale(DOUT, CLK); On Thu., Aug. 8, 2019, 12:30 p.m. Andreas Ashikkis, < ***@***.***> wrote: Hi, I am having the same problem as sravyasona. I am using 2 load cells for my project so my code looks like this at the start: #include<LiquidCrystal.h> #include <HX711.h> #define RST 10 #define DOUT 22 #define CLK 24 #define DOUT1 46 #define CLK1 48 LiquidCrystal lcd(8, 9, 4, 5, 6, 7); int serial_in; HX711 scale(DOUT, CLK); HX711 scale1(DOUT1, CLK1); The error that shows up is : no matching function for call to 'HX711::HX711(int, int)' Any help would be appreciated. I have not much experience with arduino. Thanks, Andreas — You are receiving this because you commented. Reply to this email directly, view it on GitHub <https://gist.github.com/14d118e2fc5b6217da11?email_source=notifications&email_token=ALQENGVCGIHQDUCG4XC2V5TQDRQ3PA5CNFSM4H4LO4SKYY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAFWXD6#gistcomment-2993727>, or mute the thread <https://github.com/notifications/unsubscribe-auth/ALQENGRLAME4BT27LDG4NITQDRQ3PANCNFSM4H4LO4SA> .

Uh oh!

There was an error while loading. Please reload this page.

@AndreasAsiikkis Copy link

AndreasAsiikkis commented Aug 8, 2019

I have already tried this but it doesn’t work for me. How do i define the pins of the two HX711?

Thanks

Uh oh!

There was an error while loading. Please reload this page.

@sravyasona Copy link

sravyasona commented Aug 8, 2019 via email

This pic may help you dear On Thu., Aug. 8, 2019, 2:06 p.m. Andreas Ashikkis, ***@***.***> wrote: I have already tried this but it doesn’t work for me. How do i define the pins of the two HX711? Thanks — You are receiving this because you commented. Reply to this email directly, view it on GitHub <https://gist.github.com/14d118e2fc5b6217da11?email_source=notifications&email_token=ALQENGTVMOPKQB2D26BWOALQDR4FLA5CNFSM4H4LO4SKYY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAFWXJG#gistcomment-2993811>, or mute the thread <https://github.com/notifications/unsubscribe-auth/ALQENGT7KS2HGL2LJUQQ2EDQDR4FLANCNFSM4H4LO4SA> .

Uh oh!

There was an error while loading. Please reload this page.

@madhavmaheshwari Copy link

madhavmaheshwari commented Oct 19, 2019

call HX711 scale; and then in the setup call scale.begin(DOUT,SCK);

Uh oh!

There was an error while loading. Please reload this page.

@Dhanush21-dg Copy link

Dhanush21-dg commented Mar 15, 2020

#include<LiquidCrystal.h> #include "HX711.h" #define RST 10 #define DOUT 22 #define CLK 24 #define DOUT1 46 #define CLK1 48

LiquidCrystal lcd(8, 9, 7, 6, 5, 4);

int serial_in; HX711 scale; HX711 scale1;

Try this code..... and comment if you get any error

Uh oh!

There was an error while loading. Please reload this page.

@viet30081999 Copy link

viet30081999 commented Nov 25, 2020

Hi,

I am having the same problem as sravyasona. I am using 2 load cells for my project so my code looks like this at the start:

#include<LiquidCrystal.h> #include <HX711.h> #define RST 10 #define DOUT 22 #define CLK 24 #define DOUT1 46 #define CLK1 48

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

int serial_in; HX711 scale(DOUT, CLK); HX711 scale1(DOUT1, CLK1);

The error that shows up is : no matching function for call to 'HX711::HX711(int, int)'

Any help would be appreciated. I have not much experience with arduino. Thanks, Andreas

HX711 scale; void setup(){ scale.begin(DOUT, CLK); } // this is ok

Uh oh!

There was an error while loading. Please reload this page.

@Hfrag Copy link

Hfrag commented Dec 29, 2021

In line 59 you wrote: units = scale.get_units(), 10; What it really means?

Number 10 is not an argument of get units function, but rather the number of times that some function will be rolled but it is outside funcion variables ().

Uh oh!

There was an error while loading. Please reload this page.

@flowmeter Copy link

flowmeter commented May 9, 2022 edited Loading

Uh oh!

There was an error while loading. Please reload this page.

Hi, Something seems strange on line 30 ;

`float calibration_factor = 2125; //-7050 worked for my 440lb max scale setup'

2125 seems to be :

  • a constant
  • an unsigned integer

Best.

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment You can’t perform that action at this time.

Tag » Arduino Hx711 Set_scale