#include "HX711.h"
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
const int TRIG_PIN = 7;
const int ECHO_PIN = 8;
#define DATA_PIN 1
#define CLOCK_PIN 2
HX711 hx711;
void setup() {
pinMode(TRIG_PIN, OUTPUT);
digitalWrite(TRIG_PIN, LOW);
lcd.begin();
lcd.backlight();
lcd.setCursor(0, 0);
delay(1500);
lcd.clear();
pinMode(ECHO_PIN, INPUT);
hx711.begin(DATA_PIN, CLOCK_PIN);
hx711.set_scale(420.0983);
hx711.tare();
Serial.begin(96000);
}
void loop() {
unsigned long t1;
unsigned long t2;
unsigned long pulse_width;
float height;
float weight;
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
while ( digitalRead(ECHO_PIN) == 0 );
t1 = micros();
while ( digitalRead(ECHO_PIN) == 1);
t2 = micros();
pulse_width = t2 - t1;
weight = hx711.get_units(0);
height = pulse_width / 58.7;
lcd.setCursor(0,0);
lcd.print("H:");
lcd.print(height);
lcd.print("Cm");
lcd.setCursor(0,1);
lcd.print("W:");
lcd.print(weight);
lcd.print("Kg");
delay(1000);
}