I am TOTALLY new to programming and this is my very FIRST project. I have worked out how to do most of the coding and things with the help of you guys by reading similar questions and answers you guys gave other people but I am having one problem now and I can't seem to wrap my head around it, hoping someone here has a solution for me.
I am using:
Original Arduino UNO
Load Cell 1kg
HX711 Module
SG90 Servo Motor
Workings of the project:
There is a weight on the load cell when the weight is more than 50grams the servo motor stays forever in 0 degrees but when the load cell picks up that the weight is less than 50 grams it triggers the servo motor to go to 90 degrees. There is a delay of 5 seconds with the servo motor on 90 degrees and then it will put the servo motor to 0 degress. The loop starts all over. The code will check the weight again and see if the weight is more than 50 grams and if it is more than 50 grams it will keep the servo motor on 0 degrees OR it will see it's less than 50grams again and the servo motor will go to 90 degrees for 5 seconds and after 5 seconds it will put the servo motor to 0 degrees again. I have calibrated the load cell and saved the value to the EEPROM when I first initialized the load cell. I also used the calibration value in my Setup to get the correct value of the weight on the load cell.
The problem I am having:
When there is already a weight on the load cell and we lose power for some or other reason, when the power comes back on some time later, the load cell sees the weight as zero even though there is a weight on it. I need to have it calculate the weight of what is on the scale after starting up but it doesn't. How can I do that??
I read you can use EEPROM but I don't even know if it is needed but as far as I know I read that if you want something to be saved while restarting happens then EEPROM is the answer and so I read a lot about EEPROM.put and EEPROM.get but I still have no idea how to actually put it into my code to utilize it and have it "translate" the weight on the scale after starting up.
As I was trying to solve it, I read up about it, I got to a sketch to "test" or read what is my current value in my EEPROM and I got a result which is correct: 2080.02
So I know the EEPROM has it saved and it is available but I still have no idea how to use it in a way to tell my program it should use it every time it starts up to calculate the current weight on the scale and not reset it to zero every time after it restarts.
I am hoping someone would be able to explain it to me in a way I can understand or show me just how it should look like perhaps??
Thank you so much, that stopped the reseting to zero after losing power with a weight on from happening but I have no idea why but since I put the (1000, false); thing in my calibration is off ..... no weight on the scale showed 0.00 and putting 100grams on showed 100.00 but when I put the false in the code, my "zero" or no weight measurement went to 3821.20 measurement, so I don't know why it basically throws my calibration out .... if I put a 100gram weight on, it picks up the 100 grams and displays 3921.20 but the "false" added basically 3821.20 to the scale reading. Any idea why? or how to fix this problem?
When storing a calibration in EEPROM, you should also store the tareOffset. On reboot, you should read the calibration and the tareOffset and restore them. I think I'd add a storeParameters button and function, and a restoreParameters button and function.
I suspect that you will need a button for the user to be able to force tare. The scale can't tell whether a weight was left on the scale during a power outage.
You could use EEPROM to record that a weight was there last you knew, but who knows whether it still is?
I assume I have "managed" the .setCalFactor() by using:
LoadCell.setCalFactor(2080.02);
I don't have a glue how to "manage" the .setTareOffset()
So since I am getting 3821.02 MORE weight added I thought I could offset it this way:
LoadCell.setTareOffset(3821.02);
but that didn't work because it gave me an error saying:
'Loadcell' was not declared in this scope
I tried to search and read how to implement this .setTareOffset() but I can't find any source to explain what I need to do to offset this 3821.02 amount that is counted extra.
Nope, I am an idiot with coding. I don't get it to see the tareoffset story. I am wondering if it won't just be easier to forget the tareoffset lol
I want to measure 50grams .... at the moment it is measuring 3821.02 ... so perhaps I should program the code to "see" 3821.02 as zero and add 50 to it lol
so then it would like this .....
if (i < 3871.02)
myServo.write(90);
currentMillis = millis();
if (currentMillis - startMillis >= period)
{
myServo.write(servoPos);
startMillis = currentMillis;
}
I think that would be the quickest fix since I can't figure this setTareOffset thing out