#include <WiFi.h>
#include "DHT.h"
const char* ssid = "Wokwi-GUEST"; //
const char* password = ""; // Ganti dengan password WiFi Anda
#define DHTPIN 15
#define DHTTYPE DHT22
#define PH_PIN 36
#define WATER_LEVEL_PIN 34
#define TDS_PIN 32
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(115200);
// Mencoba menghubungkan ke WiFi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi terhubung!");
Serial.println("Alamat IP lokal:");
Serial.println(WiFi.localIP());
// Initialize DHT sensor
dht.begin();
}
void loop() {
// Lakukan tugas lain di sini
// Read DHT22
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
// Check if any reads failed and exit early (to try again).
if (isnan(humidity) || isnan(temperature)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// Read pH Meter
int phValue = analogRead(PH_PIN);
float voltage = phValue * (3.3 / 4095.0); // Convert ADC value to voltage
float ph = 3.5 * voltage; // Example conversion, adjust as necessary
// Read Water Level
int waterLevel = analogRead(WATER_LEVEL_PIN);
// Read TDS Meter
int tdsValue = analogRead(TDS_PIN);
float tds = tdsValue * (3.3 / 4095.0); // Example conversion, adjust as necessary
// Print sensor data to Serial
Serial.print("Humidity: ");
Serial.println(humidity);
Serial.print("Temperature: ");
Serial.println(temperature);
Serial.print("pH: ");
Serial.println(ph);
Serial.print("Water Level: ");
Serial.println(waterLevel);
Serial.print("TDS: ");
Serial.println(tds);
delay(2000); // Delay 2 seconds before the next reading
}