arduino_kamon

ซื้อ board http://www.makearduino.com/product/52/esp8266-smartrealy-shield-4ch-relay-4-input-ds3231-rtc-eeprom-256kb

https://github.com/iamdev/ESP8266_SmartRelayShield

http://www.archiduino.com/liquidcrystal_i2c-h-library-arduino-ide-1-6-x/

Example code for MakeArduino-ESP8266 Smart-Relay Shield

Edit all user config in "config.h"

Serial Command:

    • D yyyy-mm-dd hh:mm:ss -> Set Clock to RTC

    • T HH:mm:ss -> Set Time to RTC

    • A S ss -> Set Alarm to Toggle Relay 1 (alarm when Second matched)

    • A M mm:ss -> Set Alarm to Toggle Relay 1 (alarm when Minute and Second matched)

    • A H hh:mm:ss -> Set Alarm to Toggle Relay 1 (alarm when match all Hour,Minute and Second)

Blynk Example

บอร์ดขนาด 11x8cm

code ตัวอย่าง แยกเป็น library .h ไว้ให้เรียกใช้งานใน main ได้เลยจะมี function ดังนี้ครับ

- Serial Command ส่งคำสังผ่าน Serial เช่น ตั้งนาฬิกา ตั้งเวลา alarm

- ตั้งเวลาตามสั่งงานตามปฏิทิน

- เชื่อมต่อ Blynk Server

- กดปุ่ม Config บน Shield ตอนเปิด power หรือกด reset จะเข้า mode SmartConfig wifi ผ่าน app SmartConfig บน android ได้เลย

- สั่งงาน Relay ผ่าน Blynk Virtual PIN (V1-V4)

- แสดงนาฬิกาบน และสถานะ Relay บน LCD 1602

- รับเช็ค Input สั่งปิดเปิด relay แยก Channel (Toggle Button กดเปิด กดอีกครั้งปิด)

- กดสั่งงานผ่าน input switch แสดงสถานะบน Virtual Pin ของ Blynk ตามสถานะของ Relay

- เก็บสถานะล่าสุดของ Relay บน EEPROM และเมื่อ reset หรือปิด/เปิดไหม่ relay จะยังคงสถานะเดิม

- มีตัวอย่าง MQTT sub/pub ไว้ให้ด้วย แต่ไม่ได้เรียกใช้

** Code ทั้งหมดเป็นแค่ตัวอย่างการใช้งานบอร์ดให้ครบทุก function ที่ใส่เข้าไปในบอร์ดนะครับ ถ้าจะใช้งานจริงจะเพิ่มหรือจะแก้ไขตามสะดวกครับ

Source Code --> https://github.com/iamdev/ESP8266_SmartRelayShield

แจกไปศึกษาฟรีครับ library ที่ต้องลงเพิ่มจะมี Blynk กับ LiquidCrystal_I2C นอกนั้นเขียนเองบ้างดึงมาบางส่วนบ้างเฉพาะที่ใช้และปรับให้ใช้งานได้กับบอร์ด

void sendUptime()

{

Blynk.virtualWrite(V5, millis() / 500);

sensors_event_t event;

dht.temperature().getEvent(&event);

if (!isnan(event.temperature)) {

Blynk.virtualWrite(V1, event.temperature);

}

dht.humidity().getEvent(&event);

if (!isnan(event.relative_humidity)) {

Blynk.virtualWrite(V2, event.relative_humidity);

}

}

void loop()

{

Blynk.run();

timer.run();

BLYNK_CONNECTED();

Blynk.syncAll();

}