#include <HX711_ADC.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
HX711_ADC LoadCell(4, 5);
LiquidCrystal_I2C lcd(0x27,20,4);
void setup() {
LoadCell.begin();
LoadCell.start (2000);
LoadCell.setCalFactor(1.0);
lcd.init();
lcd.backlight();
}
void loop (){
LoadCell.update();
float i = LoadCell.getData();
lcd.setCursor(0, 0);
lcd.print("Weight[g]:");
lcd.setCursor(0, 1);
lcd.print(i);
}
was wondering if someone could help me add a tare function to 0 the scale. this is the first thing ive tried programming and ive spent hours trying to figure this out. thank you to whoever can offer some help.
AR_ans
April 7, 2018, 7:08pm
2
Do you have an input method set that triggers the tare mode?
Like a pushbutton or something?
yes i have a pushbutton on a breadboard that goes into the d2 port on the arduino.
AR_ans
April 7, 2018, 7:22pm
4
Here hope this helps:
Probably not the best code but give it a shot
#include <HX711_ADC.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
HX711_ADC LoadCell(4, 5);
LiquidCrystal_I2C lcd(0x27,20,4);
const int tarePin = 12; //Tare button at pin 12
float tareVal = 0;
float i=0;
void setup() {
LoadCell.begin();
LoadCell.start (2000);
LoadCell.setCalFactor(1.0);
lcd.init();
lcd.backlight();
pinMode(tarePin, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if(tarePin == HIGH){
//If push button is pressed
if(tareVal==0){
//Assign new tare
LoadCell.update();
tareVal = LoadCell.getData();
delay(100);
}else{
//When tare is assigned already and button is pressed clear tare
tareVal = 0;
}
}
LoadCell.update();
i = (LoadCell.getData() - tareVal);
lcd.setCursor(0, 0);
lcd.print("Weight[g]:");
lcd.setCursor(0, 1);
lcd.print(i);
}
it compiles and uploads to my arduino but the tare function doesnt seem to be working properly i will try and
figure it out from here but thank you for your help.