// Pin Definitions
int sensorPin = A0; // Potentiometer connected to A0 (simulating hydration sensor)
int ledPin = 13; // LED connected to pin 13
// Variables
int sensorValue = 0;
int hydrationLevel = 888;
int hydrationThreshold = 30; // Hydration alert threshold
void setup() {
Serial.begin(9600); // Initialize serial communication
pinMode(ledPin, OUTPUT); // Set LED pin as output
}
void loop() {
// Read the potentiometer value
sensorValue = analogRead(sensorPin);
// Map the sensor value (0-1023) to a percentage (0-100%)
hydrationLevel = map(sensorValue, 0, 1023, 0, 100);
// Print the hydration level to the Serial Monitor
Serial.print("Hydration Level: ");
Serial.print(hydrationLevel);
Serial.println("%");
// Check if hydration is below the threshold
if (hydrationLevel < hydrationThreshold) {
digitalWrite(ledPin, HIGH); // Turn on LED
Serial.println("Warning: Hydration is low!");
} else {
digitalWrite(ledPin, LOW); // Turn off LED
}
delay(1000); // Delay for 1 second before the next reading
}