#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <DHT.h>
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27, 16, 2); // Set the LCD address to 0x27 for a 16 chars and 2 line display
int sensorPin = A0; // Soil moisture sensor connected to A0
int sensorValue = 0; // Variable to store sensor value
int threshold = 500; // Moisture threshold value
void setup() {
lcd.begin(16, 2); // Initialize the LCD with 16 columns and 2 rows
lcd.backlight();
dht.begin();
Serial.begin(9600);
}
void loop() {
sensorValue = analogRead(sensorPin); // Read the value from the sensor
float temp = dht.readTemperature();
float humidity = dht.readHumidity();
lcd.setCursor(0, 0);
lcd.print("Moisture: ");
lcd.print(sensorValue);
lcd.setCursor(0, 1);
lcd.print("Temp: ");
lcd.print(temp);
lcd.print("C Hum: ");
lcd.print(humidity);
lcd.print("%");
Serial.print("Soil Moisture Value: ");
Serial.println(sensorValue); // Print the sensor value to the serial monitor
Serial.print("Temperature: ");
Serial.print(temp);
Serial.println(" *C");
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %");
delay(2000); // Wait for 2 seconds before repeating the loop
}
// Components Needed:
// Arduino Uno: The microcontroller board.
// Soil Moisture Sensor: To measure the moisture level in the soil.
// DHT Sensor: DHT11 or DHT22 to measure temperature and humidity.
// I2C LCD Display: To display the moisture level and temperature.
// Resistor (220 ohm): For the LED (optional).
// Breadboard and Jumper Wires: For connections.
// Power Supply: 9V battery or USB power.
// Step 1: Circuit Diagram
// Here's how you can connect the components:
// Soil Moisture Sensor:
// VCC: Connect to 5V on the Arduino.
// GND: Connect to GND on the Arduino.
// AO (Analog Output): Connect to Analog Pin A0 on the Arduino.
// DHT Sensor:
// VCC: Connect to 5V on the Arduino.
// GND: Connect to GND on the Arduino.
// Data: Connect to Digital Pin 2 on the Arduino.
// I2C LCD Display:
// VCC: Connect to 5V on the Arduino.
// GND: Connect to GND on the Arduino.
// SDA: Connect to A4 on the Arduino.
// SCL: Connect to A5 on the Arduino.