Hello all, I am pretty new to Arduino, and am working on a fairly complex project, the hardware is working, more of a variable is my code I think. I will attach a link to explain what I am doing. I am getting close to having the project working, but am having some hiccups on accuracy. I have a load cell (with no data sheet) and I am pretty close on my Cal factor, but the issue I am running into is my load cell will read +/- 5lbs of known weight @ 150-175 lbs one time(which is totally acceptable for me). I remove the load, and I check it again and then I read (normally) 20-40 lbs heavy of the known weight @150-175lbs. I can scale the load in this manner, 6 times, and its a crapshoot which way it will go every time. I also am having an issue with it going back to "0". The sketch I am using is a generic code that I have slightly modified. It seems to take a reading once a second, and therefore the reading is very unstable. I am wondering how to go about making code or logic that it will update the LCD readout once every 5 seconds, but take a reading every second, throw out the outliers/ extremes, and average the rest. I cant have the readout as sensitive as it is now, but need it to show me changes in load fairly quickly.
Recap:
Problem 1: Load cell accuracy - inconsistent load reading from one test to the next
Problem 2: Code to make the readings more stable
The load cell is designed for this exact use on a planter, and I am designing a system that will read the "margin"(see downforce attachment). The hard part is the planter will be moving through the field and as everyone knows, load cells do not particularly like constant changes in load. I am "recreating" a system that is used on newer planters, but mine is too old and the retrofit would be too costly, therefore I am building one myself. My parameters do not need to be accurate, only consistent, as the readout is only telling me the margin is "X", and now it is "Y". There is no magic number, only telling me what it is as row unit weight and soil condition change. If you have any questions on the system/use I will try to explain better.
// Include libraries needed
#include <HX711.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
//SetHX711 pins
#define DOUT 3
#define CLK 2
//Create HX711 Object
HX711 scale;
float calibration_factor = -750; // Add Cal factor here
//Set I2C Address
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
const int SW = 7;
void setup()
{
Serial.begin(9600);
lcd.begin(16,2);
lcd.backlight();
scale.begin(DOUT, CLK);
scale.set_scale(calibration_factor);
scale.tare();
Serial.println("Readings:");
lcd.setCursor(0,0); //First line
lcd.print("Roseland Farms");
lcd.setCursor(0,1); //Second line
lcd.print("MarginMonitor V1");
delay(4000) ;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("John Deere");
lcd.setCursor(0,1);
lcd.print("7200 12R30");
delay(2000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Initializing....");
long zero_factor = scale.read_average();
Serial.print("Zero factor: ");
Serial.println(zero_factor);
delay(2000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Ready...");
delay(4000);
lcd.clear(); // Need to clear before void loop or LCD will flicker
}
void loop()
{
Serial.print("Reading: ");
Serial.print(scale.get_units(), 1); //scale.get_units() returns a float
Serial.print(" lbs"); //You can change this to kg but you'll need to refactor the calibration_factor
Serial.println();
lcd.setCursor(0,0);
lcd.print("Margin");
lcd.setCursor(0,1);
lcd.print("Reading: ");
lcd.print(scale.get_units(),1);
lcd.setCursor(12,2);
lcd.print("LBS");
Serial.print("Reading: ");
Serial.print(scale.get_units(), 1); //scale.get_units() returns a float
Serial.print(" lbs");
Serial.println();
}