#include <ESP32Servo.h>
#include<LiquidCrystal_I2C.h>
#define servo_pin 18
Servo myservo;
LiquidCrystal_I2C lcd(0x27, 16, 2);
int count = 0;
char c;
String id;
int pos = 0;
void setup() {
Serial.begin(9600);
pinMode(14, OUTPUT);
pinMode(2, INPUT);
myservo.attach(servo_pin);
myservo.write(0);
lcd.init();
lcd.backlight();
lcd.print("Hello, ESP32!");
/*for (pos = 0; pos <= 90; pos += 1)
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(30); // waits 15ms for the servo to reach the position
}
//myservo.write(90);*/
}
void loop() {
bool access_requested = true;
if(digitalRead(2))
{
lcd.print("Please scan your RFID TAG");
while(Serial.available()>0)
{
c = Serial.read();
count++;
id += c;
if(count == 12)
{
Serial.print(id);
//break;
if(id=="AB123456789A")
{
Serial.println("Valid TAG");
digitalWrite(14, HIGH);
for (pos = 0; pos <= 90; pos += 1)
{
myservo.write(pos);
delay(15);
}
delay(5000);
digitalWrite(14, LOW);
for (pos = 90; pos >= 0; pos -= 1)
{
myservo.write(pos);
delay(15);
}
}
else
{
digitalWrite(14, LOW);
Serial.println("Invalid TAG");
}
}
}
count = 0;
id="";
delay(500);
}
}