const int nitrogenPin = 34; // Analog pin for nitrogen sensor
const int phosphorusPin = 35; // Analog pin for phosphorus sensor
const int potassiumPin = 32; // Analog pin for potassium sensor
// Threshold values for nutrients
const int N_THRESHOLD = 300;
const int P_THRESHOLD = 300;
const int K_THRESHOLD = 300;
void setup() {
// Initialize serial communication
Serial.begin(960);
// Initialize sensors (analog potentiometers in this case)
pinMode(nitrogenPin, INPUT);
pinMode(phosphorusPin, INPUT);
pinMode(potassiumPin, INPUT);
}
void loop() {
// Read sensor values
int nitrogenValue = analogRead(nitrogenPin);
int phosphorusValue = analogRead(phosphorusPin);
int potassiumValue = analogRead(potassiumPin);
// Print sensor values to Serial Monitor
Serial.print("Nitrogen: ");
Serial.print(nitrogenValue);
Serial.print(" | Phosphorus: ");
Serial.print(phosphorusValue);
Serial.print(" | Potassium: ");
Serial.println(potassiumValue);
// Check nutrient levels and provide specific fertilizer advice
String advice = "Fertilizer Advice: ";
bool needsFertilizer = false;
if (nitrogenValue < N_THRESHOLD) {
advice += "Add Nitrogen. ";
needsFertilizer = true;
}
if (phosphorusValue < P_THRESHOLD) {
advice += "Add Phosphorus. ";
needsFertilizer = true;
}
if (potassiumValue < K_THRESHOLD) {
advice += "Add Potassium. ";
needsFertilizer = true;
}
if (needsFertilizer) {
Serial.println(advice);
} else {
Serial.println("Nutrient levels are sufficient.");
}
// No delay, let the loop run continuously
}