Go Down

Topic: Arduino based door lock (Read 45 times) previous topic - next topic

Dzefri

I've been trying to add RFID sensor to my door so I can unlock it with keychain. Everything worked good when I tried it on breadboard with arduino uno. But when I made pcb for it, then it stopped working. I tried "blink" sample on the pin where relay is and it worked perfectly, but when I try to trigger that pin with sensor it does nothing. Then I  moved the atmega back to arduino board and it worked again, so I think the problem is with communication between atmega and RFID.

>Here is code sample. I just used piece of sample code in library for RFID and changed it a little so there should be no problems.

>I attached picture of wiring I used to make pcb board in case the problem is in there.

(1* I used 3 diodes in series to get 3.3 out of 5V and sensor powerd up, and I checked, there is 3.1V on it)

(2* The connector that is pointed with this arrow is for RFID sonsor and it is wired correctly, same way I wired it when I was testing it on arduino board and breadboard)

**I did not tried this scheme on breadboard, It is not the same because I used arduino board to test it so I don't know where the problem is**

Code: [Select]
/*pinout
SDA     -> 10
SCK     -> 13
MOSI    -> 11
MISO    -> 12
IRQ     -> not connected
GND     -> GND
RST     -> 9
3,3V    -> 3,3V
*/

#include <SPI.h>
#include <MFRC522.h>
byte readCard[4];

constexpr uint8_t RST_PIN = 9;
constexpr uint8_t SS_PIN = 10; 

MFRC522 mfrc522(SS_PIN, RST_PIN);

int master[4]={0x8B,0xD2,0x71,0x5B};
int br=0;
int br_kor=6;

String korisnik[6]={"Bane","Veljko","Milan","Sloba","Kiki","Nenad"};

int otvori=0;

int korisnici[6][4]
{
    {0x8B,0xD2,0x71,0x5B},
    {0x10,0x51,0x3C,0x52},
    {0x9E,0xF3,0x0C,0x85},
    {0x96,0x38,0x10,0x85},
    {0x70,0x38,0xE9,0x87},
    {0x10,0x56,0x6E,0x3B},
};


int compareID(int b, int card[6][4]);

void setup()
{
  delay(5000);
    pinMode(5, OUTPUT);
    digitalWrite(5,0);
    //Serial.begin(9600);
    SPI.begin();
    mfrc522.PCD_Init();
    uint8_t getID();
}

void loop()
{
      delay(1000);
      getID();

      for (br = 0; br < br_kor; br++)
      {
          if(compareID(br,korisnici) == 4)
          {
              Serial.println(br);
              Serial.println(korisnik[br]);
             
              otvori=1;
          }
      }

      if (otvori == 1)
      {
        digitalWrite(5, HIGH);
        delay(5000);
        digitalWrite(5, LOW);
        otvori=0;
      }
}

uint8_t getID()
{
    if (!mfrc522.PICC_IsNewCardPresent())
    {
        return 0;
    }
   
    if (!mfrc522.PICC_ReadCardSerial())
    {
        return 0;
    }

    Serial.println(F("Scanned PICC's UID:"));
   
    for ( uint8_t i = 0; i < 4; i++)
    {
        readCard[i] = mfrc522.uid.uidByte[i];
        Serial.println(readCard[i],HEX);
    }
   
    Serial.println("");
    mfrc522.PICC_HaltA();
    return 1;
}




int compareID(int b, int card[6][4])
{
    int m=0;
   
    for ( uint8_t i = 0; i<4; i++)
    {
        if(card[b][i]==readCard[i])
        {
            m++;
        }
       
        if(b==5)
        {
            readCard[i]=0;
        }
    }
   
    return m;
}


Thank you in advance for your time and help!

Go Up