I have one 20kg Electronic load cell sensor to measure the weight in my project. To convert the load cell value to human readable format I have used the HX711 module which converts the value and gives to my ESP32 module. The problem is up to 900gms it gives proper weight but when we put more weight it gives random long negative values(e.g -806235). I don't know why this happen even load cell capacity is to measure weight up to 20kg.
I have included the HX711 library in my code with ESP32. Link is: https://github.com/bogde/HX711
#include "HX711.h"
#define snsr_clk 4
#define snsr_data 15
HX711 scale;
float currentweight, scale_factor;
void setup()
{
Serial.begin(9600);
scale.begin(snsr_data, snsr_clk);
//scale.set_scale(); //for calibration
scale.set_scale(103229); //measured scale factor
scale.tare();
}
void loop()
{
//For calibration purpose---------------------
/*currentweight = scale.get_units(10);
//Serial.print("Current weight:\t");
//Serial.println(currentweight);
scale_factor = (currentweight);
Serial.print("Scale Factor:\t");
Serial.println(scale_factor);*/
//--------------------------------------------
//To get value in kg---------------------
Serial.print("Get Unit:\t");
Serial.println((scale.get_units(10)*1000));
//----------------------------------------------
}
Please guide how I will get the weight more than 900gms.
Yeppee..!! I solved the error. There is a little change in the library of HX711. Change in shiftIn function as shown below:
uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder)
{
uint8_t value = 0;
uint8_t i;
for(i = 0; i < 8; ++i) {
digitalWrite(clockPin, HIGH); //remove comment from here
if(bitOrder == LSBFIRST)
value |= digitalRead(dataPin) << i;
else
value |= digitalRead(dataPin) << (7 - i);
//digitalWrite(clockPin, HIGH); //comment this line
digitalWrite(clockPin, LOW);
}
return value;
}