const int pirPin = 2; // PIR sensor connected to Digital Pin 2
const int trigPin = 7; // Trig pin of the ultrasonic sensor
const int echoPin = 6; // Echo pin of the ultrasonic sensor
void setup() {
pinMode(pirPin, INPUT);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
}
void loop() {
// PIR Sensor for Automatic Door
int motion = digitalRead(pirPin);
if (motion == HIGH) {
Serial.println("Motion detected! Opening the door...");
}
// Ultrasonic Sensor for Touchless Faucet
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
long duration = pulseIn(echoPin, HIGH);
int distance = duration / 58.2;
if (distance < 10) {
Serial.println("Object detected within 10 cm! Activating the faucet...");
}
delay(5000);
}