BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

RFID Based Toll Collection System

Here is my code !! Bit messy…Thanks Blynk Community…
This project is about RFID based electronic toll collection gate…Each RFID card has some amount to be paid in toll gate…Then when the car arrives toll gate…the users need to wave their rfid card to rfid reader…Then the system deduct some amount according their car type…Each rfid card contain user identification,License number…and some other information…This project only used ESP8266 NodeMCU and MFRC522 rfid card reader which interface is SPI…The blynk LCD (advanced mode) is used in this project…Thanks…

/**************************************Pin Connection *****************************
 * NodeMCU                MFRC522
 * D4(GPIO2)              SDA(SS)
 * D5(GPIO14)            SCK
 * D7(GPIO13)            MOSI
 * D6(GPIO12)            MISO(SCL)
 * D3(GPIO0)              RST
 *    
 */

#include <SPI.h>
#include <ESP8266WiFi.h>
#include <MFRC522.h>

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

#define BLYNK_PRINT Serial
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxx";
char ssid[] = "xxxxxx";
char pass[] = "xxxxxxxx";

WidgetLCD lcd(V0);
WidgetLCD lcd1(V1);
WidgetLCD lcd2(V2);
WidgetLCD lcd3(V3);
WidgetLCD lcd4(V4);
WidgetLCD lcd5(V5);



#define SS_PIN 4    // D2
#define RST_PIN 5   // D1


MFRC522 mfrc522(SS_PIN,RST_PIN);
unsigned int statusA,statusB,statusC,statusD,statusE;
int out = 0;
unsigned int tempA,tempB,tempC,tempD,tempE;
unsigned int card_event = 0;
unsigned int cardA_bal=10000;
unsigned int cardB_bal  = 9000;
unsigned int cardC_bal  = 5000;
unsigned int cardD_bal  = 3000;
unsigned int cardE_bal  = 0;
unsigned int car_pass=0;
unsigned int d_amount=100,total_amount;


void setup() 
{
  Blynk.begin(auth, ssid, pass);
  Serial.begin(9600);
  SPI.begin();
  mfrc522.PCD_Init();  //Inititate MFRC522

}


