#include <Ultrasonic.h>
Ultrasonic ultrasonic(4,14);
const int trigPin = 4;
const int echoPin = 14;
const int led = 2;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(led, OUTPUT);
}
void loop() {
int distance = ultrasonic.read();
if (distance < 100) {
digitalWrite(led, HIGH);
}
else{
digitalWrite(led, LOW);
}
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
}