#include <ESP32WiFi.h>
#include <WiFiClient.h>
#include <WiFiUdp.h>
#include <ESP32HTTPClient.h>
#include <UrlEncode.h>
const char *ssid = "WOKWI-Guest";
const char *password = "";
String phoneNumber = "6289611587524";
String apiKey = "5713236";
void pesan1(String message) {
String url = "http://api.callmebot.com/whatsapp.php?phone=" + phoneNumber + "&apikey=" + apiKey + "&text=" + urlEncode(message);
WiFiClient client;
HTTPClient http;
http.begin(client, url);
// Specify content-type header
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
// Send HTTP POST request
int httpResponseCode = http.POST(url);
if (httpResponseCode == 200) {
Serial.print("Message sent successfully");
}
else {
Serial.println("Error sending the message");
Serial.print("HTTP response code: ");
Serial.println(httpResponseCode);
}
// Free resources
http.end();
}
#define trig 18
#define echo 19
#define valve 14
const int setpoint = 20;
int tinggi_limbah = 0;
float duration_us, distance_cm;
void setup() {
Serial.begin (9600);
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
pinMode(valve, OUTPUT);
}
void loop() {
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
int durasi = pulseIn(echo, HIGH);
int jarak = 0.017 * durasi;
if (jarak <= setpoint)
{digitalWrite(valve, HIGH); Serial.print("Saluran Ditutup!!!");}
else
{digitalWrite(valve, LOW); Serial.print("Saluran Dibuka!!");
}
Serial.print("distance: ");
Serial.print(jarak);
Serial.println(" cm");
delay(500);
}