// Include the necessary libraries #include // Define the pin where the moisture sensor is connected const int sensorPin = A2; // Variables to store the sensor value and the mapped value int sensorValue = 0; int mappedValue = 0; void setup() { // Initialize serial communication at 115200 baud Serial.begin(115200); // Initialize the sensor pin as an input pinMode(sensorPin, INPUT); } void loop() { // Read the analog value from the moisture sensor sensorValue = analogRead(sensorPin); // Map the sensor value from 0-4095 to 100-0 // Assuming the ESP32 ADC resolution is 12-bit (0-4095) mappedValue = map(sensorValue, 0, 4095, 100, 0); // Print the sensor value and the mapped value to the serial monitor Serial.print("Moisture Sensor Value: "); Serial.print(sensorValue); Serial.print(" | Mapped Value: "); Serial.println(mappedValue); // Wait for 1 second before reading the value again delay(1000); }