#define trigger 18
#define echo 19
#define pinoPIR 23
float distancia;
const int buzzer = 21;
#define pinoOut 33
#define relay 27

void setup() {
Serial.begin(115200);
pinMode(trigger, OUTPUT); 
pinMode(echo, INPUT); 
pinMode(pinoPIR,INPUT);
pinMode(buzzer, OUTPUT);
pinMode(pinoOut, INPUT);  
pinMode(relay, OUTPUT);

}

void loop() {


if(digitalRead(pinoOut) == LOW){ 

Serial.println ("nivel 1 detectado");
ultrassonico();
delay(1000);
}
else { 
Serial.println ("Nivel 0"); 
delay(1000);
}

}


void ultrassonico(){
distancia = Ultrasonic(trigger,echo);
if (distancia < 20 && digitalRead(pinoOut) == LOW){
Serial.println ("nivel 1 e 2 detectado");
void mip();
delay(1000);
}
else{
loop();
delay(1000);
}

}

void mip(){
if (digitalRead(pinoPIR) == 1) {
password();
delay(1000);
}
else {
ultrassonico();
delay(1000);
}
}

void password(){



}

float Ultrasonic(int a, int b){
int distancia = 0;
while(distancia == 0){
digitalWrite(a, 0);
delayMicroseconds(5);
digitalWrite(a, 1);
delayMicroseconds(5);
float tempo = pulseIn(b,1);
distancia = (tempo/2/29.15);
}
}
NOCOMNCVCCGNDINLED1PWRRelay Module