Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C++
//Include sections

#include <SPI.h>
#include <LiquidCrystal.h>
#include <Servo.h>


//Define Component to Arduino Pins
#define SS_PIN 10
#define RST_PIN 9

#define SERVO_PIN 5

#define Red_LED 6
#define Green_LED 7

#define Buzzer 8

#include <SPI.h>

#include <pitches.h>

#include <require_cpp11.h>
#include <MFRC522.h>
  MFRC522 rfid(10, 9);
  void setup() {
  Serial.begin(115200);
  SPI.begin();
  rfid.PCD_Init();
#include <deprecated.h>
#include <MFRC522Extended.h>

#include <Adafruit_MFRC630_regs.h>
#include <Adafruit_MFRC630_consts.h>
#include <Adafruit_MFRC630.h>



//initialize the library with the numbers of the interface pins
LiquidCrystal lcd(A0, A1, A2, A3, A4, A5);
Servo DoorLock;

//Unique ID of RFID Tag, which you want to give access.
int My_RFID_Tag[5] = {0x58, 0x76, 0x17, 0x10, 0x29};

//variable to hold your Access_card
boolean My_Card = false;

// notes in the melody, taken from:
//File -> Examples -> Digital -> ToneMelody
int melody[] = {
  NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4
};

// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
  4, 8, 8, 4, 4, 4, 4, 4
};

void setup();
{
  // put your setup code here, to run once:
  //set the pins as an input/output
  pinMode(Red_LED, OUTPUT);
  pinMode(Green_LED, OUTPUT);
  pinMode(Buzzer, OUTPUT);

  //Servo Connnected to pin Digital Pin 5
  DoorLock.attach(SERVO_PIN);
  //open the serial port at 9600 baudrate.
  Serial.begin(9600);
  //Initialise the LCD to 16x2 Character Format
  lcd.begin(16, 2);
  //Initialise Servo and RFID
  SPI.begin();
  rfid.PCD_Init();
}

