1
#include <SPI.h>
#include <MFRC522.h>
#include <LiquidCrystal.h>
#include <Servo.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.
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
Servo myservo; // create servo object to control a servo
String read_rfid;
String ok_rfid_1 = "6722323b";
String ok_rfid_2 = "99be859e";
int posClosed = 180; // variable to store the servo position for locked
int posOpen = 0; //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
 lcd.begin(16, 2);
 lcd.clear();
 lcd.print("Scan your card:");
 Serial.println("Scan your card:");
 //Choose which lock below:
 myservo.attach(7); // attaches the servo on pin 7 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 = "";
 for (byte i = 0; i < bufferSize; i++) {
 read_rfid = read_rfid + String(buffer[i], HEX);
 }
}
void open_lock() {
 //Use this routine when working with Servos.
 lcd.print("Servo Unlocking");
 myservo.write(posOpen);
 Serial.println("Servo Unlocking");
 delay(10000);
 myservo.write(posClosed);
 lcd.clear();
 lcd.print("Servo Locking");
 Serial.println("Servo Locking");
}
void loop() {
 lcd.clear();
 lcd.print("test");
 // 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);
 if (read_rfid == ok_rfid_1) {
 open_lock();
 lcd.clear();
 lcd.print(read_rfid + " (FRED FARMER)" + " -Access Granted");
 Serial.println(read_rfid + " (FRED FARMER)" + " -Access Granted");
 delay(10000);
 lcd.clear();
 lcd.print("Scan a card:");
 Serial.println("Scan a card:");
 }
 if (read_rfid == ok_rfid_2) {
 open_lock();
 lcd.clear();
 lcd.print(read_rfid + " (JOHN DOE) " + " -Access Granted");
 Serial.println(read_rfid + " (JOHN DOE) " + " -Access Granted");
 delay(10000);
 lcd.clear();
 lcd.print("Scan a card:");
 Serial.println("Scan a card:");
 } else {
 lcd.clear();
 lcd.print(read_rfid + " -Access Denied");
 Serial.println(read_rfid + " -Access Denied");
 delay(10000);
 lcd.clear();
 lcd.print("Scan your card:");
 Serial.println("Scan your card:");
 }
}

I have tried running the Arduino library's "Hello World" example, and it successfully runs the text onto the screen. Therefore I have determined that it is not a hardware problem, rather a code problem. It occasionally does display "ff" on the LCD, but that's it.

dda
1,5951 gold badge12 silver badges17 bronze badges
asked Jun 13, 2016 at 18:37

1 Answer 1

1

Pins number 12, 11 are used by some other library in your code. And that's the reason there is no LCD output. Change pins/connections from 12, 11 to 7, 6.

Then your code uses lcd.clear() too often, so whatever data you display vanishes before you were able to read. Don't clear the display unnecessarily.

dda
1,5951 gold badge12 silver badges17 bronze badges
answered Jun 14, 2016 at 20:54
3
  • I use the ISCP pins, not all the digital outputs for the MFRC. Commented Jun 15, 2016 at 21:43
  • 3
    Yes, but those pins are connected to the same pins on the chip. If you use SPI, it doesn't matter what connector you get it from, 11, 12, and 13 are off limits and 10 must be an output. Commented Aug 10, 2017 at 20:42
  • I just love it when someone gives the correct answer, and the OP says no it's not right without testing it first... Commented Jan 8, 2018 at 7:50

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.