Hello everyone,
based on my question yesterday I finished soldering my bridging-PCBs (5 pieces). It is just basically a Nano with a power relay where other chips can communicate via SPI (either 3.3V or 5V).
The only module that gives me problems is a RFID-MC522 module. As example I used the standard MC522 project from the example using this library.
When I simply connect the RFID with the Nano (short Jumper cables) and power it over the USB. I almost every time get the response from my key.
I adjusted the code in order to switch my relay (and added some delays after the relay is activated and closed to prevent multiple readings).
#include<Arduino.h>
/*
*
* All the resources for this project: https://www.hackster.io/Aritro
* Modified by Aritro Mukherjee
*
*
*/
#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 10
#define RST_PIN 9
#define RELAY_PIN 5
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
void setup() {
Serial.begin(9600); // Initiate a serial communication
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(500);
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
delay(500);
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
SPI.begin(); // Initiate SPI bus
mfrc522.PCD_Init(); // Initiate MFRC522
pinMode(RELAY_PIN, OUTPUT);
digitalWrite(RELAY_PIN, LOW); //Close the relay
Serial.println("Approximate your card to the reader...");
Serial.println();
}
void loop() {
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent()) {
//Serial.println("start");
//delay(150);
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
delay(150);
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) == "87 35 49 34") { //change here the UID of the card/cards that you want to give access
Serial.println("Authorized access");
Serial.println();
digitalWrite(RELAY_PIN, HIGH); //open the relay
delay(500);
digitalWrite(RELAY_PIN, LOW); //Close the relay
delay(2500);
}
else {
Serial.println(" Access denied");
delay(500);
}
Serial.println("end");
}
void loop1() {
delay(150);
Serial.println("here");
}
Now I connect it to the following PCB and tried following combinations:
-
Power only via USB (upload code, read out serial)
When a serial monitor is opened the key is detected 1-2 times (relay switches)
-
Power via external 9V@2A power supply
Switching works either all the time or not at all. Resetting or reconnected leads to different results
-
Power vial external 9V power supply and connected via USB
Similar behavior as in 2. with less reliability (more often the key is detected 1-2 times). When it works, it works constantly.
In other posts I read about the peak power consumption and that the Nano could not support >50mA and also tried connecting the RFID-module to a adjustable DC-Power (set to 3.3V@3.5A) supply. The error persisted.
I also measured the current drawn from entire circuit and noticed that when it is working the 'idle' current reads 68mA. When the reader is not working I read 42mA.
It is weird behavior, because usually it either works or not. Now I reconnect the power source and sometimes it works. I can not see a pattern other than the current draw, but was not able to determine the source of the problem. My only assumption is that it has to do something with the bridge-PCB, because it works with only the Nano+RFID. Adding peripherals and other functionality leads to unstable behavior.
I know it is hard to debug a custom PCB, especially over the internet, but maybe someone had a similar problem.
