มินิโปรเจค
เปิด-ปิด ไฟ 220V AC ด้วย แอพ Blynk
Blynk Application เป็นโปรแกรมบนมือถือที่ทำให้เราสร้างหน้าต่างควบคุมหรือแสดงผลเชื่อมต่อกับพวกไมโครคอนโทรเลอร์
รูป Blynk Application
อุปกรณ์ที่ใช้
1. Arduino UNO R3
2. Relay Module
3. หลอดไฟ 220V AC
4. โทรโทรศัพท์มือ
5. Notbook
การต่อวงจร ระหว่าง UNO + Relay + หลอดไฟ 200V AC
การต่อวงจร ระหว่าง Relay กับ Arduino UNO
ไปที่ Play Store ค้นหา Blynk
ติดตั้ง เหมือน App ทั่วๆไป
เปิด Blynk Application ขึ้นมา
-> Create New Account
เลือก connection type เป็น USB

ตั้งชื่อ Project ในตัวอย่างชื่อ led-v1 -> Create

โปรกรม จะส่ง Auth Toke ไปที่ อีเมล ที่เรากรอกไว้ -> OK
โดยทุกๆครั้งที่เริ่มสร้างโปรเจคใหม่ AUTH TOKEN จะถูกเปลี่ยนใหม่เสมอ ซึ่ง KEY นี้เองที่เป็นเสมือนกุญแจสำหรับเชื่อมต่อ
คลิก เครื่องหมาย +

คลิก เพิ่ม Button

จะมี ปุ่ม BUTTON เพิ่มเข้ามาที่หน้าจอ แล้วจึง คลิกที่ BUTTON เพื่อตั้งค่า
เลือก เป็นแบบ SWITCH แล้ว คลิก ที่ PIN
BUTTON จะอยู่ริมซ้ายมือบน
เพื่อความสวยงาม ให้ ลาก BUTTON ไว้กลางหน้าจอ
ไปที่
http://www.blynk.cc/getting-started/
ดาวน์โหลด ไลบรารี่ Blynk
http://www.blynk.cc/getting-started/
ดาวน์โหลด ไลบรารี่ Blynk
เปิด โปรแกรม Arduino IDE จากนั้นให้ทำการเพิ่ม ไลบรารี่ Blynk ให้กับ Arduino (IDE) ของเรา
การเพิ่ม ไลบรารี่ Blynk ให้กับ Arduino (IDE) ของเรา ตามรูป
แก้ไข YourAuthToken ที่เราได้รับจาก อีเมล
ที่เราได้รับจาก อีเมล
เมื่อแก้ไขแล้ว อัพโหลดโค้ด ไปยัง Arduino UNO
/*************************************************************
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
Social networks: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
=>
=> USB HOWTO: http://tiny.cc/BlynkUSB
=>
Feel free to apply it to any other example. It's simple!
*************************************************************/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT DebugSerial
// You could use a spare Hardware Serial on boards that have it (like Mega)
#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(2, 3); // RX, TX
#include <BlynkSimpleStream.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "bd1043f4d0084767b4a7f5650ce12c26"; // ต้องแก้ไข
void setup()
{
// Debug console
DebugSerial.begin(9600);
// Blynk will work through Serial
// Do not read or write this serial manually in your sketch
Serial.begin(9600);
Blynk.begin(Serial, auth);
}
void loop()
{
Blynk.run();
}
/*************************************************************
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
Social networks: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
=>
=> USB HOWTO: http://tiny.cc/BlynkUSB
=>
Feel free to apply it to any other example. It's simple!
*************************************************************/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT DebugSerial
// You could use a spare Hardware Serial on boards that have it (like Mega)
#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(2, 3); // RX, TX
#include <BlynkSimpleStream.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "bd1043f4d0084767b4a7f5650ce12c26"; // ต้องแก้ไข
void setup()
{
// Debug console
DebugSerial.begin(9600);
// Blynk will work through Serial
// Do not read or write this serial manually in your sketch
Serial.begin(9600);
Blynk.begin(Serial, auth);
}
void loop()
{
Blynk.run();
}
**** ต้องแก้ไข USB Port ของ Arduino UNO ให้ตรงกัน ****
ในตัวอย่าง จะเป็น COM3
ในตัวอย่าง จะเป็น COM3
ไปที่ Arduino ไลบรารี่ blynk-library-0.x.x คลิกขวาเปิดไฟล์ blynk-ser เพื่อทำการแก้ไข
ตรง COMM_PORT แก้ไขให้ตรงกับ Port Arduino ของเรา ในตัวอย่างคือ COM3 แล้วจึง Save

จากนั้น คลิกซ้าย เปิดไฟล์ให้ทำงาน (ต้องเปิดไฟล์นี้ไว้ตลอดในขณะทดสอบ)

กลับไปที่ Blynk Application คลิกที่ เครื่องหมาย สามเหลี่ยม

เพื่อทดสอบการทำงานของโปรแกรม led-v1

#define BLYNK_PRINT DebugSerial //ใช้เพื่อตั้งชื่อค่าคงที่ #include <SoftwareSerial.h> // การอ่านไฟล์จากไดเร็กทอรี หรือโฟลเดอร์ที่กำหนดไว้ SoftwareSerial DebugSerial(2, 3); //ฟังก์ชั่นของ SoftwareSerial กำหนด ให้ขา2 เป็น tx ขา3เป็นrx #include <BlynkSimpleStream.h> // การอ่านไฟล์จากไดเร็กทอรี หรือโฟลเดอร์ที่กำหนดไว้ char auth[] = "bd1043f4d0084767b4a7f5650ce12c26"; // เก็บข้อมูลอักขระ void setup() // ฟังก์ชั่นใช้ในการประกาศค่าเริ่มต้น { DebugSerial.begin(9600); Serial.begin(9600); //ประกาศการใช้งานการสื่อสารรับส่งข้อมูลผ่าน พอร์ตRS232 Blynk.begin(Serial, auth); //เริ่มการทำงานเริ่มต้นของ Blynk } void loop() // ฟังก์ชั่นใช้ในการเขียนโค้ดโปรแกรมการทำงานของArduinoเป็นฟังก์ชั่นการวนลูปไปเรื่อยๆ { Blynk.run(); //ฟังก์ชั่นของ BlynkSimpleStream}}
https://www.youtube.com/watch?v=w0HRl_xchP8



























อยากทราบว่า โค๊ด SoftwareSerial DebugSerial (2,3):
ตอบลบคืออะไรหรอครับ