Project Code
Project Code
h>
#include <SPI.h>
#include <DFRobot_HX711.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
DFRobot_HX711 MyScale(A2,A3);
#define RST_PIN 9 // Configurable, see typical pin layout above
#define SS_PIN 10 // Configurable, see typical pin layout above
#define VCC2 8 // +5V
#define GND2 7 // GND
MFRC522 mfrc522(SS_PIN, RST_PIN);
////////////////////////////////////////////////////////////////////
int plate_weight;
int food_waste;
int readsuccess;
byte readcard[4];
char str[32] = "";
String StrUID;
//////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
void setup() {
Serial.begin(9600);
pinMode(VCC2,OUTPUT);
digitalWrite(VCC2,HIGH);
pinMode(GND2,OUTPUT);
digitalWrite(GND2,LOW);
lcd.begin();
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("Place Reference ");
lcd.setCursor(0,1);
lcd.print("Plate ");
delay (5000);
if (plate_weight <5)
{
lcd.setCursor(0,0);
lcd.print("Restart Circuit ");
lcd.setCursor(0,1);
lcd.print(" ");
delay(999999);
}
lcd.setCursor(0,0);
lcd.print("Place The Plate");
lcd.setCursor(0,1);
lcd.print("Then Punch ");
}
void loop() {
if(!mfrc522.PICC_IsNewCardPresent()){
return 0;
}
if(!mfrc522.PICC_ReadCardSerial()){
return 0;
}
for(int i=0;i<4;i++){
readcard[i]=mfrc522.uid.uidByte[i]; //storing the UID of the tag in readcard
array_to_string(readcard, 4, str);
StrUID = str;
lcd.setCursor(0,0);
lcd.print(StrUID);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print(" ");
delay(200);
}
mfrc522.PICC_HaltA();
float j=(MyScale.readWeight());
food_waste = j - plate_weight;
Serial.println( (String) "DATA,DATE,TIME," + StrUID + "," + j + "," + food_waste);
if (j > plate_weight)
{
lcd.setCursor(0,0);
lcd.print("Weight = ");
lcd.print(j);
lcd.print("g");
lcd.setCursor(0,1);
lcd.print("Waste = ");
lcd.print(food_waste);
lcd.print("g");
delay(5000);
lcd.setCursor(0,0);
lcd.print("Place Next Plate ");
lcd.setCursor(0,1);
lcd.print("Then Punch ");
}
if (j < plate_weight)
{
lcd.setCursor(0,0);
lcd.print("Place Plate ");
lcd.setCursor(0,1);
lcd.print("Properly ");
}
}