#include <DHT.h>
#define DHTPIN 2 // Digital pin connected to the DHT sensor
#define DHTTYPE DHT22 // DHT 22 (AM2302)
#define SOIL_MOISTURE_PIN A0 // Analog pin for soil moisture sensor
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
dht.begin();
}
void loop() {
// Reading temperature or humidity takes about 250 milliseconds!
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
// Read soil moisture level
int soilMoistureValue = analogRead(SOIL_MOISTURE_PIN);
float soilMoisturePercent = map(soilMoistureValue, 0, 1023, 0, 100); // Arduino ADC is 10-bit (0-1023)
// Print values to serial monitor
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.print(" *C\t");
Serial.print("Soil Moisture: ");
Serial.print(soilMoisturePercent);
Serial.println(" %");
delay(2000); // Wait a few seconds between measurements.
}