ในวันนี้จะมาแนะนำในการเรียนโปรแกรมแสดงอุณภูมิแจ้งเตือนผ่าน Line Appliacation โดยใช้ NODE MCU และ DHT22
1. วิธีรับ token GET TOKEN LINE
2. โหลด Libraries >> TridentTD_LineNotify ที่นี่ Libraries TridentTD_LineNotify
3. ทำการติดตั้ง Libraries กดที่ sketch >> include Libraries >> Add.zip ตามรูป แล้วกด OK 4 . แล้วเช็ค Libraries ว่าเข้ามาหรือยัง วิธีเช็ค กด Sketch >> include libraries แล้ว เลื่อนดูว่า TridentTD_Linenotify เข้ามาหรือยัง 5. ลง Libraries ของ DHT22 เป็น Libraries ของ Sensord กด Sketch >> Include Libraries >> Manage Libraries แล้วพิม dht ตามภาพ หรือ โหลดได้ที่Libraries DHT22แล้วก็ทำการ Add.zip เหมือนติดตั้ง Libraries line 6. โค๊ดในการแสดงอุณภูมิแจ้งเตือนผ่านไลน์
โค้ด: เลือกทั้งหมด
#include <TridentTD_LineNotify.h>
#define SSID "Wifi" // บรรทัดที่ 11 ให้ใส่ ชื่อ Wifi ที่จะเชื่อมต่อ
#define PASSWORD "0000000000" // บรรทัดที่ 12 ใส่ รหัส Wifi
#define LINE_TOKEN "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" // ใส่ รหัส TOKEN ที่ได้มาจากไลน์
#include "DHT.h"
#define DHTPIN D1
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
dht.begin();
Serial.begin(115200); Serial.println();
Serial.println(LINE.getVersion());
WiFi.begin(SSID, PASSWORD);
Serial.printf("WiFi connecting to %s\n", SSID);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(400);
}
Serial.printf("\nWiFi connected\nIP : ");
Serial.println(WiFi.localIP());
// กำหนด Line Token
LINE.setToken(LINE_TOKEN);
LINE.notify("myarduino.net");
}
void loop() {
delay(2000);
float h = dht.readHumidity();
float t = dht.readTemperature();
float f = dht.readTemperature(true);
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
float hif = dht.computeHeatIndex(f, h);
float hic = dht.computeHeatIndex(t, h, false);
Serial.print(F("Humidity: "));
Serial.print(h);
Serial.print(F("% Temperature: "));
Serial.print(t);
Serial.print(F("°C "));
Serial.print(f);
Serial.print(F("°F Heat index: "));
Serial.print(hic);
Serial.print(F("°C "));
Serial.print(hif);
Serial.println(F("°F"));
if (t > 40) { // กำหนดว่า อุณภูมิเกิน 40 เมื่อไหร่ ให้แจ้งเตือนเข้าไลน์
String LineText;
String string1 = "อุณหภูมิ เกินกำหนด ";
String string2 = " °C";
LineText = string1 + t + string2;
Serial.print("Line ");
Serial.println(LineText);
LINE.notify(LineText);
}
}
7.การต่อวงจร
[list]V in ต่อกับ ขา +
GND ต่อกับ ขา -
ขา D1 ต่อกับ ขา Out[/list]
อ้างอิง : https://www.myarduino.net/article/126/%E0%B8%AA%E0%B8%AD%E0%B8%99%E0%B9%83%E0%B8%8A%E0%B9%89%E0%B8%87%E0%B8%B2%E0%B8%99-nodemcu-esp8266-%E0%B8%AA%E0%B9%88%E0%B8%87%E0%B8%84%E0%B9%88%E0%B8%B2%E0%B8%84%E0%B8%A7%E0%B8%B2%E0%B8%A1%E0%B8%8A%E0%B8%B7%E0%B9%89%E0%B8%99%E0%B9%81%E0%B8%A5%E0%B8%B0%E0%B8%AD%E0%B8%B8%E0%B8%93%E0%B8%AB%E0%B8%A0%E0%B8%B9%E0%B8%A1%E0%B8%B4-dht11-%E0%B9%81%E0%B8%88%E0%B9%89%E0%B8%87%E0%B9%80%E0%B8%95%E0%B8%B7%E0%B8%AD%E0%B8%99%E0%B8%9C%E0%B9%88%E0%B8%B2%E0%B8%99-line
http://arduinoprojects.in.th/%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%83%E0%B8%8A%E0%B9%89%E0%B8%87%E0%B8%B2%E0%B8%99-water-flow-sensor-%E0%B8%81%E0%B8%B1%E0%B8%9A-arduino/
https://www.9arduino.com/article/60/%E0%B8%95%E0%B8%B1%E0%B8%A7%E0%B8%AD%E0%B8%A2%E0%B9%88%E0%B8%B2%E0%B8%87-nodemcu-%E0%B8%94%E0%B8%B6%E0%B8%87%E0%B8%84%E0%B9%88%E0%B8%B2%E0%B8%95%E0%B8%B1%E0%B8%A7%E0%B9%81%E0%B8%9B%E0%B8%A3-json-%E0%B8%A1%E0%B8%B2%E0%B9%83%E0%B8%8A%E0%B9%89%E0%B8%87%E0%B8%B2%E0%B8%99
https://www.ab.in.th/article/6/nodemcu-esp8266-%E0%B8%81%E0%B8%B1%E0%B8%9A%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B8%AA%E0%B9%88%E0%B8%87%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%81%E0%B8%88%E0%B9%89%E0%B8%87%E0%B9%80%E0%B8%95%E0%B8%B7%E0%B8%AD%E0%B8%99%E0%B9%80%E0%B8%82%E0%B9%89%E0%B8%B2-line-%E0%B8%AA%E0%B9%88%E0%B8%87%E0%B8%82%E0%B9%89%E0%B8%AD%E0%B8%84%E0%B8%A7%E0%B8%B2%E0%B8%A1-%E0%B8%A0%E0%B8%B2%E0%B8%9E-%E0%B9%81%E0%B8%A5%E0%B8%B0%E0%B8%AA%E0%B8%95%E0%B8%B4%E0%B8%81%E0%B9%80%E0%B8%81%E0%B8%AD%E0%B8%A3%E0%B9%8C