/*
-------------------------------------
SPESIFIKASI TANDON YANG DIGUNAKAN
Merk : Penguin
Model : TB 110
Tinggi : 142 cm
Diameter : +/- 100 cm
Tinggi tampungan air : +/- 130 cm
Volume : 1050 liter
-------------------------------------
KONFIGURASI PIN
Trig = 2
Echo = 0
Relay = 15
SCL = D22
SDA = D21
*/
#define TRIGGER_PIN 2
#define ECHO_PIN 0
#define RELAY_PIN 15
#define tinggi_tandon 130 // Tinggi tandon (cm)
#define volume_tandon 1050 // Volume tandon dalam liter
#define batas_bawah 20 // Batas ketinggian air untuk menyalakan pompa (cm)
#define batas_atas 120 // Batas ketinggian air untuk mematikan pompa (cm)
#include <Adafruit_SSD1306.h>
#include <Wire.h>
Adafruit_SSD1306 display(128, 64, &Wire, -1);
const unsigned char L_flow [] PROGMEM = {
0x38, 0x00, 0x44, 0x10, 0x82, 0x10, 0x81, 0x20, 0x00, 0xc0, 0x38, 0x00, 0x44, 0x10, 0x82, 0x10,
0x81, 0x20, 0x00, 0xc0
};
const unsigned char L_waktu [] PROGMEM = {
0x0c, 0x00, 0x33, 0x00, 0x40, 0x80, 0x42, 0x80, 0x84, 0x40, 0x88, 0x40, 0x40, 0x80, 0x40, 0x80,
0x33, 0x00, 0x0c, 0x00
};
const unsigned char L_tinggi [] PROGMEM = {
0x10, 0x20, 0x10, 0x70, 0x38, 0xa8, 0x38, 0x20, 0x7c, 0x20, 0xfe, 0x20, 0xf6, 0x20, 0x6c, 0xa8,
0x7c, 0x70, 0x10, 0x20
};
bool pompa;
int tinggi_air, volume, persentase, y, h;
long durasi, jarak;
void setup() {
Wire.begin(-1, -1);
Serial.begin(115200);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;);
}
display.clearDisplay();
Serial.begin(115200);
pinMode(TRIGGER_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
pinMode(RELAY_PIN, OUTPUT);
}
void baca_keadaan() {
digitalWrite(TRIGGER_PIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIGGER_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIGGER_PIN, LOW);
durasi = pulseIn(ECHO_PIN, HIGH);
jarak = (durasi / 2) / 29.1;
tinggi_air = tinggi_tandon - jarak;
volume = tinggi_air * (volume_tandon / tinggi_tandon);
persentase = tinggi_air * 100 / tinggi_tandon;
y = 49 - (persentase / 4);
if (y == 0) {y = 1;}
h = persentase / 4;
if (h == 0) {h = 1;}
}
void updateDisplay() {
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(1);
display.setFont(NULL);
display.setCursor(2, 2);
display.println("MONITORING TANDON AIR");
display.drawLine(5, 11, 123, 11, 1);
display.drawRoundRect(2, 22, 24, 29, 3, 1);
display.fillRoundRect(5, 19, 18, 3, 3, 1);
display.setTextSize(1);
display.fillRect(4, y, 20, h, 1);
display.setCursor(3, 54);
display.print(String(persentase)+"%");
display.drawBitmap(36, 19, L_flow, 12, 10, WHITE);
display.drawBitmap(37, 35, L_waktu, 10, 10, WHITE);
display.drawBitmap(36, 51, L_tinggi, 13, 10, WHITE);
display.setCursor(55, 20);
display.print("5 L/j");
display.setCursor(55, 36);
display.print("20 m");
display.setCursor(55, 52);
display.print(String(tinggi_air)+" cm");
display.display();
}
void loop() {
baca_keadaan();
Serial.print("Tinggi Air : ");
Serial.print(tinggi_air);
Serial.println(" cm");
Serial.println("Volume Air : "+String(volume)+" Liter");
Serial.println("Volume Air : "+String(persentase)+"%");
if ((tinggi_air <= batas_bawah) && !pompa) {
digitalWrite(RELAY_PIN, HIGH);
Serial.println("Mengaktifkan Pompa");
pompa = 1;
} else if ((tinggi_air >= batas_atas) && pompa){
digitalWrite(RELAY_PIN, LOW);
Serial.println("Mematikan Pompa");
pompa = 0;
}
updateDisplay();
delay(1000);
}