void readrfid()
{
    if( mfrc522.PICC_IsNewCardPresent() == 0)
  {
      return ;
  }
  if(! mfrc522.PICC_ReadCardSerial())
  {
      return;
   }
 //Show UID on serial monitor
  Serial.println();
  Serial.print(" UID tag :");
  String content= "";
  byte letter;
  for (byte i = 0; i < mfrc522.uid.size; i++) 
  {
     Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
     Serial.print(mfrc522.uid.uidByte[i], HEX);     
     content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
     content.concat(String(mfrc522.uid.uidByte[i], HEX));
     
  }
  content.toUpperCase();
  Serial.println();
  

  if (content.substring(1) == "34 25 41 6C")   //change UID of the card that you want to give access
  {
    statusA=1;
    
    if(statusA && cardA_bal)
    {
    cardA_bal-=100;
   
    tempA=cardA_bal;
    lcd.clear();
    Serial.println(" Welcome ");
    Serial.println("Ko Yan Myo Aung");
    lcd.print(1,0,"Ko Yan Myo Aung");
    lcd.print(1,1," 8A-2493 ");
    Serial.println(" 8A-2493 ");
   // delay(100);
      if( ! cardA_bal)
       {
          tempA=0;
          
          Serial.println(tempA,DEC);
          Serial.println("Access Denied");
          Serial.println("Check Balance");
           lcd.clear();
           lcd1.clear();
          lcd1.print(1,0,"Access Denied");
          lcd1.print(1,1,"Check Balance");
       }
       else 
         Serial.println(tempA,DEC);
         car_pass+=1;
         total_amount=d_amount * car_pass;
         lcd1.clear();
         lcd2.clear();
         lcd4.clear();
         lcd5.clear();
         lcd4.print(0,0,"Deducted Amount");
         lcd4.print(3,1,d_amount);
         lcd1.print(0,0,"Your Balance is");
         lcd1.print(3,1,tempA);
         lcd1.print(8,1,"Kyats");
         lcd2.print(0,0,"Total Car-Pass");
         lcd2.print(3,1,car_pass);
         lcd5.print(0,0,"Total Amount is ");
         lcd5.print(3,1,total_amount);
         lcd5.print(10,1,"Kyats");
    }
       if(! cardA_bal)
       {
         Serial.println(" Welcome ");
         Serial.println(" Ko Yan Myo Aung ");
         Serial.println(" 8A-2493 ");
         lcd.clear();
         lcd1.clear();
         lcd4.clear();
         lcd4.print(0,0,"Insufficient");
         lcd4.print(8,1,"Balance");
         lcd.print(1,0,"Ko Yan Myo Aung");
         lcd.print(1,1," 8A-2493 ");
         Serial.println("Check Balance");
         lcd1.print(1,1,"Check Balance");
        }
     
    Serial.println("Have a good day");
    Serial.println();
    statusA=0;
  }
  else if (content.substring(1) == "56 2D 89 8D") //change UID of the card that you want to give access
  {
    statusB=1;
    
    if(statusB && cardB_bal )
    {
      cardB_bal-=100;
      tempB=cardB_bal;
    Serial.println(" Welcome ");
    Serial.println(" Ko Aung Naing Tun ");
    Serial.println(" 5C-1246 ");
    lcd.clear();
    lcd1.clear();
    lcd.print(0,0,"U Aung Naing Tun");
    lcd.print(1,1,"5C-1246");
    //delay(100);
      if(! cardB_bal)
       {
          tempB=0;
          Serial.println(tempB,DEC);
          Serial.println("Access Denied");
          Serial.println("Check Balance");
         // lcd.clear();
          lcd1.clear();
          lcd1.print(1,0,"Access Denied");
          lcd1.print(1,1,"Check Balance");
          
       }
       else
         car_pass+=1;
         total_amount=d_amount * car_pass;
         lcd1.clear();
         lcd2.clear();
         lcd4.clear();
         lcd5.clear();
         lcd4.print(0,0,"Deducted Amount");
         lcd4.print(3,1,d_amount);
         lcd1.print(0,0,"Your Balance is");
         lcd1.print(3,1,tempB);
         lcd1.print(8,1,"Kyats");
         lcd2.print(0,0,"Total Car-Pass");
         lcd2.print(3,1,car_pass);
         lcd5.print(0,0,"Total Amount is ");
         lcd5.print(3,1,total_amount);
         lcd5.print(10,1,"Kyats");
       
    }
    if(! cardB_bal)
       {
         Serial.println(" Welcome ");
         Serial.println(" U Aung Naing Tun ");
         Serial.println(" 5C-1246 ");
         lcd.clear();
         lcd1.clear();
         lcd4.clear();
         lcd4.print(0,0,"Insufficient");
         lcd4.print(8,1,"Balance");
         lcd.print(0,0,"U Aung Naing Tun");
         lcd.print(1,1,"5C-1246");
         lcd1.print(1,1,"Check Balance");
         Serial.println("Check Balance");
        }
    
    Serial.println("Have a good day");
    Serial.println();
    statusB=0;
  }
  else if (content.substring(1) == "B2 5E FD BA") //change UID of the card that you want to give access
  {
     statusC=1;
     //car_pass+=1;
    if(statusC && cardC_bal )
    {
      cardC_bal-=100;
      tempC=cardC_bal;
      Serial.println(" Access Granted ");
      Serial.println(" Ko Kaung ");
      Serial.println(" 6B-3294 ");
      lcd.clear();
      lcd1.clear();
      lcd.print(1,0,"Ko Kaung");
      lcd.print(1,1,"6B-3294");
     //delay(100);

       if(! cardC_bal)
       {
          tempC=0;
          Serial.println(tempC,DEC);
          Serial.println("Access Denied");
          Serial.println("Check Balance");
        //  lcd.clear();
          lcd1.clear();
          lcd1.print(1,0,"Access Denied");
          lcd1.print(1,1,"Check Balance");
       }
       else
        car_pass+=1;
         total_amount=d_amount * car_pass;
         lcd1.clear();
         lcd2.clear();
         lcd4.clear();
         lcd5.clear();
         lcd4.print(0,0,"Deducted Amount");
         lcd4.print(3,1,d_amount);
         lcd1.print(0,0,"Your Balance is");
         lcd1.print(3,1,tempC);
         lcd1.print(8,1,"Kyats");
         lcd2.print(0,0,"Total Car-Pass");
         lcd2.print(3,1,car_pass);
         lcd5.print(0,0,"Total Amount is ");
         lcd5.print(3,1,total_amount);
         lcd5.print(10,1,"Kyats");
    }
      
      if(! cardC_bal)
       {
         Serial.println(" Welcome ");
         Serial.println(" Ko Kaung ");
         Serial.println(" 6B-3294 ");
         Serial.println("Check Balance");
         lcd.clear();
         lcd1.clear();
         lcd4.clear();
         lcd4.print(0,0,"Insufficient");
         lcd4.print(8,1,"Balance");
         lcd.print(1,0,"Ko Kaung");
         lcd.print(1,1,"6B-3294");
         lcd1.print(1,1,"Check Balance");
          
        }
   
    Serial.println("Have a good day");
    Serial.println();
    statusC = 0;
  }
 else if (content.substring(1) == "54 53 4F 6C") //change UID of the card that you want to give access
  {
    statusD=1;
    //car_pass+=1;
    if(statusD && cardD_bal )
    {
      cardD_bal-=100;
      tempD=cardD_bal;
      Serial.println(" Access Granted ");
      Serial.println(" Ma Thitsar ");
      Serial.println(" 8A-2483 ");
      lcd.clear();
      lcd1.clear();
      lcd.print(1,0,"Ma Thitsar");
      lcd.print(1,1,"8A-2483");
      lcd1.print(1,0,"Access Denied");
      lcd1.print(1,1,"Check Balance");
      //delay(100);
      if(! cardD_bal)
      {
        tempD=0;
        Serial.println(tempD,DEC);
        Serial.println("Access Denied");
        Serial.println("Check Balance");        
      }
      else
        car_pass+=1;
         total_amount=d_amount * car_pass;
         lcd1.clear();
         lcd2.clear();
         lcd4.clear();
         lcd5.clear();
         lcd4.print(0,0,"Deducted Amount");
         lcd4.print(3,1,d_amount);
         lcd1.print(0,0,"Your Balance is");
         lcd1.print(3,1,tempD);
         lcd1.print(8,1,"Kyats");
         lcd2.print(0,0,"Total Car-Pass");
         lcd2.print(3,1,car_pass);
         lcd5.print(0,0,"Total Amount is ");
         lcd5.print(3,1,total_amount);
         lcd5.print(10,1,"Kyats");
      
    }
      if(! cardD_bal)
       {
         Serial.println(" Welcome ");
         Serial.println("  Ma Thitsar ");
         Serial.println(" 8A-2483 ");
         lcd.clear();
         lcd1.clear();
         lcd4.clear();
         lcd4.print(0,0,"Insufficient");
         lcd4.print(8,1,"Balance");
         lcd.print(1,0,"Ma Thitsar");
         lcd.print(1,1,"8A-2483");
         lcd1.print(1,1,"Check Balance");
         Serial.println("Check Balance");
        }
    
    
    Serial.println("Have a good day");
    Serial.println();
    statusD=0;
  }
  else if (content.substring(1) == "A1 F2 3E D5") //change UID of the card that you want to give access
  {
    statusE=1;
   // car_pass+=1;
    if(statusE)
    {
      if(! cardE_bal)
      {
        Serial.println("Access Denied");
        Serial.println(" Ma Aye Aye ");
        Serial.println(" 9B-1258 ");
        lcd.clear();
        lcd1.clear();
        lcd4.clear();
        lcd.print(1,0,"Ma Aye Aye");
        lcd.print(1,1,"9B-1258");
        lcd4.print(0,0,"Insufficient");
        lcd4.print(8,1,"Balance");
        lcd1.print(1,0,"Access Denied");
        lcd1.print(1,1,"Check Balance");
       // delay(100);
        Serial.println("Go to Recharge Station");
        Serial.println("Have a good day");
      }
    }
   
    statusE=0;
  }
  
  else   {
    Serial.println(" Access Denied ");
        lcd.clear();
        lcd1.clear();
        lcd2.clear();
        lcd1.print(1,0,"Access Denied");
    delay(300);
 }
  
 }



void loop() 
{
  
    Blynk.run();
    readrfid();
     }
2 Likes

It certainly was, when posted without proper formatting :stuck_out_tongue: I fixed it for you…

Blynk - FTFC

Perhaps you can add in some information… Title aside… tell us more about what it is and does, etc.

Perhaps even screen shots and a QR code (Clone, not Share) for your project?

2 Likes

Thank you so much for your formatting…I will upload my screen shots later…

1 Like

@GanLay When? :joy::rofl: