Arcade swipe card thing with arduino and rfid

I want to make a point system, like in an arcade where your tap your card and it deducts points from your card and when you tap it again you have less points and so on. Until it runs out and says insufficient balance. I have an arduino uno, an RFID Reader, A servo motor(to hopefully be able to pull in the card after it has been detected by an ultrasonic sensor and finally a led thing with 10 bars. I am really confused, especially about the storing the points on the card thing and reading it then deducting it part. I have planned out the workings and would request someone, in all of their kindness and help, to please help me to design my code. Thanking the generous heart in advance.

PLAN:

For the point thing

Read a block from the card
Get the value
Store it in a variable
gamestates to determine which code block to run
execute the required code
value-value-[the deducted amount]
store it in another variable
and finally upload it back to the card

Please post your code here within code tags, so others can see how you achieved this.

A schematic will help others copy your setup.

If possible, write some accompanying text to explain how your example works.

It will help others that want to follow your tutorial.

Ummm... I am not tutoring anyone, I would actually like help

In which case you did post in the wrong section. Introductory Tutorials is for tutorials that e.g. you write, not for questions. Feel free to write a tutorial once you have solved your problem :wink:

Your topic has been moved to a more suitable location on the forum.

// edit
Fixed some typos.

Thank you soo much, appreciated

I want to make a point system, like in an arcade where your tap your card and it deducts points from your card and when you tap it again you have less points and so on. Until it runs out and says insufficient balance. I have an arduino uno, an RFID Reader, A servo motor(to hopefully be able to pull in the card after it has been detected by an ultrasonic sensor and finally a led thing with 10 bars. I am really confused, especially about the storing the points on the card thing and reading it then deducting it part. I have planned out the workings and would request someone, in all of their kindness and help, to please help me to design my code. Thanking the generous heart in advance.

PLAN:

For the point thing

Read a block from the card
Get the value
Store it in a variable
gamestates to determine which code block to run
execute the required code
value-value-[the deducted amount]
store it in another variable
and finally upload it back to the card

You already have a topic about this; Arcade swipe card thing with arduino and rfid.

Please do not crosspost. Reported this one.

okay

I am just in a hurry cus this is for a science fair and i need help quick
Could you mabye please do something to make it happen fast :wink::sweat_smile:

I have merged your cross-posts @arduinodeveloper99.

Cross-posting is against the Arduino forum rules. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend a lot of time investigating and writing a detailed answer on one topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting can result in a suspension from the forum.

In the future, please take some time to pick the forum category that best suits the subject of your question and then only post once to that forum category. This is basic forum etiquette, as explained in the "How to get the best out of this forum" guide. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

Okay, Thank you

Please tell us which components you have tested and does each work as you expect. Done one at a time, not all together, That will happen when you get each device working.

Running with your eyes closed may be ‘faster’, but you don’t know where you’re going to end up.

Why does no one understand what i am saying?! I am not giving someone a tutorial, I am asking for help, I have mentioned everything in my post, kindly read it properly

You forgot to mention the schematic showing how all is connected. You cannot think of programming until you KNOW how each device operates and you do not know that. So, start at the beginning and tell us what you have tried and the results.


This is the Circuit Diagram

#include <Servo.h>
#include <SPI.h>
#include <MFRC522.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);

 int led1=6;
 int led2=7;
 
#define RST_PIN 9
#define SS_PIN 10
 
byte readCard[4];
String MasterTag = "2717277B";
String MasterTag2 = "6772397B";// REPLACE this Tag ID with your Tag ID!!!
String tagID = "";
 
// Create instances
MFRC522 mfrc522(SS_PIN, RST_PIN);

void setup() 
{
  lcd.init();
  lcd.backlight();
  SPI.begin(); // SPI bus
  mfrc522.PCD_Init(); // MFRC522
   pinMode(led1,OUTPUT);
   pinMode(led2,OUTPUT);
 
  lcd.clear();
  lcd.print(" Access Control ");
  lcd.setCursor(0, 1);
  lcd.print("Scan Your Card>>");
}
 
void loop() 
{
    Serial.begin(9600);
  //Wait until new tag is available
  while (getID()) 
  {
    lcd.clear();
    lcd.setCursor(0, 0);
     
    if (tagID == MasterTag) 
    {
            
      lcd.print(" Access Granted!");
       digitalWrite(led1,HIGH); 
       digitalWrite(led2,LOW);
       
      // You can write any code here like opening doors, switching on a relay, lighting up an LED, or anything else you can think of.
    }
    else
    {
       digitalWrite(led2,HIGH); 
       digitalWrite(led1,LOW);  
      lcd.print(" Access Denied!");
       
    }
     
      lcd.setCursor(0, 1);
      lcd.print(" ID : ");
      lcd.print(tagID);
       
    delay(2000);
     digitalWrite(led2,LOW); 
     digitalWrite(led1,LOW);
    lcd.clear();
    lcd.print(" Access Control ");
    lcd.setCursor(0, 1);
    lcd.print("Scan Your Card>>");
  }
}
 
//Read new tag if available
boolean getID() 
{
  // Getting ready for Reading PICCs
  if ( ! mfrc522.PICC_IsNewCardPresent()) { //If a new PICC placed to RFID reader continue
  return false;
  }
  if ( ! mfrc522.PICC_ReadCardSerial()) { //Since a PICC placed get Serial and continue
  return false;
  }
  tagID = "";
  for ( uint8_t i = 0; i < 4; i++) { // The MIFARE PICCs that we use have 4 byte UID
  //readCard[i] = mfrc522.uid.uidByte[i];
  tagID.concat(String(mfrc522.uid.uidByte[i], HEX)); // Adds the 4 bytes in a single String variable
  }
  tagID.toUpperCase();
  mfrc522.PICC_HaltA(); // Stop reading
  return true;
}

Instead of the Tag ID, I want to get the balance fo the card and be able to write a balance also - Check Original post

Like this: Arduino - RFID CREDIT CARD SYSTEM - YouTube

#include <Servo.h>
#include <SPI.h>
#include <MFRC522.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);

 int led1=6;
 int led2=7;
 
#define RST_PIN 9
#define SS_PIN 10
 
byte readCard[4];
String MasterTag = "2717277B";
String MasterTag2 = "6772397B";// REPLACE this Tag ID with your Tag ID!!!
String tagID = "";
 
// Create instances
MFRC522 mfrc522(SS_PIN, RST_PIN);

void setup() 
{
  lcd.init();
  lcd.backlight();
  SPI.begin(); // SPI bus
  mfrc522.PCD_Init(); // MFRC522
   pinMode(led1,OUTPUT);
   pinMode(led2,OUTPUT);
 
  lcd.clear();
  lcd.print(" Access Control ");
  lcd.setCursor(0, 1);
  lcd.print("Scan Your Card>>");
}
 
void loop() 
{

    MFRC522::MIFARE_Key key;
  for (byte i = 0; i < 6; i++) key.keyByte[i] = 0xFF;

  //some variables we need
  byte block;
  byte len;
  MFRC522::StatusCode status; 
  
    Serial.begin(9600);
  //Wait until new tag is available
  while (getID()) 
  {
    lcd.clear();
    lcd.setCursor(0, 0);
     
    if (tagID == MasterTag) 
    {
            
      lcd.print(" Access Granted!");
       digitalWrite(led1,HIGH); 
       digitalWrite(led2,LOW);
       
      // You can write any code here like opening doors, switching on a relay, lighting up an LED, or anything else you can think of.
    }
    else
    {
       digitalWrite(led2,HIGH); 
       digitalWrite(led1,LOW);  
      lcd.print(" Access Denied!");
       
    }
     
      lcd.setCursor(0, 1);
      lcd.print(" ID : ");
      lcd.print(tagID);
       
    delay(2000);
     digitalWrite(led2,LOW); 
     digitalWrite(led1,LOW);
    lcd.clear();
    lcd.print(" Access Control ");
    lcd.setCursor(0, 1);
    lcd.print("Scan Your Card>>");
  }
}
 
//Read new tag if available
boolean getID() 
{
   MFRC522::MIFARE_Key key;
  for (byte i = 0; i < 6; i++) key.keyByte[i] = 0xFF;

  //some variables we need
  byte block;
  byte len;
  MFRC522::StatusCode status; 
  
  // Getting ready for Reading PICCs
  if ( ! mfrc522.PICC_IsNewCardPresent()) { //If a new PICC placed to RFID reader continue
  return false;
  }
  if ( ! mfrc522.PICC_ReadCardSerial()) { //Since a PICC placed get Serial and continue
  return false;
  }

    byte buffer1[18];

  block = 4;
  len = 18;

  status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, 4, &key, &(mfrc522.uid)); //line 834 of MFRC522.cpp file
  if (status != MFRC522::STATUS_OK) {
    Serial.print(F("Authentication failed: "));
    Serial.println(mfrc522.GetStatusCodeName(status));
    return;
  }

  status = mfrc522.MIFARE_Read(block, buffer1, &len);
  if (status != MFRC522::STATUS_OK) {
    Serial.print(F("Reading failed: "));
    Serial.println(mfrc522.GetStatusCodeName(status));
    return;
  }
  tagID = "";
 for (uint8_t i = 0; i < 16; i++)
  {
    if (buffer1[i] != 32)
    {
      Serial.write(buffer1[i]);
      tagID.concat(String(buffer1[i], HEX));
    }
  }
  Serial.print(" ");
  tagID.toUpperCase();
 mfrc522.PICC_HaltA();
  mfrc522.PCD_StopCrypto1();
  return true;
}

I have experimented with this but i am not getting my desired output
i.e. to display the balance credits on the display, really close but not there yet.

Could someone please help me as my science fair project is due very soon

It is not correct. It is not a schematic it is a physical layout diagram not a schematic. The resolution is too low to see what pins you have connected to your reader. The reader is a 3V3 device, which means any signal you send from the Uno to reader will be a 5V signal, this needs cutting down to 3V3 with a potential divider. Use 1K to ground on the reader input and a 300R or 330R resistor connecting from the Arduino output pin to the reader input.
Any signals going from the reader to the Arduino can be wired directly.

On the software side are you detecting the tag ID correctly? If so you can proceed with reading one sector and writing to it. Use the example code in the library to read to a sector and write to it. You need to access sectors via the keys that encode them.

By default all sectors have two &FF keys, so remember you have to have some code that will originally load the sector with some points and set the access keys. This will be different from the code that you will normally run to read a sector and deduct points.

The hardware is totally fine as i have runned many sample codes to check that.
Coming to the software. See, I am a young coder and am really new to arduino, So I need some help with the code please if you could do that it would be much appreciated.
The coding i have done above is possible the best i can do in a lot of hours.