Arduino驱动315MHZ无线模块

在这里插入图片描述

Sapere Aude, quia Veritas Vos Liberabit.
敢于知道,因为真理使我们自由。

准备工具

1、两个Adruino开发板
2、315M发射、接收模块
3、杜邦线若干(面包板可选)
4、电脑一台(有两个USB接口)

PS:如果距离相对较远的话别忘了外接天线

Arduino接线

开发板(Arduino发射)发射模块
VCCVCC
GNDGND
10data
开发板(Arduino接收)接收模块
VCCVCC
GNDGND
2data

RC-Switch库引入

点击直接穿越
在这里插入图片描述

打开连接直接下载zip版本的,然后在Arduino引入库

在这里插入图片描述

发射模块代码


/*
  Example for different sending methods
  
  https://github.com/sui77/rc-switch/
  
*/

#include <RCSwitch.h>

RCSwitch mySwitch = RCSwitch();

void setup() {

  Serial.begin(9600);
  
  // Transmitter is connected to Arduino Pin #10  
  mySwitch.enableTransmit(10);
  
  // Optional set protocol (default is 1, will work for most outlets)
  // mySwitch.setProtocol(2);

  // Optional set pulse length.
  // mySwitch.setPulseLength(320);
  
  // Optional set number of transmission repetitions.
  // mySwitch.setRepeatTransmit(15);
  
}

void loop() {

  
  /* Same switch as above, but using decimal code */
  mySwitch.send(1, 24);
  delay(2000);  
  mySwitch.send(2, 24);
  delay(2000);




  

//  /* See Example: TypeA_WithDIPSwitches */
//  mySwitch.switchOn("11111", "00010");
//  delay(1000);
//  mySwitch.switchOff("11111", "00010");
//  delay(1000);
  

//  /* Same switch as above, but using binary code */
//  mySwitch.send("000000000001010100010001");
//  delay(1000);  
//  mySwitch.send("000000000001010100010100");
//  delay(1000);

//  /* Same switch as above, but tri-state code */ 
//  mySwitch.sendTriState("00000FFF0F0F");
//  delay(1000);  
//  mySwitch.sendTriState("00000FFF0FF0");
//  delay(1000);

//   delay(20000);
}

在一个窗口粘贴好代码, 设置接收Arduino的端口,编译并上传

在这里插入图片描述

接收模块代码


/*
  Simple example for receiving
  
  https://github.com/sui77/rc-switch/
*/

#include <RCSwitch.h>

RCSwitch mySwitch = RCSwitch();

void setup() {
  Serial.begin(9600);
  mySwitch.enableReceive(0);  // Receiver on interrupt 0 => that is pin #2
}

void loop() {
  if (mySwitch.available()) {
    
    Serial.print("Received ");
    Serial.println( mySwitch.getReceivedValue() );
//    Serial.print(" / ");
//    Serial.print( mySwitch.getReceivedBitlength() );
//    Serial.print("bit ");
//    Serial.print("Protocol: ");
//    Serial.println( mySwitch.getReceivedProtocol() );
    delay(1500);
    mySwitch.resetAvailable();
  }
}

新创建一个窗口粘贴接收代码,设置端口,编译并上传

在这里插入图片描述

打开接收板的串口监视器观察接收数据
预期接收数据1和2交替循环

在这里插入图片描述

效果展示

在这里插入图片描述

实物图

在这里插入图片描述

评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值