/*
NAMA:GHOZI YUSUF MATDOAN
NIM: 3332200043
MATKUL: EMBEDED
PROJEK: TIMBANGAN DIGITAL UNTUK TUNANETRA
DENGAN OUTPUT SUARA BERBASIS ESP32
*/
#include <LiquidCrystal_I2C.h> //library untuk lcd
#include "HX711.h" // library untuk loadcell
#define I2C_ADDR 0x27
#define LCD_COLUMNS 20
#define LCD_LINES 4
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
HX711 beban;
int buzzer = 23;
void setup() {
Serial.begin(8000);
lcd.init();
pinMode(buzzer, OUTPUT);
Serial.println("Inisialisasi");
beban.begin(16, 4);
}
void loop() {
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("Massa:");
float kilogram = beban.get_units()/420;
lcd.setCursor(7,0);
lcd.print(kilogram);
Serial.print("one reading:\t");
Serial.print(beban.get_units(), 1);
Serial.print("\t| Massa:\t");
Serial.println(kilogram,1);
delay(100);
//alarm berat massa 1-5kg
if(kilogram >= 1.0 && kilogram <=1.9){
tone(buzzer, 50, 200);
noTone(buzzer);
}
if(kilogram >= 2.0 && kilogram <=2.9){
tone(buzzer, 50, 200);
noTone(buzzer);
delay(500);
tone(buzzer, 50, 200);
noTone(buzzer);
}
if(kilogram >= 3.0 && kilogram <=3.9){
tone(buzzer, 50, 200);
noTone(buzzer);
delay(500);
tone(buzzer, 50, 200);
noTone(buzzer);
delay(500);
tone(buzzer, 50, 200);
noTone(buzzer);
}
if(kilogram >= 4.0 && kilogram <=4.9){
tone(buzzer, 50, 200);
noTone(buzzer);
delay(500);
tone(buzzer, 50, 200);
noTone(buzzer);
delay(500);
tone(buzzer, 50, 200);
noTone(buzzer);
delay(500);
tone(buzzer, 50, 200);
noTone(buzzer);
}
if(kilogram >= 5){
tone(buzzer, 50);
}
if(kilogram <1 ){
noTone(buzzer);
}
delay(1000);
}