#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// شاشة LCD1602 I2C
LiquidCrystal_I2C lcd(0x27, 16, 2);
// تعريف الأرجل
const int TDS_pin = A0;
const int buzzerPin = 8;
// حد TDS المسموح (ppm)
const int TDS_LIMIT = 1000;
void setup() {
Serial.begin(9600);
pinMode(buzzerPin, OUTPUT);
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("TDS Monitor");
lcd.setCursor(0, 1);
lcd.print("Initializing");
delay(2000);
lcd.clear();
}
void loop() {
int rawValue = analogRead(TDS_pin);
// تحويل القراءة إلى TDS (ppm) – تحويل تدريبي تقريبي
float tdsValue = (rawValue / 1023.0) * 2000; // 0–2000 ppm
// عرض القيمة
lcd.setCursor(0, 0);
lcd.print("TDS: ");
lcd.setCursor(5, 0);
lcd.print(tdsValue, 0);
lcd.print(" ppm");
lcd.setCursor(0, 1);
// منطق الإنذار
if (tdsValue > TDS_LIMIT) {
lcd.print("HIGH SALINITY!");
tone(8, 1000);
} else {
lcd.print("Status: NORMAL");
noTone(8);
}
// عرض على Serial Monitor
Serial.print("TDS: ");
Serial.print(tdsValue, 0);
Serial.println(" ppm");
delay(2000);
}