first commit
This commit is contained in:
commit
9bad96d9f7
|
@ -0,0 +1,25 @@
|
|||
#include "DHT.h"
|
||||
|
||||
#define DHTPIN 4 // Pin data DHT11 terhubung ke pin 4 Arduino
|
||||
#define DHTTYPE DHT11 // Tipe sensor DHT (DHT11 untuk sensor DHT11)
|
||||
|
||||
DHT dht(DHTPIN, DHTTYPE);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600); // Mulai komunikasi serial dengan kecepatan 9600 bps
|
||||
Serial.println("DHT11 test!");
|
||||
dht.begin(); // Inisialisasi sensor DHT
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Baca data suhu dan kelembaban
|
||||
float temperature = dht.readTemperature();
|
||||
float humidity = dht.readHumidity();
|
||||
|
||||
Serial.print("Suhu (C): ");
|
||||
Serial.println(temperature);
|
||||
Serial.print("Kelembaban (%): ");
|
||||
Serial.println(humidity);
|
||||
|
||||
delay(2000); // Tunggu 2 detik sebelum membaca data lagi
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
#include <OneWire.h>
|
||||
#include <DallasTemperature.h>
|
||||
|
||||
// Pin data sensor DS18B20 terhubung ke pin D4 (GPIO2) pada ESP8266
|
||||
const int oneWireBus = 2; // D4 pada NodeMCU
|
||||
|
||||
// Inisialisasi sensor suhu DS18B20
|
||||
OneWire oneWire(oneWireBus);
|
||||
DallasTemperature sensors(&oneWire);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
sensors.begin(); // Inisialisasi sensor suhu
|
||||
}
|
||||
|
||||
void loop() {
|
||||
sensors.requestTemperatures(); // Mengambil data suhu dari sensor
|
||||
|
||||
// Membaca suhu dalam derajat Celsius
|
||||
float temperatureC = sensors.getTempCByIndex(0);
|
||||
|
||||
// Membaca suhu dalam derajat Fahrenheit
|
||||
float temperatureF = sensors.getTempFByIndex(0);
|
||||
|
||||
// Menampilkan hasil ke Serial Monitor
|
||||
Serial.print("Suhu Celsius: ");
|
||||
Serial.print(temperatureC);
|
||||
Serial.print(" C, Suhu Fahrenheit: ");
|
||||
Serial.print(temperatureF);
|
||||
Serial.println(" F");
|
||||
|
||||
delay(1000); // Delay 1 detik
|
||||
}
|
Binary file not shown.
|
@ -0,0 +1,33 @@
|
|||
#include "DHT.h"
|
||||
|
||||
#define DHTPIN 4 // Pin data DHT11 terhubung ke pin 4 Arduino
|
||||
#define DHTTYPE DHT11 // Tipe sensor DHT (DHT11 untuk sensor DHT11)
|
||||
|
||||
#define SENSOR_PH A0 // Pin analog untuk sensor pH air
|
||||
|
||||
DHT dht(DHTPIN, DHTTYPE);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600); // Mulai komunikasi serial dengan kecepatan 9600 bps
|
||||
Serial.println("DHT11 & pH Sensor test!");
|
||||
dht.begin(); // Inisialisasi sensor DHT
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Baca data suhu dan kelembaban
|
||||
float temperature = dht.readTemperature();
|
||||
float humidity = dht.readHumidity();
|
||||
|
||||
// Baca data pH air
|
||||
float pHValue = analogRead(SENSOR_PH);
|
||||
pHValue = (5.0 / 1023.0) * pHValue; // Konversi nilai bacaan analog menjadi nilai pH
|
||||
|
||||
Serial.print("Suhu (C): ");
|
||||
Serial.println(temperature);
|
||||
Serial.print("Kelembaban (%): ");
|
||||
Serial.println(humidity);
|
||||
Serial.print("pH Air: ");
|
||||
Serial.println(pHValue);
|
||||
|
||||
delay(2000); // Tunggu 2 detik sebelum membaca data lagi
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
#define BLYNK_TEMPLATE_ID "TMPL6a-maPvoQ" // Ganti dengan ID template Blynk Anda
|
||||
#define BLYNK_TEMPLATE_NAME "TUGAS AKHIR" // Ganti dengan nama template Blynk Anda
|
||||
|
||||
#define BLYNK_PRINT Serial
|
||||
|
||||
#include <SPI.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <BlynkSimpleEsp8266.h>
|
||||
#include <OneWire.h>
|
||||
#include <DallasTemperature.h>
|
||||
|
||||
char auth[] = "ywaI_EsL3VnfWJZn8PGXb03-FDaXU_vY"; // Ganti dengan token otentikasi Blynk Anda
|
||||
|
||||
// Pin data sensor DS18B20 terhubung ke pin D4 (GPIO2) pada ESP8266
|
||||
const int oneWireBus = 2; // D4 pada NodeMCU
|
||||
|
||||
// Inisialisasi sensor suhu DS18B20
|
||||
OneWire oneWire(oneWireBus);
|
||||
DallasTemperature sensors(&oneWire);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Blynk.begin(auth, "JTI12", "12345678"); // Ganti dengan SSID dan password WiFi Anda
|
||||
sensors.begin(); // Inisialisasi sensor suhu
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Blynk.run();
|
||||
sensors.requestTemperatures(); // Mengambil data suhu dari sensor
|
||||
|
||||
// Membaca suhu dalam derajat Celsius
|
||||
float temperatureC = sensors.getTempCByIndex(0);
|
||||
|
||||
// Kirim nilai suhu ke widget Value Display di Blynk
|
||||
Blynk.virtualWrite(V3, temperatureC); // V3 adalah pin virtual yang digunakan di aplikasi Blynk
|
||||
|
||||
delay(1000); // Delay 1 detik
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
#include "DHT.h"
|
||||
#include <SoftwareSerial.h>
|
||||
|
||||
#define DHTPIN 4 // Pin data DHT11 terhubung ke pin 4 Arduino
|
||||
#define DHTTYPE DHT11 // Tipe sensor DHT (DHT11 untuk sensor DHT11)
|
||||
#define SENSOR_PH A0 // Pin analog untuk sensor pH air
|
||||
|
||||
#define RX_PIN 2 // Pin TX untuk komunikasi serial dengan ESP8266
|
||||
#define TX_PIN 3 // Pin RX untuk komunikasi serial dengan ESP8266
|
||||
|
||||
//data sensor ph
|
||||
int nilai_analog_PH;
|
||||
double TeganganPh;
|
||||
float Po = 0;
|
||||
float PH_step;
|
||||
float PH4 = 3.9;
|
||||
float PH7 = 3.6;
|
||||
|
||||
DHT dht(DHTPIN, DHTTYPE);
|
||||
SoftwareSerial espSerial(RX_PIN, TX_PIN); // Mendefinisikan pin RX dan TX untuk komunikasi serial
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600); // Mulai komunikasi serial dengan kecepatan 9600 bps
|
||||
Serial.println("DHT11 & pH Sensor test!");
|
||||
dht.begin(); // Inisialisasi sensor DHT
|
||||
espSerial.begin(9600); // Serial untuk komunikasi dengan ESP8266
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Baca data suhu dan kelembaban
|
||||
float temperature = dht.readTemperature();
|
||||
float humidity = dht.readHumidity();
|
||||
|
||||
// Baca data pH air
|
||||
|
||||
float nilai_analog_PH = analogRead(SENSOR_PH);
|
||||
TeganganPh = (5.0 / 1024.0) * nilai_analog_PH; // Konversi nilai bacaan analog menjadi nilai pH
|
||||
PH_step = (PH4 - PH7) / 3;
|
||||
Po = 7.00 + ((PH7 - TeganganPh) / PH_step);
|
||||
|
||||
// Print data ke Serial Monitor
|
||||
Serial.print("Suhu (C): ");
|
||||
Serial.println(temperature);
|
||||
Serial.print("Kelembaban (%): ");
|
||||
Serial.println(humidity);
|
||||
Serial.print("pH Air: ");
|
||||
Serial.println(Po);
|
||||
|
||||
// Kirim data ke ESP8266
|
||||
espSerial.print(temperature);
|
||||
espSerial.print(",");
|
||||
espSerial.print(humidity);
|
||||
espSerial.print(",");
|
||||
espSerial.println(Po);
|
||||
|
||||
delay(2000); // Tunggu 2 detik sebelum membaca data lagi
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
#define BLYNK_TEMPLATE_ID "TMPL6jOeJtdWS" // Ganti dengan ID template Blynk Anda
|
||||
#define BLYNK_TEMPLATE_NAME "PALING AKHIR" // Ganti dengan nama template Blynk Anda
|
||||
|
||||
#define BLYNK_PRINT Serial
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <BlynkSimpleEsp8266.h>
|
||||
#include <OneWire.h>
|
||||
#include <DallasTemperature.h>
|
||||
|
||||
char auth[] = "f_-VsN8jII8HDoku_MxUJB-4zTC76FxE"; // Ganti dengan token otentikasi Blynk Anda
|
||||
|
||||
// Pin data sensor DS18B20 terhubung ke pin D4 (GPIO2) pada ESP8266
|
||||
const int oneWireBus = 2; // D4 pada NodeMCU
|
||||
|
||||
OneWire oneWire(oneWireBus);
|
||||
DallasTemperature sensors(&oneWire);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600); // Mulai komunikasi serial
|
||||
Blynk.begin(auth, "JTI12", "12345678"); // Ganti dengan SSID dan password WiFi Anda
|
||||
sensors.begin(); // Inisialisasi sensor suhu
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Blynk.run();
|
||||
|
||||
// Membaca data dari sensor DS18B20
|
||||
sensors.requestTemperatures();
|
||||
float temperatureC = sensors.getTempCByIndex(0);
|
||||
|
||||
// Tampilkan suhu DS18B20 ke Serial Monitor
|
||||
Serial.print("Suhu DS18B20 (C): ");
|
||||
Serial.println(temperatureC);
|
||||
|
||||
// Kirim nilai suhu DS18B20 ke widget Value Display di Blynk
|
||||
Blynk.virtualWrite(V3, temperatureC); // V3 adalah pin virtual yang digunakan di aplikasi Blynk
|
||||
|
||||
// Periksa apakah ada data dari Arduino Uno
|
||||
if (Serial.available() > 0) {
|
||||
String data = Serial.readStringUntil('\n');
|
||||
float temperature, humidity, pHValue;
|
||||
sscanf(data.c_str(), "%f,%f,%f", &temperature, &humidity, &pHValue);
|
||||
|
||||
// Tampilkan data yang diterima dari Arduino Uno ke Serial Monitor
|
||||
Serial.print("Suhu DHT11 (C): ");
|
||||
Serial.println(temperature);
|
||||
Serial.print("Kelembaban (%): ");
|
||||
Serial.println(humidity);
|
||||
Serial.print("pH Air: ");
|
||||
Serial.println(pHValue);
|
||||
|
||||
// Kirim nilai ke Blynk
|
||||
Blynk.virtualWrite(V0, temperature); // V0 untuk Suhu dari DHT11
|
||||
Blynk.virtualWrite(V1, humidity); // V1 untuk Kelembaban dari DHT11
|
||||
Blynk.virtualWrite(V2, pHValue); // V2 untuk pH
|
||||
}
|
||||
|
||||
// Menampilkan Notifikasi Pada Blynk
|
||||
// if(temperatureC > 30){
|
||||
// //Blynk.email("calvasskamollak@gmail.com", "notifikasi", "Temperature over 30C!");
|
||||
// Blynk.logEvent("notifikasi","Suhu Mencapai " + temperature + " Derajat");
|
||||
// }
|
||||
// else if (temperatureC <= 25){
|
||||
// Blynk.logEvent("info","Suhu Normal" + temperature);
|
||||
// }
|
||||
|
||||
delay(1000); // Delay 1 detik
|
||||
|
||||
}
|
|
@ -0,0 +1,188 @@
|
|||
#define BLYNK_TEMPLATE_ID "TMPL6jOeJtdWS"
|
||||
#define BLYNK_TEMPLATE_NAME "PALING AKHIR"
|
||||
|
||||
#define BLYNK_PRINT Serial
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <BlynkSimpleEsp8266.h>
|
||||
#include <OneWire.h>
|
||||
#include <DallasTemperature.h>
|
||||
#include "CTBot.h"
|
||||
#include <NTPClient.h>
|
||||
#include <WiFiUdp.h>
|
||||
#include <TimeLib.h>
|
||||
|
||||
char auth[] = "f_-VsN8jII8HDoku_MxUJB-4zTC76FxE"; // Ganti dengan token otentikasi Blynk Anda
|
||||
String ssid = "JTI12"; // Ganti dengan nama WiFi Anda
|
||||
String pass = "12345678"; // Ganti dengan password WiFi Anda
|
||||
|
||||
// Pin data sensor DS18B20 terhubung ke pin D4 (GPIO2) pada ESP8266
|
||||
const int oneWireBus = 2; // D4 pada NodeMCU
|
||||
|
||||
OneWire oneWire(oneWireBus);
|
||||
DallasTemperature sensors(&oneWire);
|
||||
|
||||
CTBot myBot;
|
||||
String token = "7246926173:AAFE3s8hO86IIgqN5zbrs_k3apSR9wzfBuk"; // Token bot telegram yang telah dibuat
|
||||
int64_t chat_id = 1333761230; // Ganti dengan chat ID Anda
|
||||
|
||||
// NTPClient setup
|
||||
WiFiUDP ntpUDP;
|
||||
NTPClient timeClient(ntpUDP, "id.pool.ntp.org", 25300, 60000); // GMT+7 offset (seconds), polling interval
|
||||
|
||||
// Last notification times
|
||||
int lastNotificationHour = -1;
|
||||
int lastNotificationMinute = -1;
|
||||
|
||||
// Sensor data variables
|
||||
float temperature = 0.0;
|
||||
float humidity = 0.0;
|
||||
float pHValue = 0.0;
|
||||
|
||||
// Notification tracking variables
|
||||
int highTempNotificationCount = 0;
|
||||
bool notificationSent = false;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
// Convert String to const char*
|
||||
const char* ssid_cstr = ssid.c_str();
|
||||
const char* pass_cstr = pass.c_str();
|
||||
|
||||
// Initialize Blynk
|
||||
Blynk.begin(auth, ssid_cstr, pass_cstr); // Use converted SSID and password
|
||||
sensors.begin(); // Inisialisasi sensor suhu
|
||||
|
||||
// Connect to WiFi
|
||||
WiFi.begin(ssid_cstr, pass_cstr);
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(1000);
|
||||
Serial.println("Connecting to WiFi...");
|
||||
}
|
||||
|
||||
Serial.println("Connected to WiFi.");
|
||||
|
||||
// Initialize NTPClient
|
||||
timeClient.begin();
|
||||
|
||||
// Initialize Telegram bot
|
||||
myBot.wifiConnect(ssid_cstr, pass_cstr);
|
||||
myBot.setTelegramToken(token);
|
||||
|
||||
// Check if all things are ok
|
||||
if (myBot.testConnection()) {
|
||||
Serial.println("\ntestConnection OK");
|
||||
myBot.sendMessage(chat_id, "Sistem Notifikasi Tambak Sudah Aktif!");
|
||||
} else {
|
||||
Serial.println("\ntestConnection NOK");
|
||||
myBot.sendMessage(chat_id, "Failed to connect to Telegram bot.");
|
||||
}
|
||||
// Handle incoming Telegram messages
|
||||
TBMessage msg;
|
||||
if (myBot.getNewMessage(msg)) {
|
||||
String reply = "Sistem Notifikasi Tambak Sudah Aktif!";
|
||||
myBot.sendMessage(msg.sender.id, reply);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
TBMessage msg;
|
||||
|
||||
if (myBot.getNewMessage(msg)) {
|
||||
String reply;
|
||||
reply = "Sistem Notifikasi Tambak Sudah Aktif!";
|
||||
myBot.sendMessage(msg.sender.id, reply);
|
||||
}
|
||||
|
||||
Blynk.run();
|
||||
timeClient.update();
|
||||
|
||||
// Get current time
|
||||
time_t rawTime = timeClient.getEpochTime();
|
||||
setTime(rawTime); // Set time based on NTP
|
||||
int currentHour = hour();
|
||||
int currentMinute = minute();
|
||||
|
||||
// Membaca data dari sensor DS18B20
|
||||
sensors.requestTemperatures();
|
||||
float temperatureC = sensors.getTempCByIndex(0);
|
||||
|
||||
// Tampilkan suhu DS18B20 ke Serial Monitor
|
||||
Serial.print("Suhu DS18B20 (C): ");
|
||||
Serial.println(temperatureC);
|
||||
|
||||
// Kirim nilai suhu DS18B20 ke widget Value Display di Blynk
|
||||
Blynk.virtualWrite(V3, temperatureC); // V3 adalah pin virtual yang digunakan di aplikasi Blynk
|
||||
|
||||
// Periksa apakah ada data dari Arduino Uno
|
||||
if (Serial.available() > 0) {
|
||||
String data = Serial.readStringUntil('\n');
|
||||
sscanf(data.c_str(), "%f,%f,%f", &temperature, &humidity, &pHValue);
|
||||
|
||||
// Tampilkan data yang diterima dari Arduino Uno ke Serial Monitor
|
||||
Serial.print("Suhu DHT11 (C): ");
|
||||
Serial.println(temperature);
|
||||
Serial.print("Kelembaban (%): ");
|
||||
Serial.println(humidity);
|
||||
Serial.print("pH Air: ");
|
||||
Serial.println(pHValue);
|
||||
|
||||
// Kirim nilai ke Blynk
|
||||
Blynk.virtualWrite(V0, temperature); // V0 untuk Suhu dari DHT11
|
||||
Blynk.virtualWrite(V1, humidity); // V1 untuk Kelembaban dari DHT11
|
||||
Blynk.virtualWrite(V2, pHValue); // V2 untuk pH
|
||||
}
|
||||
|
||||
// Format date and time
|
||||
String formattedDate = String(day()) + "/" + String(month()) + "/" + String(year());
|
||||
String formattedTime = String(hour()) + ":" + String(minute()) + ":" + String(second());
|
||||
|
||||
// Display date and time to Serial Monitor
|
||||
Serial.print("Tanggal: ");
|
||||
Serial.println(formattedDate);
|
||||
Serial.print("Waktu: ");
|
||||
Serial.println(formattedTime);
|
||||
|
||||
// Check if it's time to send notification
|
||||
if ((currentMinute == 0 || currentMinute == 20 || currentMinute == 40) &&
|
||||
(currentHour == 7 || currentHour == 12 || currentHour == 18) &&
|
||||
(currentHour != lastNotificationHour || currentMinute != lastNotificationMinute)) {
|
||||
|
||||
// Format and send notification via Telegram
|
||||
String notificationMessage = "Data Sensor:\n";
|
||||
notificationMessage += "Suhu Air: " + String(temperatureC, 2) + " C\n";
|
||||
notificationMessage += "Suhu Sekitar: " + String(temperature, 2) + " C\n";
|
||||
notificationMessage += "Kelembaban Sekitar: " + String(humidity, 2) + " %\n";
|
||||
notificationMessage += "pH Air: " + String(pHValue, 2) + "\n" + "\n";
|
||||
notificationMessage += "Tanggal: " + formattedDate + "\n";
|
||||
notificationMessage += "Waktu: " + formattedTime + "\n";
|
||||
|
||||
myBot.sendMessage(chat_id, notificationMessage);
|
||||
|
||||
// Update last notification time
|
||||
lastNotificationHour = currentHour;
|
||||
lastNotificationMinute = currentMinute;
|
||||
}
|
||||
|
||||
// Check if the temperature exceeds 30 degrees
|
||||
if (temperatureC > 30.0 && highTempNotificationCount < 3 && !notificationSent) {
|
||||
String alertMessage = "Perhatian! Suhu air melebihi 30 derajat Celcius.\n";
|
||||
alertMessage += "Suhu saat ini: " + String(temperatureC, 2) + " C\n";
|
||||
alertMessage += "Tanggal: " + formattedDate + "\n";
|
||||
alertMessage += "Waktu: " + formattedTime + "\n";
|
||||
|
||||
myBot.sendMessage(chat_id, alertMessage);
|
||||
highTempNotificationCount++; // Tingkatkan jumlah notifikasi yang telah dikirim
|
||||
notificationSent = true; // Setel flag notifikasi sudah dikirim
|
||||
}
|
||||
|
||||
// Reset flag if the temperature goes back below 30 degrees
|
||||
if (temperatureC <= 30.0) {
|
||||
notificationSent = false; // Reset flag notifikasi
|
||||
highTempNotificationCount = 0; // Reset counter notifikasi
|
||||
}
|
||||
|
||||
delay(1000); // Delay 1 detik
|
||||
}
|
Loading…
Reference in New Issue