I am currently using HX711 and a load cell. However, the calibration thing in the load cell confuses me, even if I already watched several tutorials, I still don't get it. I have questions in mind such as:
- What should I do with the standard (from what I think it is) "-7050" value in the calibration? Do I add or do I subtract?
- How do I convert the values into grams?
- How can I use an "if/else" code to it? I'm thinking of something like connecting it to a DHT11 temperature sensor and it should be something like "If the weight is 0 grams, don't read the temperature. If the weight is more than 0 grams, read the temperature"
I have the typical schematic diagram from the internet, and no, I haven't tried to connect the whole weight sensor yet, only the load cell once before soldering it to the HX711.
I am trying to use this library: GitHub - bogde/HX711: An Arduino library to interface the Avia Semiconductor HX711 24-Bit Analog-to-Digital Converter (ADC) for Weight Scales.
For the code, I used SparkFun's Code (note: this is only for the calibration, I haven't coded the connection to the DHT11 yet):
#include "HX711.h"
#define LOADCELL_DOUT_PIN 3
#define LOADCELL_SCK_PIN 2
HX711 scale;
float calibration_factor = -7050; //-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_PIN, LOADCELL_SCK_PIN);
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: ");
Serial.print(scale.get_units(), 1);
Serial.print(" lbs"); //Change this to kg and re-adjust the calibration factor if you follow SI units like a sane person
Serial.print(" calibration_factor: ");
Serial.print(calibration_factor);
Serial.println();
if(Serial.available())
{
char temp = Serial.read();
if(temp == '+' || temp == 'a')
calibration_factor += 10;
else if(temp == '-' || temp == 'z')
calibration_factor -= 10;
}
}
Along with the library, I found the weight code:
/*!
* @file readWeight.ino
* @brief Get the weight of the object
* @details After the program download is complete,
* @n The serial port will print the current weight
* @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
* @License The MIT License (MIT)
* @author [Wuxiao](xiao.wu@dfrobot.com)
* @version V1.0
* @date 2020-12-26
* @https://github.com/DFRobot/DFRobot_HX711
*/
#include <DFRobot_HX711.h>
/*!
* @fn DFRobot_HX711
* @brief Constructor
* @param pin_din Analog data pins
* @param pin_slk Analog data pins
*/
DFRobot_HX711 MyScale(A2, A3);
void setup() {
Serial.begin(9600);
}
void loop() {
// Get the weight of the object
Serial.print(MyScale.readWeight(), 1);
Serial.println(" g");
delay(200);
}