基于Arduino Uno开发板的红外遥控开发

本文介绍了基于Arduino Uno开发板的红外遥控开发过程,包括硬件准备、走线配置、代码编写与修改。通过使用Arduino应用程序和IRremote库,实现了红外遥控器的接收与发送功能,详细解析了ReceiveDump和SendRawDemo两个示例代码的修改步骤。
摘要由CSDN通过智能技术生成

基于Arduino Uno开发板的红外遥控开发

1 准备

1.1 硬件与软件

  1. 单片机
  2. Arduino应用程序:
    https://www.arduino.cc/en/software

1.2 走线

如图,arduino走线
需要舵机,红外接收器,红外发射器以及遥控器

2 代码

Arduino在IRremote库中提供了许多例子,在已有例子的基础上稍微加以改动便可以实现红外遥控

2.1 ReceiveDump

在这里插入图片描述
新建了示例之后,在PinDefinitionsAndMore.h文件中复制

#define IR_RECEIVE_PIN          14 // D5
#define IR_SEND_PIN             12 // D6 - D4/pin 2 is internal LED

在ReceiveDump中的

#include <Arduino.h>

//#define RAW_BUFFER_LENGTH  750  // 750 is the value for air condition remotes.

/*
 * You can change this value accordingly to the receiver module you use.
 * The required value can be derived from the timings printed here.
 * Keep in mind that the timings may change with the distance
 * between sender and receiver as well as with the ambient light intensity.
 */
#define MARK_EXCESS_MICROS    20 // recommended for the cheap VS1838 modules

//#define RECORD_GAP_MICROS 12000 // Activate it for some LG air conditioner protocols
//#define DEBUG // Activate this for lots of lovely debug output from the decoders.

#include "PinDefinitionsAndMore.h" //Define macros for input and output pin etc.
#include <IRremote.hpp>

//+=============================================================================

Include <IRremote.hpp>这一行之后粘贴,将#define RAW_BUFFER_LENGTH取消注释,变成

#include <Arduino.h>

#define RAW_BUFFER_LENGTH  750  // 750 is the value for air condition remotes.

/*
 * You can change this value accordingly to the receiver module you use.
 * The required value can be derived from the timings printed here.
 * Keep in mind that the timings may change with the distance
 * between sender and receiver as well as with the ambient light intensity.
 */
#define MARK_EXCESS_MICROS    20 // recommended for the cheap VS1838 modules

//#define RECORD_GAP_MICROS 12000 // Activate it for some LG air conditioner protocols
//#define DEBUG // Activate this for lots of lovely debug output from the decoders.

#include "PinDefinitionsAndMore.h" //Define macros for input and output pin etc.
#include <IRremote.hpp>
#define IR_RECEIVE_PIN          14 // D5
#define IR_SEND_PIN             12 // D6 - D4/pin 2 is internal LED
//+=============================================================================

将IR_RECEIVE_PIN后的14改为红外接收器的接收管脚,
将IR_SEND_PIN后的12改为红外发射器的发射管脚
最终是

#include <Arduino.h>

#define RAW_BUFFER_LENGTH  750  // 750 is the value for air condition remotes.

/*
 * You can change this value accordingly to the receiver module you use.
 * The required value can be derived from the timings printed here.
 * Keep in mind that the timings may change with the distance
 * between sender and receiver as well as with the ambient light intensity.
 */
#define MARK_EXCESS_MICROS    20 // recommended for the cheap VS1838 modules

//#define RECORD_GAP_MICROS 12000 // Activate it for some LG air conditioner protocols
//#define DEBUG // Activate this for lots of lovely debug output from the decoders.

#include 
  • 0
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值