In this course, you will build a smart door lock system that utilizes RFID technology to grant access to authorized individuals. The system will consist of an Arduino Uno, an RC522 RFID reader, an SG90 servo motor, an LCD 16x2 display, a buzzer, and other supporting components. By the end of the course, you will have a fully functional access control system that can read RFID tags, control a servo motor to lock and unlock a door, and display status messages on an LCD screen.
The system will also feature a buzzer that sounds when an invalid RFID tag is presented, adding an extra layer of security and feedback. You will learn how to connect and program these components to work together seamlessly, creating a robust and reliable access control system. This project is an excellent way to learn about RFID technology, servo motor control, and access control logic, making it a valuable skillset for any aspiring IoT or embedded systems developer.
This course is designed for intermediate learners, assuming a basic understanding of electronics and programming concepts. You will learn how to:
By completing this course, you will gain hands-on experience with popular hardware components and develop a deeper understanding of the underlying technologies. You will also learn how to design and build a practical and useful project that can be applied to real-world scenarios, making it an excellent addition to your portfolio and skillset.
| Component | Arduino Pin |
|---|---|
| RC522 RFID reader | 3.3V, 9, GND, 12, 11, 13, 10 |
| SG90 servo motor | 5V, GND, 8 |
| LCD 16x2 display | 5V, GND, 5, 4, 7, 6, 2, 3 |
| Buzzer | 5, GND |
In this project, we will build an RFID-based access control system using an Arduino Uno, RC522 RFID reader, SG90 servo motor, LCD 16x2 display, and a buzzer. This system will unlock a door with an authorized card, show the status on the LCD, and sound a buzzer on invalid attempts.
Start by gathering all the necessary hardware components, including the Arduino Uno, RC522 RFID reader, SG90 servo motor, LCD 16x2 display, buzzer, breadboard, and jumper wires. Make sure all the components are in good condition and properly packaged.
Connect the RC522 RFID reader to the Arduino Uno as follows:
Connect the SG90 servo motor to the Arduino Uno as follows:
Connect the LCD 16x2 display to the Arduino Uno as follows:
Connect the buzzer to the Arduino Uno as follows:
Write the firmware code to read RFID tags, control the servo motor, and manage the access logic. The code should include the following functionalities:
Upload the firmware code to the Arduino Uno using the Arduino IDE. Make sure to select the correct board, processor, and serial port before uploading the code.
Test the smart door lock system by scanning an authorized RFID tag and verifying that the servo motor unlocks the door and the LCD display shows the correct status. Also, test the system with an invalid RFID tag and verify that the buzzer sounds and the LCD display shows an error message.
If the system is not working as expected, check the following:
```cpp
#include <SPI.h>
#include <MFRC522.h>
#include <Servo.h>
#include <LiquidCrystal.h>
// Define constants for pins and variables
const int RST_PIN = 9; // Reset pin for RC522
const int SS_PIN = 10; // Slave select pin for RC522
const int SERVO_PIN = 6; // Pin for servo motor
const int BUZZER_PIN = 8; // Pin for buzzer
const int LCD_RS = 7; // RS pin for LCD
const int LCD_E = 2; // Enable pin for LCD
const int LCD_D4 = 5; // D4 pin for LCD
const int LCD_D5 = 4; // D5 pin for LCD
const int LCD_D6 = 3; // D6 pin for LCD
const int LCD_D7 = A0; // D7 pin for LCD
// Initialize MFRC522 instance
MFRC522 mfrc522(SS_PIN, RST_PIN);
// Initialize Servo instance
Servo servo;
// Initialize LiquidCrystal instance
LiquidCrystal lcd(LCD_RS, LCD_E, LCD_D4, LCD_D5, LCD_D6, LCD_D7);
// Authorized RFID tag UID
byte authorizedTag[] = {0x12, 0x34, 0x56, 0x78};
void setup() {
// Initialize serial communication for debugging
Serial.begin(9600);
// Initialize SPI bus
SPI.begin();
// Initialize MFRC522
mfrc522.PCD_Init();
// Initialize servo motor
servo.attach(SERVO_PIN);
servo.write(0); // Initialize servo to locked position
// Initialize LCD
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print("Smart Door Lock");
// Initialize buzzer pin as output
pinMode(BUZZER_PIN, OUTPUT);
}
void loop() {
// Look for new cards
if (!mfrc522.PICC_IsNewCardPresent()) {
return;
}
// Select one of the cards
if (!mfrc522.PICC_ReadCardSerial()) {
return;
}
// Get the UID of the card
byte* uid = mfrc522.uid.uidByte;
byte uidSize = mfrc522.uid.size;
// Check if the card is authorized
if (checkAuthorization(uid, uidSize)) {
// Unlock the door
servo.write(90); // Unlock position
lcd.setCursor(0, 1);
lcd.print("Access granted");
delay(2000);
// Lock the door after 2 seconds
servo.write(0); // Lock position
lcd.setCursor(0, 1);
lcd.print(" ");
} else {
// Invalid card, sound the buzzer
tone(BUZZER_PIN, 1000, 500);
lcd.setCursor(0, 1);
lcd.print("Access denied");
delay(1000);
lcd.setCursor(0, 1);
lcd.print(" ");
}
}
// Function to check if the RFID tag is authorized
bool checkAuthorization(byte* uid, byte uidSize) {
// Compare the UID with the authorized tag
for (byte i = 0; i < uidSize; i++) {
if (uid[i] != authorizedTag[i]) {
return false;
}
}
return true;
}
```
1. What is the primary function of the RC522 RFID reader in the smart door lock system? a) To control the servo motor b) To display status on the LCD c) To read RFID tags d) To sound the buzzer Answer: c 2. Which pin of the Arduino Uno is typically used to connect the servo motor signal wire in this project? a) Digital pin 2 b) Digital pin 9 c) Analog pin 0 d) Digital pin 13 Answer: b 3. What is the purpose of the LCD 16x2 display in the smart door lock system? a) To display the RFID tag's unique ID b) To show the system's status and access messages c) To control the servo motor's angle d) To generate a beep sound Answer: b 4. How does the system respond to an invalid RFID card attempt? a) The servo motor unlocks the door b) The LCD displays a welcome message c) The buzzer sounds an alert d) The system remains idle Answer: c 5. In the code, what is the purpose of the delay() function when controlling the servo motor? a) To read the RFID tag's data b) To display a message on the LCD c) To allow the servo motor to reach its target position d) To connect to an external database Answer: c