Hello everyone,
I'm new to arduino and this is my second project.
I wanted to use arduino to unlock a 12V Electric strike door lock by RFID cards and a push button. I'm using the RC522 module and a one channel jqc-3ff-s-z relay. Basically to unlock the door I'd have to scan the card or press the button which should trigger the relay and connect the lock to 12V.
For some reason the RC522 module stops detecting cards right after the first unlock or basically when the 12V load is connected to the other end (door lock). The push button works just fine and keeps unlocking the door.
I tested the relay with the COM and NO of the relay disconnected, and the RC522 module works just fine and keeps scanning. Once I connect the COM and NO, it stops working and then I'd have to re-plug the entire arduino for it work again.
In the beginning, I used an AC-DC12V 1A adaptor with the arduino and the VIN and GND pins of the arduino for the lock and It didn't work: the door unlocks but the RFID reader stops working.
Then, I cut the adaptor and connected one end directly to the door lock, and back to the normal output socket and the other end to normal output socket and the COM of the relay then the other end of the lock to the NO of the relay. That didn't work either.
(something like this, sorry for the crappy quality)
I also tried using separate power supplies for each of the arduino and the door lock (12V 1A for the lock, 12V 2A for the arduino) and one end of the power supply is controlled by the relay but that didn't seem to work either.
(something like this)
I tried using the NC and COM (instead of NO and COM of the relay) and changed the code, but that didn't seem to work either.
I don't think it's a problem with the code for the project because, the serial monitor of RC522 Library dumpinfo also stops once the NC and COM are connected to the 12V adaptor.
Code:
//RFID
#include <SPI.h>
#include <MFRC522.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define SS_PIN 10
#define RST_PIN 9
#define LED_G 4 //define green LED pin
#define LED_R 5 //define red LED
#define BUZZER 7 //buzzer pin
#define BUTTON 2 //BUTTON pin
#define RELAY 8 //RELAY pin
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup()
{
Serial.begin(9600); // Initiate a serial communication
SPI.begin(); // Initiate SPI bus
mfrc522.PCD_Init(); // Initiate MFRC522
pinMode(LED_G, OUTPUT);
pinMode(LED_R, OUTPUT);
pinMode(BUZZER, OUTPUT);
pinMode(RELAY, OUTPUT);// Define RELAY_PIN as OUTPUT for relay
pinMode(BUTTON, INPUT_PULLUP);
noTone(BUZZER);
Serial.println("Put your card to the reader...");
Serial.println();
// initialize the LCD,
lcd.begin();
// Turn on the blacklight and print a message.
lcd.backlight();
digitalWrite(RELAY,LOW);// Turn the relay OFF
}
void OpenDoor() {
Serial.println("DOOR OPENED");
digitalWrite(RELAY, HIGH);// Turn the relay ON
digitalWrite(LED_G, HIGH);
tone(BUZZER, 500);
delay(300);
noTone(BUZZER);
delay(5000);
lcd.clear();
digitalWrite(RELAY,LOW);// Turn the relay OFF
digitalWrite(LED_G, LOW);
}
void loop()
{
int pushButton = digitalRead(BUTTON);
if(pushButton == LOW){
Serial.println("BUTTON PUSHED");
lcd.clear();
lcd.print("Indoor Exit");
OpenDoor();
}
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent())
{
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial())
{
return;
}
//Show UID on serial monitor
Serial.print("UID tag :");
String content= "";
byte letter;
for (byte i = 0; i < mfrc522.uid.size; i++)
{
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
content.concat(String(mfrc522.uid.uidByte[i], HEX));
}
Serial.println();
Serial.print("Message : ");
content.toUpperCase();
if (content.substring(1) == "B1 5B 3E 20" || content.substring(1) == "B9 C3 BC 6E")
{
Serial.println("Authorized access");
lcd.clear();
lcd.print("Access Granted");
lcd.setCursor (0,1); // go to start of 2nd line
if (content.substring(1) == "B1 5B 3E 20") { lcd.print("CARD 1"); }
if (content.substring(1) == "B9 C3 BC 6E") { lcd.print("CARD 2"); }
Serial.println();
OpenDoor();
} else {
Serial.println("Access denied");
lcd.clear();
lcd.print("Access Denied");
digitalWrite(LED_R, HIGH);
tone(BUZZER, 300);
delay(2000);
digitalWrite(LED_R, LOW);
noTone(BUZZER);
}
}
The code has LEDs, LCD, and a buzzer which are not used yet: I ordered them, but they haven't arrived.
The wiring
(I'm using INPUT_PULLUP for the button)
Also, removing the button altogether didn't change anything.
Bottom line, I can't manage to use the relay with the RC522 module; the relay works fine on its own in a different sketch, and the module works fine on its own when the relay is not connected to the 12V.
I can't seem to figure out how to fix this and I've looked everywhere.
Any advice?















