A simple security system

Hi, I use what I have to make a simple security system.
Except Arduino Mega, I used an LED1602 module and an RFID module.
Here is how i conenct them together.


After the RFID reader detects the ID card, it will sound the LED and sound the buzzer, then send the card number to Arduino via TX port. Then Arduino decides whether the card is authenticated. Then it will output the result to LCD via Serial2 Port.

Put the authenticated card on the antenna:

Put other card on the antenna:

Meanwhile, card number send to PC, to displayed or do other application development.
I display it on Serial Monitor:

Code:

char incomingByte[20];      // for incoming serial data
int i;
boolean compareString(char a_str[], char b_str[], int length)
{
  for(int i=0; i<length; i++)
  {
    if(a_str[i]!=b_str[i])
    return false;
  }
  return true;
}

void setup() {
      Serial.begin(9600);      // opens serial port, sets data rate to 9600 bps
        Serial1.begin(9600);
        Serial2.begin(9600);
        pinMode(7, OUTPUT);
}

void loop() {

      for(i=0;i<19;i++)
       {
       // send data only when you receive data:
      if (Serial1.available() > 0) {
            // read the incoming byte:
            incomingByte[i] = Serial1.read();
                digitalWrite(7, HIGH);
                delay(10);
         }
            
        else
        { 
          digitalWrite(7, LOW);
          incomingByte[i] = '\0';  
          break; 
           
               
      }
       }
        if (i>0)
        {
      Serial.write(incomingByte);
        Serial.println();
        if(compareString(incomingByte, "2900119980290C", 14)== true)
          {
            Serial2.print("$CLEAR\r\n");
            Serial2.print("$PRINT Authenticated\r\n");
          }
        else
         {
          Serial2.print("$CLEAR\r\n");
          Serial2.print("$PRINT Denied\r\n"); 
         }
        delay(2000);
        Serial2.print("$CLEAR\r\n");
        Serial2.print("$PRINT Please check in\r\n"); 
        Serial1.flush();
      
        }
       
        
}

Please give some advice :slight_smile:

Advice about what?

It seems to work great what you made, or did I overlook something?

Nice job swseansw

My advice: find a nice box to package your project ;)

I miss the ‘door open’ part :slight_smile:

Or does it simply deny everyone? (Which is as secure as it gets :D)

if(compareString(incomingByte, "2900119980290C", 14)== true) { Serial2.print("$CLEAR\r\n"); Serial2.print("$PRINT Authenticated\r\n"); dooropen(); } else { Serial2.print("$CLEAR\r\n"); Serial2.print("$PRINT Denied\r\n"); sprayurine(); } Pictures show this part runs OK so I suppose you just write a dooropen() ?

thanks, april, you are right