#include <ESP32Servo.h>
#include <Ultrasonic.h>
// Ultrasonic Pins
int trigPin = 15;
int echoPin = 4;
Ultrasonic ultrasonic(trigPin, echoPin);
// Servo Pin
int servoPin = 18;
Servo myServo;
void setup() {
Serial.begin(115200);
myServo.attach(servoPin);
pinMode(21, INPUT_PULLUP);
}
void loop() {
long distance = ultrasonic.read();
long Height = 400 - distance;
if(digitalRead(21)){
Serial.print("Height: ");
Serial.println(Height);
if (Height >= 122) { // Check if height is 122 cm or more (4 feet or more)
myServo.write(90); // Unlock the door
Serial.println("Door Unlocked: Person taller than 4 feet detected.");
} else {
myServo.write(0); // Lock the door
Serial.println("Door Locked: Person not tall enough.");
}
}
delay(3000); // Delay before the next measurement
}