#include "HX711.h" //This library can be obtained here http://librarymanager/All#Avia_HX711
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define BLYNK_TEMPLATE_ID "TMPL6km9zWVn6"
#define BLYNK_TEMPLATE_NAME "Sistem Pengelolaan Ruang Parkir Berbasis IoT"
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
LiquidCrystal_I2C lcd(0x27,20,4);
// definisi variabel token, ssid, password
char auth[] = "U2Fi0f_iaw4Oh5q3k4Uf5qcMed7czRYl";
char ssid[] = "Samsung";
char pass[] = "123456789";
WidgetLED led1(V1);
WidgetLED led2(V2);
#define LOADCELL_DOUT_PIN1 5
#define LOADCELL_SCK_PIN1 18
#define LOADCELL_DOUT_PIN2 13
#define LOADCELL_SCK_PIN2 14
HX711 scale1;
HX711 scale2;
float calibration_factor1 = 434.10; //-7050 worked for my 440lb max scale setup
float calibration_factor2 = 431.10; //-7050 worked for my 440lb max scale setup
void setup() {
Serial.begin(9600);
lcd.init();
lcd.backlight();
Blynk.begin(auth, ssid, pass);
// Serial.println("HX711 calibration sketch");
// Serial.println("Remove all weight from scale");
// Serial.println("After readings begin, place known weight on scale");
// Serial.println("Press + or a to increase calibration factor");
// Serial.println("Press - or z to decrease calibration factor");
lcd.setCursor(0,0);
lcd.print(" Sistem Pengelolaan ");
lcd.setCursor(0,1);
lcd.print(" Ruang Parkir ");
lcd.setCursor(0,2);
lcd.print(" Berbasis ");
lcd.setCursor(0,3);
lcd.print(" Internet of Things ");
delay (2000);
lcd.clear();
scale1.begin(LOADCELL_DOUT_PIN1, LOADCELL_SCK_PIN1);
scale2.begin(LOADCELL_DOUT_PIN2, LOADCELL_SCK_PIN2);
scale1.set_scale();
scale2.set_scale();
scale1.tare(); //Reset the scale to 0
scale2.tare(); //Reset the scale to 0
long zero_factor1 = scale1.read_average(); //Get a baseline reading
long zero_factor2 = scale2.read_average(); //Get a baseline reading
// Serial.print("Zero factor 1: "); //This can be used to remove the need to tare the scale. Useful in permanent scale projects.
// Serial.println(zero_factor1);
// Serial.print("Zero factor 2: "); //This can be used to remove the need to tare the scale. Useful in permanent scale projects.
// Serial.println(zero_factor2);
}
void loop() {
int total = 0;
int p1,p2;
scale1.set_scale(calibration_factor1); //Adjust to this calibration factor
scale2.set_scale(calibration_factor2); //Adjust to this calibration factor
lcd.setCursor(0, 0);
lcd.print(" Selamat Datang ");
if(scale1.is_ready()) {
long reading1 = scale1.get_units(10);
Serial.print("Sensor 1 reading results : ");
Serial.println(reading1);
if(reading1 > 120) {
p1 = 1;
led1.on();
lcd.setCursor(0,2);
lcd.print("P1:TERISI");
Serial.println("P1:TERISI");
} else {
p1 = 0;
led1.off();
lcd.setCursor(0,2);
lcd.print("P1:KOSONG");
Serial.println("P1:KOSONG");
}
} else {
Serial.println("HX711 1 not found");
}
if(scale2.is_ready()) {
long reading2 = scale2.get_units(10);
Serial.print("Sensor 2 reading results : ");
Serial.println(reading2);
if(reading2 > 120) {
p2 = 1;
led2.on();
lcd.setCursor(11, 2);
lcd.print("P2:TERISI");
Serial.println("P2:TERISI");
} else {
p2 = 0;
led2.off();
lcd.setCursor(11, 2);
lcd.print("P2:KOSONG");
Serial.println("P2:KOSONG");
}
} else {
Serial.println("HX711 2 not found");
}
lcd.setCursor(0, 1);
total = p1 + p2;
lcd.print(" Total Kosong : ");
lcd.setCursor(17, 1);
lcd.print(total);
if(total == 2) {
lcd.setCursor(0, 3);
lcd.print("Maaf Parkiran Penuh!");
} else if(total == 0 || total == 1) {
lcd.setCursor(0, 3);
lcd.print(" .. ");
}
// Serial.println("===================");
Blynk.run();
delay(1000);
// Serial.print("Reading: ");
// Serial.print(scale1.get_units(10), 4);
// Serial.print(" gram"); //Change this to kg and re-adjust the calibration factor if you follow SI units like a sane person
// Serial.print(" calibration_factor 1: ");
// Serial.print(calibration_factor1);
// Serial.println();
// Serial.print("Reading: ");
// Serial.print(scale2.get_units(10), 4);
// Serial.print(" gram"); //Change this to kg and re-adjust the calibration factor if you follow SI units like a sane person
// Serial.print(" calibration_factor 2: ");
// Serial.print(calibration_factor2);
// Serial.println();
// if(Serial.available())
// {
// char temp1 = Serial.read();
// if(temp1 == '+' || temp1 == 'a')
// calibration_factor1 += 10;
// else if(temp1 == '-' || temp1 == 'z')
// calibration_factor1 -= 10;
// }
// if(Serial.available())
// {
// char temp2 = Serial.read();
// if(temp2 == 'x' || temp2 == 'b')
// calibration_factor2 += 10;
// else if(temp2 == 'y' || temp2 == 'c')
// calibration_factor2 -= 10;
// }
// Serial.println("=====================");
delay(1000);
}