program ini dibuat Mei 2023 dan direvisi Februari 2024
untuk 6 inputan:
-PT1 : Gross Hotel = IN 34 = range 0-500 psig
-PT2 : OGOL Juliet = IN 35 = range 0-500 psig
-PT3 : OGGL Juliet = IN 32 = range 0-500 psig
-PT4 : Instrument Air Pressure = IN 33 = range 0-300 psig
-PT5 : ESD Loop Pressure = IN 25 = range 0-300 psig
-PT6 : G/L Incoming = IN 26 = range 0-1450 psig
percobaan dengan ESP32 DEV KIT
LCD 20x4 i2c diconnect ke D22=SCL, D21=SDA
program dirangkum gedeasetiawan@gmail.com
*/
#include <WiFi.h>
//lcd
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
//channel: 2413899
//#define WIFI_SSID "RANACITTA"
//#define WIFI_PASSWORD "Pandakgede999"
#define WIFI_SSID "Tselhome-5D61"
#define WIFI_PASSWORD "60699303"
#define API_KEY "K1UO1A5BGCO2PKAE"
// definisi variabel
//PT1 Gross hotel -------------------------------------------------------------------------------
float rumus1;
float zero1 = 463; //(kalo kekecilan hasil psi-nya, ini naikkan) cek saat pressure zero
float maxi1 = 3991; //cek saat pressure max range, cek saat pressure di range maximal psi
float range1 = 500; //range pressure transmitter dalam hal ini 500 psig
float inputpressure1 = 34; //baca data dari Ai
float bacapressure1; //baca data dari inputpressure
//-----------------------------------------------------------------------------------------------
//PT2 OGOL Juliet -------------------------------------------------------------------------------
float rumus2;
float zero2 = 463; //(kalo kekecilan hasil psi-nya, ini naikkan) cek saat pressure zero
float maxi2 = 3991; //cek saat pressure max range, cek saat pressure di range maximal psi
float range2 = 500; //range pressure transmitter dalam hal ini 500 psig
float inputpressure2 = 35; //baca data dari Ai
float bacapressure2; //baca data dari inputpressure
//-----------------------------------------------------------------------------------------------
//PT3 OGGL Juliet -------------------------------------------------------------------------------
float rumus3;
float zero3 = 463; //(kalo kekecilan hasil psi-nya, ini naikkan) cek saat pressure zero
float maxi3 = 3991; //cek saat pressure max range, cek saat pressure di range maximal psi
float range3 = 500; //range pressure transmitter dalam hal ini 500 psig
float inputpressure3 = 32; //baca data dari ANALOG INPUT
float bacapressure3; //baca data dari inputpressure
//-----------------------------------------------------------------------------------------------
//PT4 Instrument Air Pressure--------------------------------------------------------------------
float rumus4;
float zero4 = 467; //(kalo kekecilan hasil psi-nya, ini naikkan) cek saat pressure zero
float maxi4 = 3871; //cek saat pressure max range, cek saat pressure di range maximal psi
float range4 = 300; //range pressure transmitter dalam hal ini 300 psig
float inputpressure4 = 33; //baca data dari ANALOG INPUT
float bacapressure4; //baca data dari inputpressure
//-----------------------------------------------------------------------------------------------
//PT5 ESD Loop Pressure--------------------------------------------------------------------------
float rumus5;
float zero5 = 467; //(kalo kekecilan hasil psi-nya, ini naikkan) cek saat pressure zero
float maxi5 = 3871; //cek saat pressure max range, cek saat pressure di range maximal psi
float range5 = 300; //range pressure transmitter dalam hal ini 300 psig
float inputpressure5 = 25; //baca data dari ANALOG INPUT
float bacapressure5; //baca data dari inputpressure
//-----------------------------------------------------------------------------------------------
//PT6 Gas Lift Pressure Incoming-----------------------------------------------------------------
float rumus6;
float zero6 = 451; //(kalo kekecilan hasil psi-nya, ini naikkan) cek saat pressure zero
float maxi6 = 3987; //cek saat pressure max range, cek saat pressure di range maximal psi
float range6 = 1450; //range pressure transmitter dalam hal ini 1450 psig
float inputpressure6 = 26; //baca data dari ANALOG INPUT
float bacapressure6; //baca data dari inputpressure
//-----------------------------------------------------------------------------------------------
void setup() {
Serial.begin(9600);
lcd.begin(); //lcd inisiasi
//PIN MODE---------------------------------------------------------------------------------------
pinMode(inputpressure1, INPUT);
pinMode(inputpressure2, INPUT);
pinMode(inputpressure3, INPUT);
pinMode(inputpressure4, INPUT);
pinMode(inputpressure5, INPUT);
pinMode(inputpressure6, INPUT);
//-----------------------------------------------------------------------------------------------
// Connect to WiFi network
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi... ");
}
Serial.println("Connected to WiFi");
Serial.println("Hotel Platform Monitoring");
}
void loop() {
// Wait a few seconds between measurements
delay(1000);
//rumus menghitung pressure
//GROSS H===============================================================================================
bacapressure1 = analogRead(inputpressure1);
rumus1 = ((bacapressure1-zero1)*(range1/(maxi1-zero1))); //rumus kalkulasi pressure dlm satuan psig
if (rumus1 < 0) rumus1 = 0;
//OGOL JULIET ==========================================================================================
bacapressure2 = analogRead(inputpressure2);
rumus2 = ((bacapressure2-zero2)*(range2/(maxi2-zero2))); //rumus kalkulasi pressure dlm satuan psig
if (rumus2 < 0) rumus2 = 0;
//OGGL JULIET =========================================================================================
bacapressure3 = analogRead(inputpressure3);
rumus3 = ((bacapressure3-zero3)*(range3/(maxi3-zero3))); //rumus kalkulasi pressure dlm satuan psig
if (rumus3 < 0) rumus3 = 0;
//Instrument Air Pressure==============================================================================
bacapressure4 = analogRead(inputpressure4);
rumus4 = ((bacapressure4-zero4)*(range4/(maxi4-zero4))); //rumus kalkulasi pressure dlm satuan psig
if (rumus4 < 0) rumus4 = 0;
//ESD Loop Pressure====================================================================================
bacapressure5 = analogRead(inputpressure5);
rumus5 = ((bacapressure5-zero5)*(range5/(maxi5-zero5))); //rumus kalkulasi pressure dlm satuan psig
if (rumus5 < 0) rumus5 = 0;
//ESD Loop Pressure====================================================================================
bacapressure6 = analogRead(inputpressure6);
rumus6 = ((bacapressure6-zero6)*(range6/(maxi6-zero6))); //rumus kalkulasi pressure dlm satuan psig
if (rumus6 < 0) rumus6 = 0;
//=====================================================================================================
if (isnan(bacapressure1) || isnan(inputpressure1)) {
Serial.println("Failed to read from pressure transmitter");
return;
}
// Connect to ThingSpeak server
WiFiClient client;
const int httpPort = 80;
if (!client.connect("api.thingspeak.com", httpPort)) {
Serial.println("Connection to ThingSpeak failed");
return;
}
// Send data to ThingSpeak
String url = "/update?key=" + String(API_KEY) +
"&field1=" + String(rumus1) +
"&field2=" + String(rumus2) +
"&field3=" + String(rumus3) +
"&field4=" + String(rumus4) +
"&field5=" + String(rumus5) +
"&field6=" + String(rumus6) +
"&field7=" + String(0.0);
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: api.thingspeak.com\r\n" +
"Connection: close\r\n\r\n");
//print serial
Serial.println(" --------------------------- ");
Serial.print(" Gross H Pressure : ");
Serial.print(rumus1); Serial.println(" psig");
Serial.print(" OGOL J Pressure : ");
Serial.print(rumus2); Serial.println(" psig");
Serial.print(" OGGL J Pressure : ");
Serial.print(rumus3); Serial.println(" psig");
Serial.print(" Inst Air Pressure : ");
Serial.print(rumus4); Serial.println(" psig");
Serial.print(" ESD Loop Pressure : ");
Serial.print(rumus5); Serial.println(" psig");
Serial.print(" Gas Lift Pressure : ");
Serial.print(rumus6); Serial.println(" psig");
//display to LCD 20x4
lcd.setCursor(0,0);
lcd.print("Gross :");
lcd.print(rumus1, 0);
lcd.setCursor(0,1);
lcd.print("OGOL J:");
lcd.print(rumus2, 0);
lcd.setCursor(0,2);
lcd.print("OGGL J:");
lcd.print(rumus3, 0);
lcd.setCursor(0,3);
lcd.print("Instr :");
lcd.print(rumus4, 0);
lcd.setCursor(14,0);
lcd.print("ESD:");
lcd.setCursor(14,1);
lcd.print(rumus5, 0);
lcd.setCursor(14,2);
lcd.print("G/L H:");
lcd.setCursor(14,3);
lcd.print(rumus6, 0);
delay(20000);
Serial.println(" Data sent to ThingSpeak");
}
No comments:
Post a Comment