Skip to content

Instantly share code, notes, and snippets.

@squk
Last active April 29, 2022 20:57
Show Gist options
  • Save squk/1ac9c81772cf5d75e38cf1273bae1fea to your computer and use it in GitHub Desktop.
Save squk/1ac9c81772cf5d75e38cf1273bae1fea to your computer and use it in GitHub Desktop.
//#include "HX711.h" //This library can be obtained here http://librarymanager/All#Avia_HX711
#include <HX711_2.h>
#define LOADCELL_DOUT_PIN1 12
#define LOADCELL_DOUT_PIN2 13
#define LOADCELL_SCK_PIN 11
HX711_2 scale;
float calibration_factor1 = 3900;
float calibration_factor2 = 2560;//-7050 worked for my 440lb max scale setup
void setup() {
Serial.begin(9600);
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.begin(LOADCELL_DOUT_PIN1, LOADCELL_DOUT_PIN2, LOADCELL_SCK_PIN);
scale.set_scale(calibration_factor1, calibration_factor2);
scale.power_up();
delay(500);
scale.tare(5); //Reset the scale to 0
}
void loop() {
scale.set_scale(calibration_factor1, calibration_factor2); //Adjust to this calibration factor
float values[2];
scale.get_units(values);
Serial.print("Reading: ");
Serial.print(values[0]);
Serial.print("g "); //Change this to kg and re-adjust the calibration factor if you follow SI units like a sane person
Serial.print(values[1]);
Serial.print("g");
Serial.print(" TOTAL: ");
Serial.print(values[0] + values[1]);
Serial.print("\t F1: ");
Serial.print(calibration_factor1);
Serial.print(" F2: ");
Serial.print(calibration_factor2);
Serial.println();
if(Serial.available())
{
char temp = Serial.read();
if(temp == 'a')
calibration_factor1 += 10;
else if(temp == 'z')
calibration_factor1 -= 10;
else if(temp == 's')
calibration_factor2 += 10;
else if(temp == 'x')
calibration_factor2 -= 10;
else if(temp == 't')
scale.tare(5);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment