IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 嵌入式 -> 基于Arduino Uno开发板的红外遥控开发 -> 正文阅读

[嵌入式]基于Arduino Uno开发板的红外遥控开发

基于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 "PinDefinitionsAndMore.h" //Define macros for input and output pin etc.
#include <IRremote.hpp>
#define IR_RECEIVE_PIN          6 // D5
#define IR_SEND_PIN             3 // D6 - D4/pin 2 is internal LED
//+=============================================================================

然后保存
在这里插入图片描述
确定,在选定目录上新建一个同名文件夹
在这里插入图片描述

存储任何ino(Arduino)文件时都不能使用中文名

进入文件夹,保存,上传
在这里插入图片描述
在这里插入图片描述

打开串口监视器,波特率ino文件中是115200。
在这里插入图片描述
对遥控器的开关键进行解码
请添加图片描述

Result as microseconds array - compensated with MARK_EXCESS_MICROS=20
uint16_t rawData[229] = {很多数};  // Protocol=UNKNOWN Hash=0x24B61CFE 115 bits (incl. gap and start) received

复制中间的一串数到记事本内。

2.2 SendRawDemo

同样打开SendRawDemo示例,进行更改
在代码中的#include <IRremote.hpp>后添加2行

#include <Arduino.h>

#include "PinDefinitionsAndMore.h" //Define macros for input and output pin etc.
#include <IRremote.hpp>
// On the Zero and others we switch explicitly to SerialUSB
#if defined(ARDUINO_ARCH_SAMD)
#define Serial SerialUSB
#endif
}

改成(增加IR_RECEIVE_PIN 6和IR_SEND_PIN 3的设置)

#include <Arduino.h>

#include "PinDefinitionsAndMore.h" //Define macros for input and output pin etc.
#include <IRremote.hpp>
#define IR_RECEIVE_PIN          6 // 自行设置
#define IR_SEND_PIN             3 // 自行设置
// On the Zero and others we switch explicitly to SerialUSB
#if defined(ARDUINO_ARCH_SAMD)
#define Serial SerialUSB
#endif

然后更改下面代码。

    const uint16_t rawData[] = { 9000, 4500/*Start bit*/, 560, 560, 560, 560, 560, 1690, 560,
            560/*0010 0x4 of 16 bit address LSB first*/, 560, 560, 560, 560, 560, 560, 560, 560/*0000*/, 560, 1690, 560, 1690, 560,
            560, 560, 1690/*1101 0xB*/, 560, 1690, 560, 1690, 560, 1690, 560, 1690/*1111*/, 560, 560, 560, 560, 560, 560, 560,
            1690/*0001 0x08 of command LSB first*/, 560, 560, 560, 560, 560, 560, 560, 560/*0000 0x00*/, 560, 1690, 560, 1690, 560,
            1690, 560, 560/*1110 Inverted 8 of command*/, 560, 1690, 560, 1690, 560, 1690, 560, 1690/*1111 inverted 0 of command*/,
            560 /*stop bit*/}; // Using exact NEC timing
    IrSender.sendRaw(rawData, sizeof(rawData) / sizeof(rawData[0]), NEC_KHZ); // Note the approach used to automatically calculate the size of the array.

将复制的源码在记事本中分成2段,第一段为偶数个数值,第二段可以为奇数个数值;
将代码更改为

    const uint16_t rawData0[] = { 3080,2970, 3080,4370, 580,1570, 580,520, 580,1620, 580,520, 580,520, 530,1620, 580,1620, 580,520, 530,1620, 580,520, 530,1670, 580,1570, 580,520, 580,520, 530,570, 580,520, 530,520, 580,520, 580,520, 530,1670, 580,520, 530,1620, 580,520, 580,1570, 580,520, 580,520, 480,620, 580,520, 580,470, 530,570, 580,520, 480,620, 580,520, 580,1570, 580,1620, 530,570, 580,1570, 530,570, 580,520, 530,1620, 580,520, 580,1620, 580,1620, 530,520, 580,1620, 530,1670, 580,470, 580,520, 580,520, 530,570, 580,520, 580,470, 580,520, 580,520, 580,520, 580,520, 580,470
    }; // Using exact NEC timing
    const uint16_t rawData1[] = { 580,520, 580,1620, 530,570, 580,520, 580,470, 580,520, 580,520, 530,570, 580,520, 580,470, 580,520, 580,520, 580,520, 530,570, 580,470, 580,520, 580,520, 580,520, 530,570, 580,520, 580,470, 580,520, 580,520, 530,570, 580,520, 580,470, 580,520, 580,520, 580,520, 480,620, 580,470, 580,520, 580,520, 580,520, 530,570, 580,520, 580,470, 530,570, 580,520, 480,620, 580,520, 580,470, 530,570, 580,520, 580,520, 530,570, 580,1570, 580,520, 580,1620, 530,1620, 580,520, 580,520, 580,520, 580,470, 580,1620, 580
    }; // Using exact NEC timing
    IrSender.sendRaw(rawData0, sizeof(rawData0) / sizeof(rawData0[0]), NEC_KHZ); // Note the approach used to automatically calculate the size of the array.
    IrSender.sendRaw(rawData1, sizeof(rawData1) / sizeof(rawData1[0]), NEC_KHZ); // Note the approach used to automatically calculate the size of the array.

保存代码,上传。成功!

  嵌入式 最新文章
基于高精度单片机开发红外测温仪方案
89C51单片机与DAC0832
基于51单片机宠物自动投料喂食器控制系统仿
《痞子衡嵌入式半月刊》 第 68 期
多思计组实验实验七 简单模型机实验
CSC7720
启明智显分享| ESP32学习笔记参考--PWM(脉冲
STM32初探
STM32 总结
【STM32】CubeMX例程四---定时器中断(附工
上一篇文章      下一篇文章      查看所有文章
加:2022-08-06 11:00:44  更:2022-08-06 11:03:41 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年12日历 -2024/12/28 17:23:26-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码
数据统计