Jump to content

Motorized Door Lock

Hey guys,

I just finished the basic version of my lock and was looking to add some improvements. First I was wondering if it's possible to turn off the power to servo when in the lock position, my servo makes a buzzing noise when the servo is in the lock position. The second is I would like to be able to keep it in a certain position and then when I tap the RFID, it switches. Is this only possible with relays or can I do it with software? Lastly, I have a white switch that I would like to use as the inside manual switch when I can't reach around it, will the switch pictured work. Sorry for the long list, but thanks for any help in advance.

Arduino code:

/*
 * ----------------------------------------------------------------------------
 * This sketch uses the MFRC522 library ; see https://github.com/miguelbalboa/rfid
 * for further details and other examples.
 * 
 * NOTE: The library file MFRC522.h has a lot of useful info. Please read it.
 * 
 * This sketch show a simple locking mechanism using the RC522 RFID module.
 * ----------------------------------------------------------------------------
 * Typical pin layout used:
 * -----------------------------------------------------------------------------------------
 *             MFRC522      Arduino       Arduino   Arduino    Arduino          Arduino
 *             Reader/PCD   Uno           Mega      Nano v3    Leonardo/Micro   Pro Micro
 * Signal      Pin          Pin           Pin       Pin        Pin              Pin
 * -----------------------------------------------------------------------------------------
 * RST/Reset   RST          9             5         D9         RESET/ICSP-5     RST
 * SPI SS      SDA(SS)      10            53        D10        10               10
 * SPI MOSI    MOSI         11 / ICSP-4   51        D11        ICSP-4           16
 * SPI MISO    MISO         12 / ICSP-1   50        D12        ICSP-1           14
 * SPI SCK     SCK          13 / ICSP-3   52        D13        ICSP-3           15
 *
 */
#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="3d265ac2";
String ok_rfid_2="35a5715";
//String ok_rfid_2="ffffffff"; //add as many as you need.
int lock=3; //Which pin the lock will be on if using a relay or solenoid or similar 

//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 = 360;    // 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

    //Choose which lock below:
    //pinMode(lock, OUTPUT);
    myservo.attach(3);  // 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="";
    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.
  myservo.write(0); 
  delay(4000);
  myservo.write(360);
}

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) {
      open_lock();
    }

    if (read_rfid==ok_rfid_2) {
         open_lock();
   }
}

 

20170724_220300.thumb.jpg.ae36c7550f72e19bdca59c442c9c3bd5.jpg

20170724_220325.thumb.jpg.e187fa3f71ea7f2644b5a3aa7fde06f8.jpg

Link to comment
Share on other sites

Link to post
Share on other sites

As for the buzzing, the servo might have reached the end of its travel. Try set the end point a little further back, and see  if it stops.

 

What do you mean by 'keep it in a certain position and then when I tap the RFID, it switches'? I presume this means you wish for the servo to change position when the RFID tag is presented.

 

As for the switch, more photos will be required, as it initially looks good, however the configuration of the contacts inside the switch will determine whether it can be used for your purposes.

Sync RGB fans with motherboard RGB header.

 

Main rig:

Ryzen 7 1700x (4.05GHz)

EVGA GTX 1070 FTW ACX 3.0

16GB G. Skill Flare X 3466MHz CL14

Crosshair VI Hero

EK Supremacy Evo

EVGA SuperNova 850 G2

Intel 540s 240GB, Intel 520 240GB + WD Black 500GB

Corsair Crystal Series 460x

Asus Strix Soar

 

Laptop:

Dell E6430s

i7-3520M + On board GPU

16GB 1600MHz DDR3.

Link to comment
Share on other sites

Link to post
Share on other sites

9 hours ago, unknownmiscreant said:

As for the buzzing, the servo might have reached the end of its travel. Try set the end point a little further back, and see  if it stops.

 

What do you mean by 'keep it in a certain position and then when I tap the RFID, it switches'? I presume this means you wish for the servo to change position when the RFID tag is presented.

 

As for the switch, more photos will be required, as it initially looks good, however the configuration of the contacts inside the switch will determine whether it can be used for your purposes.

I would like it to operate like a key, so that when the RFID key is recognized it stays open and then to close it I would have to tap the key again. Currently it work's like a traditionally RFID where it autolocks after a certain time frame.

Link to comment
Share on other sites

Link to post
Share on other sites

To get that functionality, you just need to modify the software, so that it keeps track of the current state of the lock, and monitor for RFID tags to trigger a change of state.

 

I won't be able to write the code for you, as without identical hardware to what you have, it would be a waste of both of our time.

Sync RGB fans with motherboard RGB header.

 

Main rig:

Ryzen 7 1700x (4.05GHz)

EVGA GTX 1070 FTW ACX 3.0

16GB G. Skill Flare X 3466MHz CL14

Crosshair VI Hero

EK Supremacy Evo

EVGA SuperNova 850 G2

Intel 540s 240GB, Intel 520 240GB + WD Black 500GB

Corsair Crystal Series 460x

Asus Strix Soar

 

Laptop:

Dell E6430s

i7-3520M + On board GPU

16GB 1600MHz DDR3.

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, IsmetUcur said:

O shit I just made a post about dis lol

Really not too hard, I'm just figuring out how to implement a switch. Do you need a part list?

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, Sebastian Kurpiel said:

Really not too hard, I'm just figuring out how to implement a switch. Do you need a part list?

Yes boss, but I need it simple as possible like I'm not good at coding and stuff so yeah thanks

Link to comment
Share on other sites

Link to post
Share on other sites

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×