#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Initialize the LCD
LiquidCrystal_I2C lcd(0x27, 20, 4);
// Pin definitions
const int pot1Pin = 35; // Pin for potentiometer 1
const int pot2Pin = 33; // Pin for potentiometer 2
const int tempPin = 34; // Pin for temperature sensor
const int ledg =32;//led
int temperature;
int pot1Percent;
int pot2Percent;
//blynk
#define BLYNK_TEMPLATE_ID "TMPL6-x9uZmdP"
#define BLYNK_TEMPLATE_NAME "FYP 1"
#define BLYNK_AUTH_TOKEN "z2Q4NC-G_G6w1xlM0YIAD9HrOv88MF1F" // token Blynk
#define BLYNK_PRINT Serial
#include <WiFi.h> //Library WiFi
#include <WiFiClient.h> //Library WiFiClient
#include <BlynkSimpleEsp32.h> //Library BlynkESP32
char ssid[] = "Wokwi-GUEST"; //Nama WiFi yang digunakan
char pass[] = ""; //Password WiFi yang digunakan
BlynkTimer timer; // code push data
void blynk()
{
Blynk.run();
timer.run();
}
void setup() {
// Blynk
Serial.begin(115200); //Menginisiasi serial monitor
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
timer.setInterval(2000L, blynk);
pinMode(ledg, OUTPUT);
digitalWrite(ledg, LOW);
// Initialize the LCD
lcd.init();
lcd.backlight();
// Print welcome message
lcd.setCursor(0, 0);
lcd.print("Water Quality");
lcd.setCursor(0, 1);
lcd.print("Monitoring System");
delay(2000);
// Clear the LCD
lcd.clear();
}
void loop() {
blynk();
// Read values from sensors
int pot1Value = analogRead(pot1Pin);
int pot2Value = analogRead(pot2Pin);
int tempValue = analogRead(tempPin);
// Map potentiometer values to a range (e.g., 0-100)
int pot1Percent = map(pot1Value, 0, 4095, 0, 100);
int pot2Percent = map(pot2Value, 0, 4095, 0, 100);
// Convert temperature sensor value to Celsius (assuming a specific sensor)
// float voltage = tempValue * (3.3 / 4095.0);
// float temperature = (voltage - 0.5) * 100.0; // Example conversion for TMP36 sensor
float temperature=-0.0281*(tempValue) + 85.043;
// Print values to the LCD
lcd.setCursor(0, 0);
lcd.print("Turbi:");
lcd.setCursor(6, 0);
lcd.print(pot1Percent);
lcd.print("% ");
lcd.setCursor(0, 1);
lcd.print("PH :");
lcd.setCursor(6, 1);
lcd.print(pot2Percent);
lcd.print("% ");
lcd.setCursor(0, 2);
lcd.print("Temp :");
lcd.setCursor(6, 2);
lcd.print(temperature);
lcd.print("C ");
Blynk.virtualWrite(V0, temperature);
Blynk.virtualWrite(V1, pot1Percent);
Blynk.virtualWrite(V2, pot2Percent);
// Print values to the Serial Monitor
Serial.print("Turbidity value: ");
Serial.print(pot1Percent);
Serial.print("%, ");
Serial.print("PH value: ");
Serial.print(pot2Percent);
Serial.print("%, ");
Serial.print("Temperature value: ");
Serial.print(temperature);
Serial.println("C");
if(pot1Percent==0 && (pot2Percent>=6.5 &&pot2Percent<=8.5 )&&(temperature>=10 &&temperature<=22))
digitalWrite(ledg, HIGH);
else
digitalWrite(ledg, LOW);// Delay before next reading
delay(1000);
}