Skip to content

Commit

Permalink
interfacing soil moisture with esp8266
Browse files Browse the repository at this point in the history
  • Loading branch information
amri-tah committed Jun 8, 2024
1 parent 2ae8d1e commit 8d30bb6
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions arduino codes/soil_moisture_esp.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#define AOUT_PIN A0

const int minMoistureValue = 0; // Analog reading for very wet soil
const int maxMoistureValue = 1023; // Analog reading for very dry soil

void setup() {
Serial.begin(115200);
}

void loop() {
int sensorValue = analogRead(AOUT_PIN); // Read the analog value from sensor

// Map the sensor value to a percentage (0% to 100%)
int moisturePercent = map(sensorValue, minMoistureValue, maxMoistureValue, 0, 100);

Serial.print("Moisture: ");
Serial.print(sensorValue);
Serial.print(" -> ");
Serial.print(moisturePercent);
Serial.println("%");

delay(500);
}

0 comments on commit 8d30bb6

Please sign in to comment.