A
A
AISka12015-06-03 20:47:52
Arduino
AISka1, 2015-06-03 20:47:52

Arduino RFID servo how to write a program for a beginner?

Guys, help, I've already broken my whole head
. I want to make an RFID lock, the server works separately, RFID too, but I can't program it together. There is on the Internet, but there is no verification, so the buttons are also made. And I need a clean keychain. I ask you to throw a program or help solder the servo to RFID programmatically in Arudino
RFID wrote on this example

#include <SPI.h>
#include <MFRC522.h>

#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.

void setup() {
 Serial.begin(9600); // Initialize serial communications with the PC
 SPI.begin();   // Init SPI bus
 mfrc522.PCD_Init(); // Init MFRC522 card
 Serial.println("Scan PICC to see UID and type...");
}

void loop() {
  byte uidCard[4] = {0x93, 0x48, 0x67, 0x9A}; 
  
 if ( ! mfrc522.PICC_IsNewCardPresent()) {
  return;
 }

 // Select one of the cards
 if ( ! mfrc522.PICC_ReadCardSerial()) {
  return;
 }
          
        for (byte i = 0; i < 4; i++) {
          if (uidCard[i] != mfrc522.uid.uidByte[i])
            return;           
        }
        
  Serial.println("OPEN");
  // digitalWrite(); 
  delay(5000);
  // digitalWrite();      
}

the bottom line is that as a key fob with the desired ID is connected so the door opens, if you bring the key fob with the ID again, the door closes, etc.
like if (uidCard[i] != mfrc522.uid.uidByte[i]) and servo 90 grad
open door servo 180 grad
and second
if (uidCard[i] != mfrc522.uid.uidByte[i]) and servo 180 grad
close door servo 0 grad

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander Gusev, 2015-06-03
@AISka1

"separately the server works, rfid too"
What exactly does not work?
If rfid works, then you can perform actions upon triggering
. All actions will come down to fixing the servo angle in a variable and changing it (a very conditional code):
if(servo_angle==180)
servo.write(servo_angle=0);
else
servo.write(servo_angle=180);
well, and delays between RFID readings, so that while the card / key fob is working nearby, there would be no convulsions.

O
Ocelot, 2015-06-04
@Ocelot

Read about finite state machines. You have the simplest here: two states (open-closed), two transitions between them (by rfid). To prevent the lock from bobbing back and forth with a card attached, there are two solutions:
1. (easy) Delay reading rfid after a state change.
2. (correct) Add to the machine two intermediate states
open_2 --(card brought)--> closed_1 --(card removed)--> closed_2 --(card brought)--> open_1 --(card removed)-- > open_2 Something
like that.

M
Max, 2015-06-04
@MaxDukov

I did something similar for the quest - and as experience has shown, another algorithm of work is more convenient:
upon an event (entering a code, presenting a label, etc.), the lock is unlocked for 5-10 seconds - then it is locked back. This is enough for a person to get out / come in.
One "but" - you need a door closer and a latch (or electromagnetic).
in your version, you can track the fact of closing the door - and lock the lock on this event.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question