Lab 11 Blynk IoT

จุดประสงค์การเรียนรู้

- สามารถรับส่งข้อมูลESP32โดยใช้เทคโนโลยีInternet of things


อุปกรณ์

1. หลอด LED 3 จำนวน 3 หลอด

2. ตัวต้านทาน 220 โอห์ม จำนวน 3 ตัว

3. บอร์ด ESP32 Devkit V.1


วิธีทำการทดลอง

1. ต่อวงจรดังนี้

LED หลอดที่ 1 ต่อกับพอร์ต D5 (GPIO5)

LED หลอดที่ 2 ต่อกับพอร์ต D19 (GPIO19)

LED หลอดที่ 3 ต่อกับพอร์ต D23 (GPIO23)

2. ทำการติดตั้งApplication Blynk ในSmartphone ให้เรียบร้อย แล้วทำการตั้งค่าดังภาพข้างล่าง

3. ทำการ Copy code Arduino IDE ในช่องข้างล่างแล้วทำการแก้ไขค่าconfig 3 ที่ให้เข้ากับเครือข่ายที่ใช้งานดังรูปข้างล่าง ดังนี้

char auth[] = "กรอก Auth token จากApplication blynk"

char ssid[] = "กรอก ssid ของ wifi ที่ใช้เชื่อมต่อชนิด 2.4 GHz"

char pass[] = "กรอกPassword ของwifi ที่ใช้เชื่อมต่อ"

Blynk v.1

/*************************************************************

Download latest Blynk library here:

https://github.com/blynkkk/blynk-library/releases/latest


Blynk is a platform with iOS and Android apps to control

Arduino, Raspberry Pi and the likes over the Internet.

You can easily build graphic interfaces for all your

projects by simply dragging and dropping widgets.


Downloads, docs, tutorials: http://www.blynk.cc

Sketch generator: http://examples.blynk.cc

Blynk community: http://community.blynk.cc

Follow us: http://www.fb.com/blynkapp

http://twitter.com/blynk_app


Blynk library is licensed under MIT license

This example code is in public domain.


*************************************************************

This example runs directly on ESP32 chip.


Note: This requires ESP32 support package:

https://github.com/espressif/arduino-esp32


Please be sure to select the right ESP32 module

in the Tools -> Board menu!


Change WiFi ssid, pass, and Blynk auth token to run :)

Feel free to apply it to any other example. It's simple!

*************************************************************/


/* Comment this out to disable prints and save space */

#define BLYNK_PRINT Serial



#include <WiFi.h>

#include <WiFiClient.h>

#include <BlynkSimpleEsp32.h>


// You should get Auth Token in the Blynk App.

// Go to the Project Settings (nut icon).

char auth[] = "-AQlaqcVkI2kzNCTFkDge0qRAuXIrB4dU*";


// Your WiFi credentials.

// Set password to "" for open networks.

char ssid[] = "BJHome2G";

char pass[] = "123456789";


void setup()

{

// Debug console

Serial.begin(9600);


Blynk.begin(auth, ssid, pass);

}


void loop()

{

Blynk.run();

}

และทำการUpload code ลงในบอร์ด ESP32 Devkit v.1 โดยเลือกบอร์ดเป็นESP32DevModule

** กรณีใช้งานใน Ubuntu ก่อนกดUpload ให้ทำการเปิดTerminal โดยเข้าไปที่desktop คลิกขวาตรงพื้นที่ว่าง แล้วเลือก Open Terminal หลังจากนั้นให้พิมพ์ข้อความในTerminalดังนี้เพื่อทำการเปิดพอร์ตUSB : sudo chmod 666 /dev/ttyUSB0 หลังจากนั้นให้กดEnter และทำการกรอกรหัสผ่านของเครื่องพร้อมกับกดEnerอีกครั้ง หลังจากนั้นก็Upload codeในArduino IDE

4.ทำการเปิดSerial monitor เพื่อดูสถานะการเชื่อมต่อwifiของบอร์ดESP32 หากขึ้นคำว่าReady ดังภาพข้างล่างแสดงว่าพร้อมสำหรับการใช้งาน

5. ทำการทดสอบกดปุ่ม GP5 ,GP9และGP23 ใน smartphone แล้วสังเกตการทำงานของหลอดLEDที่บอร์ดESP32ว่ามีการเปลี่ยนแปลงการติดดับหรือไม่