weightsensing project using arduino

Discussion in 'General Electronics Chat' started by damilarem, Aug 5, 2017.

  1. damilarem

    Thread Starter Member

    Aug 5, 2017
    41
    1
    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 (Text):
    1. #include <LiquidCrystal.h>
    2. #include "HX711.h"
    3. #define sw 2
    4. float temp_reading = 0;
    5.  
    6. HX711 scale(A1, A0);  // parameter "gain" is ommited; the default value 128 is used by the library
    7. LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
    8. void setup()
    9. {
    10.   lcd.begin(16,2);  // initialize the lcd
    11.   lcd.home();
    12.   lcd.setCursor(0,0);
    13.   lcd.print("HX711 Loadcell");
    14.   lcd.setCursor(0,1);
    15.   lcd.print("Zeroing ...");
    16.   delay(5000);
    17.  
    18.   scale.set_scale(-583.3f);  // this value is obtained by calibrating the scale with known weights; see the README for details
    19.   scale.tare();  // reset the scale to 0
    20.   lcd.clear();
    21. }
    22. void loop() {
    23.   lcd.setCursor(0,0);
    24.  
    25.   lcd.print("Weight");
    26.   lcd.setCursor(0,1);
    27.   temp_reading = (scale.get_units());
    28.   if (temp_reading <0 )
    29.   {
    30.   temp_reading =0.00 ;
    31.   }
    32.   else
    33.   {
    34.  
    35.   lcd.print(temp_reading ,2);
    36.   }
    37.   lcd.print(" Gram");
    38.   lcd.print("  ");
    39.   scale.power_down();  // put the ADC in sleep mode
    40.   delay(2000);
    41.   scale.power_up();
    42. }
    Moderator edit: added code tags.
     
  2. ericgibbs

    Moderator

    Jan 29, 2010
    6,281
    1,194
    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 (Text):
    1.  
    2.  
    3. #include "HX711.h"
    4. #define sw 2
    5. float temp_reading = 0;
    6.  
    7. HX711 scale(A1, A0);  // parameter "gain" is ommited; the default value 128 is used by the library
    8.  
    9. void setup()
    10. {
    11.   Serial.begin(38400);
    12.   Serial.println("HX711 Demo");
    13.  
    14.   Serial.println("Initializing the scale");
    15.   Serial.println(scale.read_average(20));  // Display the average of 20 readings from the ADC
    16.  
    17.   scale.set_scale(146.73);  // this value is obtained by calibrating the scale
    18.   scale.tare();  // reset the scale to 0
    19.  
    20. }
    21. void loop() {
    22.   Serial.print("Weight=");
    23.   temp_reading = (scale.get_units(5));
    24.   Serial.print(temp_reading , 2);
    25.  
    26.   Serial.print(" Gram");
    27.   Serial.println();
    28.   delay(3000);
    29. }
    30.  
    31.  
     
    Last edited: Aug 5, 2017
    Reloadron likes this.
  3. damilarem

    Thread Starter Member

    Aug 5, 2017
    41
    1
    thanks i will check it and report back to u
     
  4. damilarem

    Thread Starter Member

    Aug 5, 2017
    41
    1
    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 %
     
  5. damilarem

    Thread Starter Member

    Aug 5, 2017
    41
    1
    CAN U HELP ME WITH THIS ON PIC
    OR ATMEG?
     
  6. ericgibbs

    Moderator

    Jan 29, 2010
    6,281
    1,194
    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
     
  7. damilarem

    Thread Starter Member

    Aug 5, 2017
    41
    1
    i was told not to do it arduino again .. that i should go to pic16f877A instead
     
  8. ericgibbs

    Moderator

    Jan 29, 2010
    6,281
    1,194
    hi,
    So which language are you using to program the 16F877A.?

    I use assembly coding for the HX711 project.

    E
     
  9. damilarem

    Thread Starter Member

    Aug 5, 2017
    41
    1
    i use mickro c
     
  10. ericgibbs

    Moderator

    Jan 29, 2010
    6,281
    1,194
Loading...