weightsensing project using arduino

Thread Starter

damilarem

Joined Aug 5, 2017
41
i av done d coding part and my sensor is sensing values.. but i keep seeing errors and d tolerance is too wide.... and d values keep changing..
this is my code hope u help me speedily.. i also wanna incorporate keypad to tare change values and d rest


Code:
#include <LiquidCrystal.h>
#include "HX711.h"
#define sw 2
float temp_reading = 0;

HX711 scale(A1, A0);  // parameter "gain" is ommited; the default value 128 is used by the library
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
void setup()
{
  lcd.begin(16,2);  // initialize the lcd
  lcd.home();
  lcd.setCursor(0,0);
  lcd.print("HX711 Loadcell");
  lcd.setCursor(0,1);
  lcd.print("Zeroing ...");
  delay(5000);

  scale.set_scale(-583.3f);  // this value is obtained by calibrating the scale with known weights; see the README for details
  scale.tare();  // reset the scale to 0
  lcd.clear();
}
void loop() {
  lcd.setCursor(0,0);
 
  lcd.print("Weight");
  lcd.setCursor(0,1);
  temp_reading = (scale.get_units());
  if (temp_reading <0 )
  {
  temp_reading =0.00 ;
  }
  else
  {
 
  lcd.print(temp_reading ,2);
  }
  lcd.print(" Gram");
  lcd.print("  ");
  scale.power_down();  // put the ADC in sleep mode
  delay(2000);
  scale.power_up();
}
Moderator edit: added code tags.
 

ericgibbs

Joined Jan 29, 2010
18,766
hi d,
I downloaded your Sketch. modified it to use the Serial display, made some other changes.
Used a Calibrated weight of 500gm and 60gm, the list shows the outputs.
The lines marked 'add' are where I was placing the test weight on the load cell.
How accurate are you expecting the final weights.??

Rename the text file to .ico for Arduino

I would advise you not to suppress weights below zero and display 0.0

E

Code:
#include "HX711.h"
#define sw 2
float temp_reading = 0;

HX711 scale(A1, A0);  // parameter "gain" is ommited; the default value 128 is used by the library

void setup()
{
  Serial.begin(38400);
  Serial.println("HX711 Demo");

  Serial.println("Initializing the scale");
  Serial.println(scale.read_average(20));  // Display the average of 20 readings from the ADC

  scale.set_scale(146.73);  // this value is obtained by calibrating the scale
  scale.tare();  // reset the scale to 0

}
void loop() {
  Serial.print("Weight=");
  temp_reading = (scale.get_units(5));
  Serial.print(temp_reading , 2);

  Serial.print(" Gram");
  Serial.println();
  delay(3000);
}
 

Attachments

Last edited:

Thread Starter

damilarem

Joined Aug 5, 2017
41
THANKS D MUCH E MAN .... I HAVE DONE WHAT U SAID TO THE LETTER I DISCOVER THAT THE READINGS IS GIVEN ME NEGATIVE VALUE AND IS NOT STABLE STILL.. THE SET.SCALE VALUE I CHANGED TO -146.73 IS NOW GIVEN POSITIVE VALUE..... BUT STILL NOT STABLE .. IT FLUCTUATE FROM AROUND +5% OR -5 %
 

ericgibbs

Joined Jan 29, 2010
18,766
Can you post a photo of the project, showing the wiring etc.

What is the maximum weight that you want to weigh.?
What calibration weights are you using.
I need a lot more information so that I can help you.

E
 
Top