#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
Wire.begin(23, 22);
Serial.begin(9600);
lcd.init();
lcd.backlight();
}
void loop() {
int nitrogen = analogRead(32);
int phosphorus = analogRead(33);
int potassium = analogRead(34);
float nitrogenPercentage = (float(nitrogen) / 1023.0) * 100.0;
float phosphorusPercentage = (float(phosphorus) / 1023.0) * 100.0;
float potassiumPercentage = (float(potassium) / 1023.0) * 100.0;
// Read soil moisture value
int16_t moistureValue = analogRead(35);
float moisturePercentage = (float(moistureValue) / 1023.0) * 100.0;
String moistureStatus = moisturePercentage < 15.0 ? "DRY" : moisturePercentage > 80.0 ? "WET" : "OK";
// Display NPK Levels
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("N:");
lcd.print(nitrogenPercentage, 1);
lcd.print(" P:");
lcd.print(phosphorusPercentage, 1);
lcd.setCursor(0, 1);
lcd.print(" K:");
lcd.print(potassiumPercentage, 1);
delay(2000);
lcd.clear();
lcd.print("Soil: ");
lcd.print(moistureStatus);
lcd.setCursor(0, 1);
lcd.print("Moisture: ");
lcd.setCursor(10, 1);
lcd.print(moisturePercentage, 1);
delay(2000);
}