#include <LiquidCrystal.h>
LiquidCrystal lcd(19,23,18,17,16,15);
int Trig_pin =33;
int Echo_pin =32;
long duration;
float Speed_of_sound =0.034;
float dist_in_cm;
void setup() {
// put your setup code here, to run once:
lcd.begin(16,2);
lcd.println("NIHAD");;
Serial.begin(115200);
pinMode(Trig_pin, OUTPUT);
pinMode(Echo_pin,INPUT);
Serial.begin(115200);
}
void loop() {
lcd.setCursor(1,0);
//String f=millis().ToString();
lcd.print(millis()/1000);
delay(300); // this speeds up the simulation
// put your setup code here, to run once:
Serial.begin(115200);
#define buzzer 14
pinMode (buzzer, OUTPUT);
// put your ;ain code here, to run repeatedly:
tone(buzzer, 500,1000);
delay(1000); // this speeds up the simulation
tone(buzzer, 100,1000);
delay(1000); //speedsup the simulation
digitalWrite(Trig_pin, LOW);
delayMicroseconds(2);
digitalWrite(Trig_pin, HIGH);
delayMicroseconds(10);
digitalWrite(Trig_pin,LOW);
duration =pulseIn(Echo_pin,HIGH);
dist_in_cm=duration*Speed_of_sound/2;
Serial.print("distance in cm :");
Serial.println(dist_in_cm);
delay(1000);
}
Loading
esp32-devkit-v1
esp32-devkit-v1