16
16
16
h>
#include <LiquidCrystal_I2C.h>
#include <Servo.h>
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;
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() {
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));
lcd.clear();
lcd.setCursor(1, 0);
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);
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() {
content.concat(String(mfrc522.uid.uidByte[i], HEX));
content.toUpperCase();
return content.substring(1);