0% found this document useful (0 votes)
98 views5 pages

TUGAS Sensor DHT INFLUXDB - GRAFANA

This document describes a project to monitor temperature and humidity using an ESP8266 microcontroller with a DHT22 sensor. The sensor readings are sent to an InfluxDB database hosted on the cloud. A Grafana dashboard is then used to visualize the sensor data over time for monitoring purposes. The system works by reading sensor values, writing them to the InfluxDB database, and displaying them on a Grafana dashboard for easy monitoring of temperature and humidity.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
98 views5 pages

TUGAS Sensor DHT INFLUXDB - GRAFANA

This document describes a project to monitor temperature and humidity using an ESP8266 microcontroller with a DHT22 sensor. The sensor readings are sent to an InfluxDB database hosted on the cloud. A Grafana dashboard is then used to visualize the sensor data over time for monitoring purposes. The system works by reading sensor values, writing them to the InfluxDB database, and displaying them on a Grafana dashboard for easy monitoring of temperature and humidity.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

TUGAS

Weather Monitoring dengan ESP8266, InfluxDB, dan DHT22

POLITEKNIK NEGERI BALI

PRAMUDYA WARDHANA
NIM : 2315374032

PROGRAM STUDI D4 TEKNIK OTOMASI


JURUSAN TEKNIK ELEKTRO
POLITEKNIK NEGERI BALI
2023
1. Deskripsi Project
Dalam tugas ini, percobaan yang dilakukan adalah melakukan monitoring suhu dan
kelembapan ruang dengan memanfaatkan ESP8266 yang disertai sensor DHT22, InfluxDB
sebagai Database dan Grafana sebagai media visualisasi dalam bentuk dashboard.

2. Wiring Diagram

DHT22 ESP8266
Out D5
+ 3V3
- GND

3. Kode Program Arduino IDE


4. #if defined(ESP32)
5. #include <WiFiMulti.h>
6. WiFiMulti wifiMulti;
7. #define DEVICE "ESP32"
8. #elif defined(ESP8266)
9. #include <ESP8266WiFiMulti.h>
10. ESP8266WiFiMulti wifiMulti;
11. #define DEVICE "ESP8266"
12. #endif
13.
14. #include <InfluxDbClient.h>
15. #include <InfluxDbCloud.h>
16. #include "DHT.h"
17. #define DHTTYPE DHT22
18. #define dht_dpin D5
19. DHT dht(dht_dpin, DHTTYPE);
20.
21. // WiFi AP SSID
22. #define WIFI_SSID "Indihome"
23. // WiFi password
24. #define WIFI_PASSWORD "plnbali123"
25.
26. #define INFLUXDB_URL "https://us-east-1-1.aws.cloud2.influxdata.com"
27. #define INFLUXDB_TOKEN "cF685x7RVuM81kDXp3qRRS5ki6iVNOpK7-
ZtxIYa5iSBqOWpF9KxtxpOTEXuxBc4qtSk6u6U1BTBf-2Rva4rng=="
28. #define INFLUXDB_ORG "5df04e67d1f834c8"
29. #define INFLUXDB_BUCKET "DHTsensor"
30.
31. // Time zone info
32. #define TZ_INFO "WITA-8"
33.
34. // Declare InfluxDB client instance with preconfigured InfluxCloud certificate
35. InfluxDBClient client(INFLUXDB_URL, INFLUXDB_ORG, INFLUXDB_BUCKET,
INFLUXDB_TOKEN,
36. InfluxDbCloud2CACert);
37.
38. // Declare Data point
39. Point sensor("DHT_Sensor");
40. void setup() {
41. Serial.begin(9600);
42. dht.begin();
43. // Setup wifi
44. WiFi.mode(WIFI_STA);
45. wifiMulti.addAP(WIFI_SSID, WIFI_PASSWORD);
46.
47. Serial.print("Connecting to wifi");
48. while (wifiMulti.run() != WL_CONNECTED) {
49. Serial.print(".");
50. delay(100);
51. }
52. Serial.println();
53.
54. // Add tags
55. sensor.addTag("device", DEVICE);
56. sensor.addTag("SSID", WiFi.SSID());
57. timeSync(TZ_INFO, "pool.ntp.org", "time.nis.gov");
58. // Check server connection
59. if (client.validateConnection()) {
60. Serial.print("Connected to InfluxDB: ");
61. Serial.println(client.getServerUrl());
62. } else {
63. Serial.print("InfluxDB connection failed: ");
64. Serial.println(client.getLastErrorMessage());
65. }
66. }
67.
68. void loop() {
69. sensor.clearFields();
70.
71. float h = dht.readHumidity();
72. float t = dht.readTemperature();
73.
74. sensor.addField("Temperature", t);
75. sensor.addField("Humidity", h);
76.
77. Serial.print("Current humidity = ");
78. Serial.print(h);
79. Serial.print("% ");
80. Serial.print("temperature = ");
81. Serial.print(t);
82. Serial.println("C ");
83. Serial.print("Writing: ");
84. Serial.println(client.pointToLineProtocol(sensor));
85. // If no Wifi signal, try to reconnect it
86. if (wifiMulti.run() != WL_CONNECTED) {
87. Serial.println("Wifi connection lost");
88. }
89. // Write point
90. if (!client.writePoint(sensor)) {
91. Serial.print("InfluxDB write failed: ");
92. Serial.println(client.getLastErrorMessage());
93. }
94. delay(500);
95. }

4. Hasil Percobaan
Tampilan di Serial Monitor
Tampilan Data Expoler di InfluxDB Cloud

Tampilan Dashboard di Grafana

5. Cara Kerja Sistem


Dari data yang dibaca oleh sensor DHT22 menggunakan coding yang sudah dilampirkan akan
dilakukan penyimpanan ke database InfluxDB Cloud. Dikarenakan InfluxDB versi free tidak bisa
membuat Dashboard untuk monitoring, maka akan ditampilkan datanya dalam bentuk
dashboard menggunakan Grafana. Untuk membaca data dari InfluxDB, Grafana
memanfaatkan fitur FlightSQL untuk membaca database dari InfluxDB dengan menggunakan
URL dan Token sebagai autentikasi koneksinya. Berikut adalah tampilannya.

You might also like