Monitoring PH dan Suhu via ESP32 WEBSERVER
Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yangdapat memonitor kadar ph dan suhu dengan menggunakan webserver, maksud webserver disini yaitu menggunakan IP lokal sehingga tidak membutuhkan koneksi internet hanya butuh koneksi wifi saja. untuk lebih jelasnya berikut adalah koding dan komponennya.
a. Komponen
b. Program Arduino IDE
#include <Wire.h>
#include <SPI.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <LiquidCrystal_I2C.h>
#include <Adafruit_ADS1015.h>
LiquidCrystal_I2C lcd(0x27,16,2);
Adafruit_ADS1115 ads1115;
#define ONE_WIRE_BUS 32
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
float TempC;
float pHValue;
int adcPH;
int h;
int TempCx;
int pHValuex;
const char* ssid = "hotspothpku";
const char* password = "123456789";
WiFiServer server(80);
AsyncWebServer server(80);
void setup(){
ads1115.begin();
ads1115.setGain(GAIN_ONE);
Wire.begin();
sensors.begin();
Serial.begin(9600);
lcd.begin();
lcd.clear();
// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
// Start the server
server.begin();
Serial.println("Server started");
// Print the IP address
Serial.print("Use this URL to connect: ");
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.println("/");
}
void loop(){
WiFiClient client = server.available();
adcPH = ads1115.readADC_SingleEnded(0);
pHValue = (adcPH - 1136.84) / 330.283;
sensors.requestTemperatures();
TempC = sensors.getTempCByIndex(0); // Celcius
lcd.setCursor(0,0);
lcd.print("Ph: ");
lcd.print(pHValue);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("Suhu: ");
lcd.print(TempC);
lcd.print(" c ");
// Return the response
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Refresh: 1");
client.println(""); // do not forget this one
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.println("<center>");
client.println("<h1>");
client.println("Monitoring PH dan SUHU");
client.println("</h1>");
client.println("<h3>");
client.println("PH = ");
client.println(pHValue);
client.println("<br>");
client.println("Suhu = ");
client.println(TempC);
client.println(" C");
client.println("<br>");
client.println("</h3>");
client.println("</center>");
client.println("</html>");
delay(1);
//Serial.println("Client disonnected");
//Serial.println("");
delay(200);
}
c. VIDEO HASILNYA
No comments:
Post a Comment