0% found this document useful (0 votes)
15 views

Project Code

This document contains code for an Arduino project that uses an RFID reader, scale, and LCD display to measure food waste. It initializes libraries and pins for the components, calibrates the scale, reads RFID tags of plates, weighs plates before and after use to calculate waste, and displays results on the LCD screen with optional serial output. The code sets up the components, enters a continuous loop to read RFID tags, weigh plates, and display/log weight and waste measurements.

Uploaded by

Vikram
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Project Code

This document contains code for an Arduino project that uses an RFID reader, scale, and LCD display to measure food waste. It initializes libraries and pins for the components, calibrates the scale, reads RFID tags of plates, weighs plates before and after use to calculate waste, and displays results on the LCD screen with optional serial output. The code sets up the components, enters a continuous loop to read RFID tags, weigh plates, and display/log weight and waste measurements.

Uploaded by

Vikram
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

#include <MFRC522.

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 array_to_string(byte array[], unsigned int len, char buffer[])


{
for (unsigned int i=0; i < len; i++)
{
byte nib1 = (array[i] >> 4) & 0x0F;
byte nib2 = (array[i] >> 0) & 0x0F;
buffer[i*2+0] = nib1 < 0xA ? '0' + nib1 : 'A' + nib1 - 0xA;
buffer[i*2+1] = nib2 < 0xA ? '0' + nib2 : 'A' + nib2 - 0xA;
}
buffer[len*2] = '\0';
}

/////////////////////////////////////////////////////////////////////////
void setup() {

Serial.begin(9600);

pinMode(VCC2,OUTPUT);
digitalWrite(VCC2,HIGH);
pinMode(GND2,OUTPUT);
digitalWrite(GND2,LOW);

lcd.begin();
lcd.backlight();

Serial.println("LABEL,Date,Time,RFID UID,Weight,Food Waste");

SPI.begin(); // Init SPI bus


mfrc522.PCD_Init(); // Init MFRC522 card

// Set the calibration

lcd.print("Clear tray for");


lcd.setCursor(0,1);
lcd.print("Calibration");
delay(1000);
MyScale.setCalibration(491);
lcd.setCursor(0,0);
lcd.print("Calibration ");
lcd.setCursor(0,1);
lcd.print("Done ");
delay(1000);

lcd.setCursor(0,0);
lcd.print("Place Reference ");
lcd.setCursor(0,1);
lcd.print("Plate ");
delay (5000);

for (int l=0; l<5; l++){


plate_weight = (MyScale.readWeight());
delay(200);
}
lcd.setCursor(0,0);
lcd.print(plate_weight);
lcd.print("g ");
lcd.setCursor(0,1);
lcd.print(" ");
delay(3000);

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 ");
}
}

You might also like