The circuit in question is designed to interface an ESP8266 NodeMCU microcontroller with a variety of sensors and an OLED display. The primary components include the ESP8266 NodeMCU, a VL53L0X time-of-flight distance sensor, a 0.96" OLED display, a piezo sensor, a photodiode, and two resistors. The circuit is powered by a LiPoly battery. The ESP8266 NodeMCU is programmed to read sensor data, classify pressure, display information on the OLED, and serve a webpage with the current pressure classification.
#include <ESP8266WiFi.h>
#include <ESPAsyncWebServer.h>
#include <VL53L0X.h>
#include <Adafruit_SSD1306.h>
#define PIEZO_PIN 36
#define PHOTODIODE_PIN 37
#define OLED_SDA 21
#define OLED_SCL 22
VL53L0X myLidar;
Adafruit_SSD1306 display(128, 64, &Wire);
const int piezo_threshold_high = 1200;
const int piezo_threshold_low = 800;
const int photodiode_threshold_high = 600;
const int photodiode_threshold_low = 400;
AsyncWebServer server(80);
String pressure_classification;
void setup() {
// Wi-Fi setup
WiFi.begin("YOUR_SSID", "YOUR_PASSWORD");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("Connected to WiFi");
// Initialize sensors
myLidar.init();
myLidar.startContinuous();
// Initialize OLED display
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.display();
// Start web server
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
String response = "<!DOCTYPE html><html><head><title>Eye Pressure Monitor</title></head><body>";
response += "<h1>Current Eye Pressure:</h1>";
response += "<h2>" + pressure_classification + "</h2>";
// ... (add more HTML elements to display historical data, graphs, etc.)
response += "</body></html>";
request->send(200, "text/html", response);
});
server.begin();
}
void loop() {
// Read sensor values
int distance = myLidar.getDistance();
int piezo_value = analogRead(PIEZO_PIN);
int photodiode_value = analogRead(PHOTODIODE_PIN);
// Classify pressure
pressure_classification = classify_pressure(piezo_value, photodiode_value);
// Display on OLED
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.print("Distance: ");
display.println(distance);
display.print("Piezo: ");
display.println(piezo_value);
display.print("Photodiode: ");
display.println(photodiode_value);
display.print("Pressure: ");
display.println(pressure_classification);
display.display();
// Handle web server requests
server.handleClient();
}
The OLED display is controlled by the ESP8266 NodeMCU and does not have separate code.
The provided code for the ESP8266 NodeMCU includes placeholders for Wi-Fi credentials and a function classify_pressure
which is not defined within the given code snippet. The actual implementation of this function should be provided to complete the code documentation. Additionally, the pin definitions in the code do not match the wiring details provided, which suggests that the code may need to be updated to reflect the actual pin connections used in the circuit.