16

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

#include <Wire.

h>

#include <LiquidCrystal_I2C.h>

#include <Servo.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

Servo myservo;

#include <SPI.h>

#include "MFRC522.h"

#define RST_PIN D3

#define SS_PIN D4

#define relay D8

int count1 = 0;

int count2 = 0;

MFRC522 mfrc522(SS_PIN, RST_PIN);

String rfid_in = "";

void setup() {

pinMode(relay,OUTPUT);

Serial.begin(9600);

SPI.begin();

mfrc522.PCD_Init();

lcd.begin();

lcd.backlight();

myservo.attach(D0);

myservo.write(0);

lcd.setCursor(4, 0);

lcd.print("Welcome");

int pos = 0;

void loop() {

if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial()) {

rfid_in=rfid_read();

Serial.print(">>>> ");

Serial.println(rfid_in);

if (count1 <=0){
count1 =0;

if (count2 <=0){

count2 =0;

if(rfid_in=="D2 93 A7 1B"){

count1 ++;

Serial.print("count1 = ");

Serial.println(count1);

if(count1 == 1){

lcd.clear();

lcd.setCursor(1, 0);

lcd.print("turn on light");

digitalWrite(relay,!digitalRead(relay));

else if(count1 == 2){

lcd.clear();

lcd.setCursor(1, 0);

lcd.print("turn off light");

digitalWrite(relay,!digitalRead(relay));

count1 --;

count1 --;

delay(2000);

lcd.clear();

lcd.setCursor(4, 0);

lcd.print("Welcome");

if(rfid_in=="47 EC E9 26"){

count2 ++;

Serial.print("count2 = ");

Serial.println(count2);

}
if(count2 == 1){

lcd.clear();

lcd.setCursor(3, 0);

lcd.print("Open door");

myservo.write(180);

else if(count2 == 2){

lcd.clear();

lcd.setCursor(3, 0);

lcd.print("thank you");

myservo.write(0);

count2 --;

count2 --;

delay(2000);

lcd.clear();

lcd.setCursor(4, 0);

lcd.print("Welcome");

delay(100);

String rfid_read() {

String content = "";

for (byte i = 0; i < mfrc522.uid.size; i++)

content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));

content.concat(String(mfrc522.uid.uidByte[i], HEX));

content.toUpperCase();

return content.substring(1);

You might also like