#define BLYNK_TEMPLATE_ID "TMPL3Ob01oI7P"
#define BLYNK_TEMPLATE_NAME "smart soil nutrition monitoring system"
#define BLYNK_AUTH_TOKEN "21HEIOM4ZG9TyWnl260arpn6oEmSflK-"
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
#include <DHT.h>
DHT dht(4, DHT22);
float temperature;
float humidity;
LiquidCrystal_I2C lcd(0x27, 16, 2); // LCD address and dimensions
char ssid[] = "Wokwi-GUEST"; // Replace with your WiFi SSID
char pass[] = ""; // Replace with your WiFi Password
#define LED_PIN 2 // Replace with the pin connected to your LED
void setup() {
Wire.begin(23, 22);
Serial.begin(115200);
lcd.init();
lcd.backlight();
// Connect to WiFi
Serial.println("Connecting to WiFi");
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nConnected to WiFi");
// Connect to Blynk
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
}
void loop() {
// Soil Moisture Monitoring
int soilMoisture = analogRead(34);
String msg = soilMoisture > 2165 ? "WET" : soilMoisture < 3135 ? "DRY" : "DRY";
lcd.clear();
lcd.print("Soil: ");
lcd.print(msg);
Blynk.virtualWrite(V0, soilMoisture); // Send soil moisture data to Blynk
// Temperature and Humidity Monitoring
temperature = dht.readTemperature();
humidity = dht.readHumidity();
Blynk.virtualWrite(V1, temperature); // Send temperature data to Blynk
Blynk.virtualWrite(V2, humidity); // Send humidity data to Blynk
delay(500);
Blynk.run();
delay(500);
}