my project make arduino read load cell and then print the sensor read in lcd (0, 0)
and then print largest val of load cell read in lcd (0, 1) and not clear till i rest arduino
let us say i put 100g on sensor
the arduino will write 100g in (0,0) and (0,1) in lcd
and when i remove the 100g
arduino will write in (0.0) 0g and in (0.1) 100g
but when i use my code arduino donot do that
i want know why where the wrong here
//code made by elsayed ayman
//:3
//lcd setup
#include <LiquidCrystal595.h>
LiquidCrystal595 lcd(7,8,9);
//hx711 setup
#include <HX711_ADC.h>
HX711_ADC LoadCell(A0, A1);
long t;
//code
void setup()
{
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print("plz w8");
lcd.setCursor(0,1);
lcd.print("loading");
LoadCell.begin();
long stabilisingtime = 2000;
LoadCell.start(stabilisingtime);
LoadCell.setCalFactor(696.0);
}
void loop()
{
LoadCell.update();
if (millis() > t + 250)
{
float i = LoadCell.getData();
float ii = i ;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("sensor=");
lcd.print(i);
lcd.print("g");
t = millis();
if ( ii > i);
{
lcd.setCursor(0, 1);
lcd.print("LastVal=");
lcd.print(ii);
lcd.print("g");
}
}
if (LoadCell.getTareStatus() == true) {
lcd.setCursor(0, 1);
lcd.print("Tare complete");
}
}
Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read. If you're using the Arduino Web Editor you will not have access to this useful tool but it's still unacceptable to post poorly formatted code. I recommend you to use the standard IDE instead.
elsayed_ayman:
but when i use my code arduino donot do that
You are declaring new variables to hold data each time through loop(). That is OK but each time you do it they will both be set to an unknown value and will not retain the previous one. If you want a variable to retain its previous value then either declare it as a global or declare it static.
To make your code clearer can I suggest that you give them clearer names, perhaps highestValue and currentValue. When the program start set highestValue to zero and update it is currentValue is greater than highestValue
Your method of using millis() by addition has flaws in it if the program is to run for a long time. Timing variables should be unsigned long (and the names could be clearer) and the calculations should be done by subtraction. Doing this will ensure that there are no problems when millis() rolls over to zero.
thx for info master UKHeliBob
the guide is so good and help me alot (( english not my main so take alot of time to read and understand it ))
any way i think i did what you say and that is my new code
but :o
still the same problem
arduino print the Weight i add it on sensor but when i remove it arduino clear the result form lcd in (0.1)
what is wrong here
what i want from code is print the weight which i add on sensor in lcd (0.0) and (0.1) and when i remove the weight arduino print 0g in lcd (0.0) and the result not clear for lcd (0.1)
Stop declaring new variables when you want to retain the values previously assigned to them and don't copy the current value to the highest value without testing whether it is higher than the previously stored value
Notice that you'll have to either declare highestValue as a global variable (like at the top of the program, outside any functions) or as a static variable. Otherwise, it gets a new copy every time the loop routine is executed, and the old data would get thrown away.
Declare your value variables as global at the top of the program
Set the highest value to zero
When you use the variables in the program do not put the type specifier in front of the name
Read the current value and compare it with the highest value
If the current value is greater than the highest value assign it to the highest value
Display the highest and current values when a new current value becomes available
pert:
Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read. If you're using the Arduino Web Editor you will not have access to this useful tool but it's still unacceptable to post poorly formatted code. I recommend you to use the standard IDE instead.
(ok) Declare your value variables as global at the top of the program
(!!) Set the highest value to zero -> should i write (( float highestValue =0 ; )) not (( float highestValue ; )) only !!
Actually either will do because delaring global variables sets them to zero
(ok) When you use the variables in the program do not put the type specifier in front of the name
(??)Read the current value and compare it with the highest value i try to do it but i fail
(!!)If the current value is greater than the highest value assign it to the highest value
if (currentValue > highestValue)
{
highestValue = current value; //saved new highest
}
(??)Display the highest and current values when a new current value becomes available
Use you display code which you already have working
but
still same problem :o when i put Weight on sensor and arduino read it give me the result in sensor lcd line (0.0) and last val lcd line (0.1) and when i remove the Weight arduino write in last val lcd line 0g not the last result befor i remove the Weight !!