Tip: after the article is written, the directory can be generated automatically. Please refer to the help document on the right for how to generate it
preface
Out of interest, I made a small experiment of opening the door with IC card by using Internet query and my own brain, which is also the first finished product I made. The method of how to make IC card is specially recorded here, and I will continue to update other experiments I do in the future. Please pay attention
Tip: the following is the main content of this article. The following cases can be used for reference
1, Prepare items?
An Arduino board, an induction module of RC522, a 12V electronic lock, a relay and a device that can provide 12V voltage (I use 8 1.5V batteries in series)
2, Use steps
1. Load Library
Open this interface in Arduino, and then click the management library. The following interface will appear
Install the second MFRC522. If you can't find MFRC522 in this library installer, you can download the library installation package in GITHUB to download the library.
Oil pipe address: https://www.youtube.com/watch?v=KQiVLEhzzV0
Code address: https://www.viralsciencecreativity.com/post/arduino-rfid-sensor-mfrc522-tutorial
2. Looking for source code
I found the video about the access control card in a teacher's blog, and then found the source code under the video. Of course, there are many access card source codes, and I list only one of them.
Tubing address
The code is as follows (example):
//RFID #include <SPI.h> #include <MFRC522.h> #include <Servo.h> #define SS_PIN 10 #define RST_PIN 9 #define LED_G 4 //define green LED pin because I didn't use LED lights in my experiment, I sent the relay to port 4 #define LED_R 5 //define red LED similarly, no LED is used, so the LED in the later program_ R has no effect on program results #Define BUZZER 2 / / BUZZER pin 2 port is a defined BUZZER, and the BUZZER is still not used, so the BUZZER has no impact on the program result. In order to detect whether the card is detected or not, there are often cases in which the card is not detected int i=0; MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance. Servo myServo; //define servo name controls the steering gear void setup() { Serial.begin(9600); // Initiate a serial communication SPI.begin(); // Initiate SPI bus mfrc522.PCD_Init(); // Initiate MFRC522 // myServo.attach(3); //servo pin // myServo.write(0); //servo start position pinMode(LED_G, OUTPUT); digitalWrite(LED_G, HIGH); pinMode(LED_R, OUTPUT); //pinMode(BUZZER, OUTPUT); //noTone(BUZZER); Serial.println("Put your card to the reader..."); Serial.println(); } void loop() { //In order to detect whether the card is detected or not, there are often cases in which the card is not detected i++; Serial.print(i); Serial.print(LED_G); // Look for new cards if ( ! mfrc522.PICC_IsNewCardPresent()) { return; } // Select one of the cards if ( ! mfrc522.PICC_ReadCardSerial()) { 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) == "27 42 90 B4") //change here the UID of the card/cards that you want to give access { Serial.println("Authorized access"); Serial.println(); delay(500); digitalWrite(LED_G, LOW); // tone(BUZZER, 500); delay(300); // noTone(BUZZER); // myServo.write(180); delay(2000); // myServo.write(0); digitalWrite(LED_G, HIGH); } else { Serial.println(" Access denied"); // digitalWrite(LED_R, HIGH); // tone(BUZZER, 300); // delay(1000); //digitalWrite(LED_R, LOW); //noTone(BUZZER); } }
3. Hardware connection
Connect Arduino to RC522 according to the above figure. The physical object after connection is shown in the figure below.
4 read card number
Connect the connected hardware to the computer and read the card number of the IC card.
When uploading, pay attention to selecting the right development board and port
After uploading the program to Arduino and placing the card in RC522, open the port monitor and a string of characters will appear, as shown in the figure
Replace 27 42 90 B4 (the number may be different for different cards) to the position shown in the program
Replace the yellow part with the number just displayed by the port monitor
4 connect relay and electronic lock
Connect the electronic lock and relay as shown in the figure (changed to IN-Digital4 in the figure)
The physical object after connection is shown in the figure (it may be a little messy, hahaha, don't care)
The last step
Connect the connected hardware to the computer, upload the program to Arduino, close the IC card to RC522, and the lock of the door lock will go in.
6 warm tips
1. If the IC card cannot be detected, the electronic lock can be disconnected and tested again. There may be a problem with the connection of the electronic lock
2. Be sure to distinguish the role of the relay. The relay is a switch, and distinguish the role of each port of the relay.
3. If there is a problem, you must be patient to read the program at once and understand the logical relationship in the program. If you do not put the card lock in and the card lock comes out, it must be because the logic is wrong. You only need to change the logic in the program.