Arduino 433 + 串口

Posted kekeoutlook

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Arduino 433 + 串口相关的知识,希望对你有一定的参考价值。

http://www.freebuf.com/articles/wireless/105398.html

技术分享图片

 

/*本作品使用的例程中包含RCSwitch库文件用于信号的解码和编码发送*/
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
void setup() {
  Serial.begin(9600);
//串口打印命令帮助信息
 Serial.print("HELP:A-flash the lamp A\\n     B-flash the lamp B\\n     C-flash the lamp C\\n     D-flash the lamp D\\n");
  Serial.print("     a-open the lamp A\\n     b-open  the lamp B\\n     c-open the lamp C\\n     d-open  the lamp D\\n\\n");
    mySwitch.enableReceive(1);
  mySwitch.enableTransmit(10);}2
void loop()
{
    if(mySwitch.available())
    {
    output(mySwitch.getReceivedValue(),mySwitch.getReceivedBitlength(), mySwitch.getReceivedDelay(),mySwitch.getReceivedRawdata(),mySwitch.getReceivedProtocol());
   mySwitch.resetAvailable();
    }
  /* Same switch as above,but using binary code */
  if(Serial.available()>0)//如果串口有数据进入的话
  { delay(10);           //延时50 可以一次性发送多个命令
   char M=Serial.read();//每次读一个字符,是ASCII码的
   if(M==‘A‘)
    {
  Serial.print("Thecommand is A\\n");
 mySwitch.send("010101010101010100001100");//遥控器-A
  Serial.print("      OK!!! The LED A has been DONE\\n");
    }
       if(M==‘a‘)
    {
     Serial.print("The command is a\\n");
     Serial.print("      OK!!! TheLED A has hlod ON\\n");
     while(Serial.available()<=0)
      {
      mySwitch.send("010101010101010100001100");//遥控器-A 按下不放
      }
    }
  if(M==‘B‘)
    {
  Serial.print("Thecommand is B\\n");
 mySwitch.send("010101010101010111000000");//遥控器-B
  Serial.print("      OK!!! The LED B has been DONE\\n");
    }
     if(M==‘b‘)
    {
     Serial.print("The command is b\\n");
      Serial.print("      OK!!! The LED B has hlod ON\\n");
     while(Serial.available()<=0)
      {
      mySwitch.send("010101010101010111000000");//遥控器-B 按下不放
      }
    }
  if(M==‘C‘)
    {
  Serial.print("Thecommand is C\\n");
 mySwitch.send("010101010101010100000011");//遥控器-C
  Serial.print("      OK!!! The LED C has been DONE\\n");
    }
         if(M==‘c‘)
    {
     Serial.print("The command is c\\n");
     Serial.print("      OK!!! TheLED C has hlod ON\\n");
     while(Serial.available()<=0)
      {
      mySwitch.send("010101010101010100000011");//遥控器-C按下不放
      }
    }
  if(M==‘D‘)
    {
  Serial.print("Thecommand is D\\n");
 mySwitch.send("010101010101010100110000");//遥控器-D
  Serial.print("      OK!!! The LED D has been DONE\\n");
    }
         if(M==‘d‘)
    {
     Serial.print("The command is d\\n");
     Serial.print("      OK!!! TheLED D has hlod ON\\n");
     while(Serial.available()<=0)
      {
      mySwitch.send("010101010101010100110000");//遥控器-D按下不放
      }
    }
  }
}

  

以上是关于Arduino 433 + 串口的主要内容,如果未能解决你的问题,请参考以下文章

Arduino nano 通过RF433将DHT11数据传输实验

Arduino ESP8266 RF433数据传输实验二(传输ADC模拟量信号)

Arduino UNO + 433无线模块实例

Arduino nano RF433数据收发实验(只能实现单板数据收发)

Arduino RF 接收器接收一些 433MHz 信号,但不接收其他信号

433 模块 ARDUINO测试