Answer the question
In order to leave comments, you need to log in
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();
}
Answer the question
In order to leave comments, you need to log in
"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.
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.
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 questionAsk a Question
731 491 924 answers to any question