SMART DOOR LOCK SYSTEM
Our project is about Smart Door Lock using NodeMCU ESP8266, RFID, temperature and humidity sensor and Blynk application. This system will be focused on rented house to give convenience and ensure the tenants safety. The tenants need to scan their card at the entrance door and the door of their own room will automatically unlocked. Meanwhile the temperature and humidity sensor were used to detect extreme air conditions in the room. Through this, the owner and tenants can know if something unwanted accident such fire happens in the house.
Supplies
NodeMCU
RFID RC522, KEY RING, WHITE CARD
Jumper Wire (male to male)
Servo
Breadboard
Temperature and Humidity sensor
LED
Wiring Diagram
This is the wiring diagram of our system
Upload Library
Arduino code - Reading RFID Tag
To connect RFID RC522, first thing we need to do is download a library called MFRC522 which simplifies reading from and writing to RFID tags by visiting the GitHub repo.
To install the file, open the Arduino IDE, choose the Sketch > Include Library > Add .Zip Library
Upload Library MFRC522 and Blynk-library-master
Then select the blynk-library-master and MFRC522-1.4.10
Arduino Code
#include <SPI.h>
#include <MFRC522.h>
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
#define SS_PIN 4
#define RST_PIN 5
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
char auth[] ="pkVLAYRBbXh7a8Akk1Yr8btIh1nniAHh"; //replace with your Auth code here
const char* ssid = "UniSZA-WiFi"; // replace with Your SSID
const char* password = "unisza2016"; //replace with your wifi Password
#include <Servo.h>
Servo myServo1; //define servo name
Servo myServo2; //define servo name
#define LED 15 //LED pin
#define DHTPIN 16 // D0
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer temptimer;
SimpleTimer timer;
int fflag = 0;
int eflag = 0;
int pos1 = 0;
int pos2 = 0;
WidgetTerminal terminal(V2);
void sendSensor()
{
float h = dht.readHumidity();
float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Blynk.virtualWrite(V5, t);
Blynk.virtualWrite(V6, h);
Serial.println(t);
Serial.print("Temperature : ");
Serial.print(t);
Serial.print(" Humidity : ");
Serial.println(h);
}
void setup()
{
Serial.begin(115200); // Initiate a serial communication
Blynk.begin(auth, ssid, password);
SPI.begin(); // Initiate SPI bus
myServo1.attach(2); //servo pin D4
myServo2.attach(0); //servo pin D3
myServo1.write(pos1); //servo start position
myServo2.write(pos2);
pinMode(LED, OUTPUT);
dht.begin();
temptimer.setInterval(2500L, sendSensor);
mfrc522.PCD_Init(); // Initiate MFRC522
Serial.println("Put your card to the reader...");
Serial.println();
timer.setInterval(1000L, iot_rfid);
}
void loop()
{
Blynk.run();
timer.run(); // Initiates SimpleTimer
temptimer.run();
}
void iot_rfid(){
// 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], DEC);
content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
content.concat(String(mfrc522.uid.uidByte[i], DEC));
}
Serial.println();
if( (content.substring(1) == "163 201 73 25") && (fflag == 1))
{
Serial.println("User A");
Blynk.virtualWrite(V2, "USER A" );
digitalWrite(LED, HIGH);
delay(250);
digitalWrite(LED, LOW);
myServo1.write(180);
delay(8000);
myServo1.write(0);
}
if( (content.substring(1) == "115 232 180 162") && (eflag == 1))
{
Serial.println("User B");
Blynk.virtualWrite(V2, "USER B" );
digitalWrite(LED, HIGH);
delay(250);
digitalWrite(LED, LOW);
myServo2.write(180);
delay(8000);
myServo2.write(0);
}
else
Serial.println("unregistered user");
digitalWrite(LED, HIGH);
delay(1500);
digitalWrite(LED, LOW);
}
// in Blynk app writes values to the Virtual Pin 3
BLYNK_WRITE(V3)
{
fflag = param.asInt(); // assigning incoming value from pin V3 to a variable
// Blynk.virtualWrite(V2, fflag );
}
// in Blynk app writes values to the Virtual Pin 4
BLYNK_WRITE(V4)
{
eflag = param.asInt(); // assigning incoming value from pin V4 to a variable
}
BLYNK
- Open the app and create a new project and name it as RFID
- Click on the select device and NodeMCU. Set the connection type to WIFI
- Click on the screen and search for tabs to add two tabs with the name Monitoring and Remote.
- Then click on Remote Access Control Tab. Click on empty space and add two buttons. Click on the first button, set the name as user A and choose virtual pin V3. Next, repeat the same method to create V4 as user B. set both button Mode as Switch.
- Click on Terminal setting and named it as Terminal and choose V2 as input. Set the New Line to Yes while Input Line and Autoscroll to on.
- Then click on Gauge setting. Rename the first button as Temp for temperature and choose V5 as Input and set 50 as limit. Then, rename the next button as Humi for humidity and choose V6 as Input and set 100 as limit.
Component Assembly
Step 1: connect the LED, RFID and NodeMCU on breadboard
Step 2: For the RFID sensor, the ground pin needs to be connected with ground pin of NodeMCU.
Step 3: The middle pin of temperature and humidity sensor needs to be connected with D0.
Step 4: The anode on LED will be connected on D8 while the cathode will connect to the ground
Step 5: The servo will connect to the NodeMCU and it will act as the lock
This video will show you how the system works