#define EMISOR 23// EMISOR AL PIN 23 CONECTADO AL TIGGER
#define RECEPTOR 22 // RECEPTOR AL PIN 22 CONECTADO AL ECHO
void setup() {
pinMode(EMISOR, OUTPUT); //CONFIGURO PIN COMO SALIDA
pinMode(RECEPTOR, INPUT); //CONFIGURO COMO ENTRADA
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
}
void loop() {
digitalWrite(EMISOR, HIGH); //ACTIVO PRENDO, PONGO ALTO EMISOR
delay(1); //PAUSA 1 MILISEGUNDO
digitalWrite(EMISOR, LOW); ///////DESACTIVO, APAGO, PONGO EN BAJO EMISOR
//////CREAR VARIABLE/////
int DURACION;
/////////////////////////
DURACION=pulseIn(RECEPTOR, HIGH); //ASIGNO LA DURACION DEL TIEMPO
////////CREO VARIABLE DISTANCIA/////
int DISTANCIA;
////////////////////////////
DISTANCIA=DURACION/58.8; ///divido la duracion y la almaceno en variable distancia
///////////////////////////
Serial.print("la distancia medida es >");
Serial.print(DISTANCIA);
Serial.println("cm");
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
}