Translate

Monitoring PH, Suhu, Turbidity, Jarak IOT Notif Telegram ESP32

Monitoring PH, Suhu, Turbidity, Jarak IOT Notif Telegram ESP32 


        Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang bisa memonitor PH, Suhu, Turbidity, Jarak via IOT Telegram, alat ini menggunakan ESP32 sehingga bagus untuk melakukan pengujian data secara online. untuk lebih jelasnya berikut adalah koding dan komponennya.


1. Komponen



2. Program Arduino IDE

#include <Wire.h> 
#include <SPI.h>
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <UniversalTelegramBot.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);

#define ONE_WIRE_BUS 25
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

const int trigPin = 33;
const int echoPin = 32;
long cm;

//define sound speed in cm/uS
#define SOUND_SPEED 0.034
#define CM_TO_INCH 0.393701

long duration;
float distance;
float distanceInch,distanceInch2;
float TempC;
float pHValue;
//deklarasi pin analog
int ntu;
int adctds,tds,tdsx;
int adcPH;
float TempCx;
int pHValuex;
int ntux;
float ntufix;
float temperature = 25,tdsValue = 0;

char ssid[ ] = "hotspothpku";
char pass[ ] = "123456789";//password wifi

#define BOTtoken "7147669669:AAGLKDRroiHhS1Fao1skULzZhiRPmxxxxxx" //token bot telegram
#define idChat "1148812345" //idbot

WiFiClientSecure client;
UniversalTelegramBot bot(BOTtoken, client);


void setup() {
  Serial.begin(9600);
  Wire.begin();  
  lcd.begin();
  lcd.clear();
  lcd.noCursor();
  sensors.begin();
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
  pinMode(echoPin, INPUT); // Sets the echoPin as an Input

  client.setInsecure();
  Serial.print("Connecting Wifi: ");
  Serial.println(ssid);
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, pass);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
   
}
 
void loop() {

 adctds = analogRead(35);             
 tds = map(adctds, 4096, 1, 0, 100);

 adcPH = analogRead(34); 
 pHValue = (adcPH - 123.026)/589.009;
 
 sensors.requestTemperatures();
 TempC = sensors.getTempCByIndex(0); // Celcius

 digitalWrite(trigPin, LOW);
 delayMicroseconds(2);
 digitalWrite(trigPin, HIGH);
 delayMicroseconds(10);
 digitalWrite(trigPin, LOW);
 duration = pulseIn(echoPin, HIGH);

 cm = microsecondsToCentimeters(duration);

  lcd.setCursor(0,0);
  lcd.print("P/T= ");
  lcd.print(pHValue,1);
  lcd.print("/");
  lcd.print(tds);
  lcd.print("   ");
  lcd.setCursor(0,1);
  lcd.print("J/S= ");
  lcd.print(cm);
  lcd.print("/");
  lcd.print(TempC,1);
  lcd.print("     ");

    bot.sendChatAction(idChat, "Sedang mengetik...");
    delay(1000);
    String suhu = " Nilai ph : ";
    suhu += float(pHValue);
    suhu += " Turbidity: ";
    suhu += int(tds);
    suhu += " Suhu: ";
    suhu += float(TempC);
    suhu += " Jarak: ";
    suhu += int(cm);
    suhu += " cm Terimakasih\n";
    bot.sendMessage(idChat, suhu, "");
    Serial.print("Mengirim data sensor ke telegram");
    
  delay(1000);
}


long microsecondsToCentimeters(long microseconds)
{
// The speed of sound is 340 m/s or 29 microseconds per centimeter.
// The ping travels out and back, so to find the distance of the
// object we take half of the distance travelled.
return microseconds / 29 / 2;
}



3. VIDEO HASILNYA



No comments:

Post a Comment