#include <Arduino.h>
void setup() {
// Initialize serial communication at a baud rate of 115200:
Serial.begin(115200);
Serial.println("ESP32 Oxygen Level Calculator");
Serial.println("Enter Oxygen Sensor reading (percentage):");
}
void loop() {
// Check if data is available to read
if (Serial.available() > 0) {
// Read the incoming data as a string
String reading = Serial.readStringUntil('\n');
// Convert the string to a float for percentage of oxygen
float oxygenPercentage = reading.toFloat();
// Print the received oxygen level
Serial.print("Received Oxygen Level: ");
Serial.print(oxygenPercentage);
Serial.println("%");
// Determine the status based on oxygen percentage
if (oxygenPercentage >= 95) {
Serial.println("Status: High - Normal oxygen level");
} else if (oxygenPercentage >= 85 && oxygenPercentage < 95) {
Serial.println("Status: Medium - Caution");
} else {
Serial.println("Status: Low - Dangerously low");
}
// Prompt for next input
Serial.println("Enter next Oxygen Sensor reading (percentage):");
}
delay(500); // Delay a little bit to improve stability
}