Objective:
//broadcast ultrasonic sensor telemetry to webpage hosted by ESP32
//by Rico Kanthatham, Skylabworkshop 2024
//pin connections
#define trigPin 5
#define echoPin 18
#define blueLed 2
#define greenLed 22
#define redLed 23
void setup(){
//init Serial Monitor
Serial.begin(9600);
//pin mode specifications
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(blueLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(redLed, OUTPUT);
}
void loop() {
ultrasonicSense(); //run ultrasonic sensor function
}
void ultrasonicSense(){
//send out ultrasonic pulse
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
//receive ultrasonic pulse
duration_us = pulseIn(echoPin, HIGH);
distance_cm = 0.017 * duration_us;
//print ultrasonic telemetry
Serial.print("distance: ");
Serial.print(distance_cm);
Serial.println(" cm");
}
Asynchronous web server using the ESPAsynchWebServer library
HTML to buld the web page will be store on the ESP32 Filesystem (SPIFFS)
Must use pre-2.0 Arduino to utilize ESP32 SPIFF File Loader
Tutorial to install SPIFFS for ESP32 here
The ESP32 File Loader can be downloaded here
When ESP File Loader is installed properly in the Arduino IDE, a new menu item will appear…
To display charts…use the ichartsjs library