I had downloaded this code http://duinos.net/files/2015/rfid_lock.ino and have modified it to only light an LED for a few seconds on and later to work with a relay. It is working fine except for the fact that it will work with whatever string code it has received. As if it is not checking for the right code or interpreting any code as the one i have set as ok_rfid. I am somewhat new to the Ardunio platform so if anyone could help me that would be great.
Thanks in advance!
Here is the code what I am using right now
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 9 // Configurable, see typical pin layout above
#define SS_PIN 10 // Configurable, see typical pin layout above
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
String read_rfid;
String ok_rfid_1 = "21";
//String ok_rfid_2="ffffffff"; //add as many as you need.
int ledPin = 4;
//Use the lines below if you plan on using a servo as a locking mechanism.
//#include <Servo.h>
//Servo myservo; // create servo object to control a servo
//int posClosed = 0; // variable to store the servo position for locked
//int posOpen = 360; //same for open...
/*
- Initialize
*/
void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522 card
pinMode(ledPin, OUTPUT);
// myservo.attach(2); // attaches the servo on pin 2 to the servo object
}
/*
Helper routine to dump a byte array as hex values to Serial.
/
void dump_byte_array(byte buffer, byte bufferSize) {
read_rfid = "SDEF sadf s";
for (byte i = 0; i < bufferSize; i++) {
read_rfid = read_rfid + String(buffer, HEX);
- }*
} - //USE LATER FOR COMPUTER AND DOOR*
//void light_led() {
//Use this routine when working with Relays and Solenoids etc.
//digitalWrite(ledPin, HIGH);
//delay(2000);
//digitalWrite(ledPin,LOW);
//}
//Use this routine when working with Servos.
//myservo.write(360);
//delay(2000);
//myservo.write(0);
void loop() { - // Look for new cards*
- if ( ! mfrc522.PICC_IsNewCardPresent())*
- return;*
- // Select one of the cards*
- if ( !mfrc522.PICC_ReadCardSerial())*
- return;*
- dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);*
- Serial.println(read_rfid);*
- if (read_rfid == ok_rfid_1);*
- //ok, open the door.*
- Serial.println(ok_rfid_1);*
- light_led();*
- }*
- //Add below as many "keys" as you want*
- //if (read_rfid==ok_rfid_2) {*
- //also ok, open the door*
- // open_lock();*
- //}*
- // else not needed. Anything else is not ok, and will not open the door...*