#define BLYNK_TEMPLATE_ID "TMPL6cUAkZbPx"
#define BLYNK_TEMPLATE_NAME "Proyek Fermentasi Pintar Tempe"
#define BLYNK_AUTH_TOKEN "5NMSR6O-3So8tfbFaW8qU5EfYl_nLHiU"
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <DHT.h>
#include <LiquidCrystal_I2C.h>
// WiFi credentials
const char* ssid = "Wokwi-GUEST";
const char* password = "";
// DHT sensor
#define DHTPIN 15
#define DHTTYPE DHT22
DHT dht (DHTPIN, DHTTYPE);
// pH sensor (simulated with potentiometer)
#define PHPIN 34
// LCD
LiquidCrystal_I2C lcd (0x27, 16, 2);
// Relay pin
#define RELAYPIN 13
// Blynk virtual pins
#define VPIN_TEMPERATURE V0 // Sebelumnya V1
#define VPIN_HUMIDITY V1 // Sebelumnya V0
#define VPIN_PH V2
#define VPIN_RELAY V3
void setup() {
Serial.begin(115200);
dht.begin();
pinMode (RELAYPIN, OUTPUT);
digitalWrite(RELAYPIN, LOW);
lcd.init(); // Initialize the LCD
lcd.backlight(); // Turn on the LCD backlight
// Welcome message with scrolling text
lcd.setCursor (0, 0);
lcd.print ("Welcome to Smart");
lcd.setCursor(0,1);
lcd.print ("Tempe Fermentation");
delay(2000); // Delay to show the full message initially
for (int i=0; i<16; i++) {
lcd.scrollDisplayLeft(); // Scroll text to the left
delay (300); // Delay 0.3 second between scroll steps
}
lcd.clear();
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
lcd.setCursor (0, 0);
lcd.print ("Connecting to");
lcd.setCursor (0, 1);
lcd.print ("WiFi...");
for (int i = 0; i <16; i++) {
lcd.scrollDisplayLeft(); // Scroll text to the left
delay (300); // Delay 0.3 second between scroll steps
}
lcd.clear();
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
lcd.setCursor (0, 0);
lcd.print ("Connected to WiFi");
for (int i = 0; i <16; i++) {
lcd.scrollDisplayLeft(); // Scroll text to the left
delay (300); // Delay 0.3 second between scroll steps
}
lcd.clear();
Blynk.begin (BLYNK_AUTH_TOKEN, ssid, password);
}
void loop() {
Blynk.run();
float temperature = dht.readTemperature ();
float humidity = dht.readHumidity();
int phValue = analogRead (PHPIN);
float ph = (phValue / 4095.0 )*14.0; // simulate pH scale from 0 to 14
Blynk.virtualWrite (VPIN_TEMPERATURE, temperature);
Blynk.virtualWrite (VPIN_HUMIDITY, humidity);
Blynk.virtualWrite (VPIN_PH, ph);
lcd.setCursor(0, 0);
lcd.print ("Temp: ");
lcd.print (temperature);
lcd.print ("C");
lcd.setCursor (0, 1);
lcd.print ("Hum: ");
lcd.print (humidity);
lcd.print ("%");
delay(2000);
lcd.clear();
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.print(" °C, Humidity: ");
Serial.print (humidity);
Serial.print("%, pH: ");
Serial.println(ph);
if (temperature < 30.0) {
digitalWrite (RELAYPIN, HIGH); // Turn on relay to activate heater
Blynk.virtualWrite (VPIN_RELAY, 1);
lcd.setCursor (0, 0);
lcd.print ("Heater On");
} else {
digitalWrite (RELAYPIN, LOW); // Turn off relay
Blynk.virtualWrite (VPIN_RELAY, 0);
lcd.setCursor(0, 0);
lcd.print ("Heater Off");
}
delay(2000);
}
BLYNK_WRITE(VPIN_RELAY) {
int relayState = param.asInt();
digitalWrite(RELAYPIN, relayState);
}