#include <LiquidCrystal.h>
// Pins for soil moisture and nutrient sensors
const int soilMoisturePin = A0;
const int nutrientSensorPin = A1;
// Pins for LCD display
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
}
void loop() {
// Read soil moisture and nutrient levels
int soilMoisture = analogRead(soilMoisturePin);
int nutrientLevel = analogRead(nutrientSensorPin);
// Map sensor readings to meaningful values
int moisturePercent = map(soilMoisture, 0, 1023, 0, 100);
int nutrientPercent = map(nutrientLevel, 0, 1023, 0, 100);
// Display readings on LCD
lcd.setCursor(0, 0);
lcd.print("Moisture: ");
lcd.print(moisturePercent);
lcd.print("%");
lcd.setCursor(0, 1);
lcd.print("Nutrient: ");
lcd.print(nutrientPercent);
lcd.print("%");
// Check if nutrient level is low and trigger action
if (nutrientPercent < 30) {
// Add nutrient action here, e.g., turn on a pump
// digitalWrite(nutrientPumpPin, HIGH);
// delay(5000);
// digitalWrite(nutrientPumpPin, LOW);
}
delay(1000); // Update readings every second
}