#include <WiFi.h>
#include <WebServer.h>
// Replace with your Wi-Fi credentials
const char* ssid = "YOUR_SSID";
const char* password = "YOUR_PASSWORD";
WebServer server(80);
void setup() {
Serial.begin(115200);
// Connect to Wi-Fi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to Wi-Fi.");
// Start the server
server.on("/", handleRoot);
server.begin();
Serial.println("HTTP server started.");
// Initialize pin 21 as an analog input
analogReadResolution(12); // 12-bit resolution for ESP32
}
void loop() {
// Handle client requests
server.handleClient();
}
void handleRoot() {
int readValue = analogRead(21); // Read the analog value from pin 21
float voltage = readValue * (3.3 / 4095.0); // Convert to voltage
String html = "<!DOCTYPE html><html><head><meta http-equiv='refresh' content='1'/><title>Voltage Reader</title></head><body><h1>Voltage on Pin 21: " + String(voltage) + " V</h1></body></html>";
server.send(200, "text/html", html);
}
Loading
esp32-s2-devkitm-1
esp32-s2-devkitm-1