"Untitled Post" - Views: 4,753 · Hits: 4,753 - Type: Public


/*   MakerMan Weighing Scale Ver: 1.0    
  This example code uses bogde's excellent library: https://github.com/bogde/HX711
  bogde's library is released under a GNU GENERAL PUBLIC LICENSE

  The HX711 does one thing well: read load cells. The breakout board is compatible with any wheat-stone bridge
  based load cell which should allow a user to measure everything from a few grams to tens of tons.
  
  Arduino pin to HX711
  A2 ->  CLK
  A1 -> DAT
  5V -> VCC
  GND -> GND

  The HX711 board can be powered from 2.7V to 5V so the Arduino 5V power should be fine.
 */
#include <LiquidCrystal.h>
#include <HX711.h>

int button1 = 9;
int press1 = 0;

LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

HX711 scale1(A1, A2);

#define MAXFLT 8 // 24 bit resolution is 7 digits

void setup() {
  lcd.clear();
  lcd.begin(16, 2);

  lcd.setCursor(0, 0);
  lcd.print(" Weighing Scale ");
  lcd.setCursor(0, 1);
  lcd.print("----MakerMan----");
  delay(3000);

  lcd.setCursor(0, 0);
  lcd.print("--Place Weight--");
  lcd.setCursor(0, 1);
  lcd.print("   ..... kg      ");

  scale1.set_scale(-11410);  // BUG: calibrate the scale (higher number, lower reading)
  scale1.tare();   // reset the scale to zero

  pinMode(button1, INPUT);
  digitalWrite(button1, HIGH); //enable pullups to make pin high

}

void loop() {
  float r;
  char buf[MAXFLT + 1];
  r = scale1.get_units(5); // average 10 readingslcd.print(scale1.get_units(10), 3); // average 10 readings
  Serial.println(dtostrf(r, MAXFLT, 3, buf));
  lcd.setCursor(0, 1);
  lcd.print(dtostrf(r, MAXFLT, 2, buf)); // average 10 readings, approx 1 second

  {
    press1 = digitalRead(button1);
    if (press1 == LOW)
    {
      scale1.tare();
    }
    else {
      /// do nothing
    }
  }
}