基于Arduino Uno开发板的红外遥控开发
1 准备
1.1 硬件与软件
- 单片机
- Arduino应用程序:
https://www.arduino.cc/en/software
1.2 走线
如图,
需要舵机,红外接收器,红外发射器以及遥控器
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