วันอังคารที่ 25 กันยายน พ.ศ. 2561

การใช้งาน Arduino กับ Module 433Mhz Wireless RF Transmitter and Receiver Module

การใช้งาน Arduino กับ Module 433Mhz Wireless RF Transmitter and Receiver Module


Arduino 433
Module 433Mhz Wireless RF Transmitter and Receiver Module ในหนึ่งชุดประกอบด้วย ภาครับและภาคส่ง ใช้สำหรับส่งข้อมูลไร้สาย โดยผ่านความถี่วิทยุ 433 MHz หรือ ความถี่วิทยุ 315 Mhz 
Module 433Mhz Wireless RF Transmitter and Receiver Module เป็นที่นิยม มากเนื่องจากราคาถูก ราคาหลักสิบบาท ใช้งานได้ง่าย มี Libraries พร้อมใช้งาน ทำให้ง่ายต่อการใช้งานกับเจ้า Arduino สำหรับ Module 433Mhz Wireless RF Transmitter and Receiver Module มีข้อเสียคือเรืองสัญญาณเคลื่อนวิทยุอาจจะถูกรบกวนได้ง่าย ความเร็วในการส่งช้า จึงเหมาะกับการงานที่ไม่ต้องการความเร็วในการรับส่ง และความถูกต้องมากมาย เช่น การควบคุมรถบังคับ การควบคุมเปิดปิดเครื่องใช้ไฟฟ้า การส่งข้อมูลระยะไกลเช่นค่าอุหภูมิ และงานทั่วไปที่ต้องการส่งข้อมูลไร้สายหรือไม่สามารถเดินสายไฟได้ เป็นต้น
สามารถสั่งซื้อสินค้าได้ที่ : https://www.9arduino.com/product/205/433mhz-wireless-rf-transmitter-and-receiver-module
Download Library : http://www.airspayce.com/mikem/arduino/RadioHead/RadioHead-1.41.zip
โปรแกรมทดสอบด้วย Arduino IDE 1.6.11
ส่วนของภาครับสัญญาณ การต่อ Module 433Mhz Wireless RF Transmitter and Receiver Module
 
ตัวอย่าง Code ภาครับสัญญาณ ของ Module 433Mhz Wireless RF Transmitter and Receiver Module
#include <RH_ASK.h>
#include <SPI.h
RH_ASK driver;
void setup()
{
    Serial.begin(9600);
    if (!driver.init())
         Serial.println("init failed");
}
void loop()
{
    uint8_t buf[12];
    uint8_t buflen = sizeof(buf);
    if (driver.recv(buf, &buflen)) 
    {
      int i;
      // รับข้อความแล้วนำมาแสดง 
      Serial.print("Message: ");
      Serial.println((char*)buf);         //ตัวแปรที่นำข้อความมาแสดง
    }
}

ส่วนของภาคส่งสัญญาณ การต่อ Module 433Mhz Wireless RF Transmitter and Receiver Module
 
ตัวอย่าง Code ภาคส่งสัญญาณ ของ Module 433Mhz Wireless RF Transmitter and Receiver Module
#include <RH_ASK.h>
#include <SPI.h
RH_ASK driver;
void setup()
{
    Serial.begin(9600);   // Debugging only
    if (!driver.init())
         Serial.println("init failed");
}
void loop()
{
    const char *msg = "Hello World! My name is 9Arduino.com";   //ข้อความที่ต้องการส่งไปยังภาครับ อาจจะดัดแปลงส่งตัวค่าต่างๆ เช่นอุณหภูมิ ตัวอักษรสำหรับคุมรถบังคับ เป็นต้น
    driver.send((uint8_t *)msg, strlen(msg));
    driver.waitPacketSent();
    delay(1000);
}
//ที่มา www.9arduino.com 

ไม่มีความคิดเห็น:

แสดงความคิดเห็น