void loop();
{
  // put your main code here, to run repeatedly:

  //First Assume detected card(Or tag) is My_Card,
  //Then later we will check is it My_Card or not!
  My_Card = true;
  DoorLock.write(0); //Servo at 0 Position, Door is Closed.
  lcd.clear();
  lcd.print("Robodia Technology");
  lcd.setCursor(0, 1);
  lcd.print("gy Solutions!");
}
  //Check if any RFID Tags Detected or not?
  if ( rfid.PICC_IsNewCardPresent() )
  {
    //if RFID Tag is detected, check for the Unique ID,
    //and print it on the Serial Window
    if ( rfid.PICC_ReadCardSerial() )
    {
      lcd.clear();
      lcd.print("UNIQUE ID is:- ");
      delay(500);
      lcd.setCursor(0, 1); //Set LCD Cursor to Second Row, First Character

      //Unique id is 5 Digit Number.
      //Printing in HEX for better Understanding
      for ( int i = 0; i < 5; i++ )
      {
        Serial.print(rfid.uid.uidByte[i], HEX);
        Serial.print(" ");
        lcd.print(rfid.uid.uidByte[i], HEX);
        lcd.print(" ");
      }
      delay(500);

      //Compare this RFID Tag Unique ID with your My_RFID_Tag's Unique ID
      for (int i = 0; i < 5; i++)
      {
        //if any one Unique ID Digit is not matching,
        //then make My_Card = false and come out from loop
        //No need to check all the digit!
        if ( My_RFID_Tag[i] != rfid.uid.uidByte[i] )
        {
          My_Card = false;
          break;
        }
      }
      Serial.println();
      delay(1000);

      //If RFID Tag is My_Card then give access to enter into room
      //else dont open the door.
      if (My_Card)
      {
        Serial.println("\nWelcome To Your Room, Shanna!");
        lcd.clear();
        lcd.print("Welcome to Your");
        lcd.setCursor(0, 1);
        lcd.print("Room, Shanna!");
        delay(2000);

        //Turn on the Green LED as an indication of permission is given
        //to access the room.
        digitalWrite(Green_LED, HIGH);

        //Buzzer Config, taken from:
        //File -> Examples -> Digital -> ToneMelody
        // iterate over the notes of the melody:
        int i = 0;
        while (i < 2)
        {
          for (int thisNote = 0; thisNote < 12; thisNote++)
          {
            // to calculate the note duration, take one second
            // divided by the note type.
            //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
            int noteDuration = 1000 / noteDurations[thisNote];
            tone(8, melody[thisNote], noteDuration);
            // to distinguish the notes, set a minimum time between them.
            // the note's duration + 30% seems to work well:
            int pauseBetweenNotes = noteDuration * 1.30;
            delay(pauseBetweenNotes);
            // stop the tone playing:
            noTone(8);
          }
          i =  i + 1;
          delay(500);
        }
        delay(1000);

        //Now, Open the Door with the help of Servo Motor
        DoorLock.write(180);
        delay(200);
        lcd.clear();
        lcd.print("Door is Open");
        lcd.setCursor(0, 1);
        lcd.print("Now!");
        delay(2000);
        lcd.clear();

        //Give 10 Sec delay to enter into room
        //After that door will again closed!
        for (int i = 10; i > 0; i--)
        {
          lcd.print("Door will close");
          lcd.setCursor(0, 1);
          lcd.print("in ");
          lcd.print(i);
          lcd.print(" Sec.HurryUp!");
          delay(1000);
          lcd.clear();
        }

        //Now,Door is closed and Green LED is Turned-Off.
        DoorLock.write(0);
        digitalWrite(Green_LED, LOW);
        delay(200);
        lcd.clear();
        lcd.print("Door is Close");
        lcd.setCursor(0, 1);
        lcd.print("Now!");
        delay(2000);
      }

      // If RFID Tag is not My_Card then
      // Do not open the Door and
      //Turn-On Red LED and Buzzer as an indication of Warning:
      //Somebody else is trying to enter into your room.
      else
      {
        Serial.println("\nGet Out of Here !");
        lcd.clear();
        lcd.print("Card is NOT FOUND!");
        lcd.setCursor(0, 1);
        lcd.print("Get Out of Here!");

        for (int i = 0; i < 7; i++)
        {
          digitalWrite(Buzzer, HIGH);
          digitalWrite(Red_LED, HIGH);
          delay(500);
          digitalWrite(Buzzer, LOW);
          digitalWrite(Red_LED, LOW);
          delay(500);
        }
        delay(1000);
      }
    }
  }
  //Put RFID Reader into Halt, untill it not detects any RFID Tag.
  rfid.PICC_HaltA();
}


i run this and it comes up as Error compiling for board Arduino Mega or Mega 2560 and ive tried everything to fix it

What I have tried:

ive tried everything and even asked my professor but im still having trouble
Posted
Updated 9-Nov-21 10:22am
v2

1 solution

You need to take a big-picture look at this code. This isn't easy for beginners but it is what you have to do to see the problem. Here is a summarization of what you have :
C++
  void setup() {
  Serial.begin(115200);
  SPI.begin();
  rfid.PCD_Init();

// more stuff here

void setup();
{
// more code here
}

void loop();
{
// more code here
}

  //Check if any RFID Tags Detected or not?
  if ( rfid.PICC_IsNewCardPresent() )
  {
  // more code here
  }
}
The first error is the setup function has no visible ending brace. Then there is prototype for setup, with a semicolon, and then more code enclosed in braces. Then there is a prototype for the loop function (with a semicolon) and then more code enclosed in braces. Finally there is another bunch of code.

To be frank, this is just a mess. You have to decide what is real code and what is a prototype. Real code looks like this :
C++
void loop()   // the function loop - this must not have a semicolon!
{
// more code here
}  // code for this function ends with a closing curly brace
while a function prototype has no code and is terminated with a semicolon, like this :
C++
void FunctionPrototype( type argument );
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900