#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
const int TRIG =6;
const int ECO =5;
int Bass=2;
int DURACION;
int DISTANCIA;
void setup() {
lcd.begin(16, 2);
pinMode(TRIG, OUTPUT);
pinMode(ECO, INPUT);
pinMode(Bass,OUTPUT);
// you can now interact with the LCD, e.g.:
lcd.print("Objeto a: ");
}
void loop() {
lcd.setCursor(0, 1);
digitalWrite(TRIG, HIGH);
digitalWrite(Bass, LOW);
delay(1);
digitalWrite(TRIG, LOW);
DURACION=pulseIn(ECO,HIGH);
DISTANCIA=DURACION /58.2;
if (DISTANCIA<=10 && DISTANCIA>=0){
digitalWrite(Bass, HIGH);
delay(120);
}
lcd.print(DISTANCIA);
lcd.print(" Cm");
delay(100);
}