wemos D1 mini / nodeMCU(ESP8266)利用ky-022和 IRremoteESP8266库接收红外编码
这个帖子拖了很久,,,久到我都不记得我还没有写,哈哈哈。其实这个实验特别简单,ESP8266 IRremote的官方例程就有。还有nodeMCU版本的接线图。具体位置见下图。稍有变化的就是开发板从nodeMCU换成Wemos D1 mini而已。(所以可以看懂官方例程真的贼拉拉重要~~~)


硬件电路图
红外接收模块的信号引脚需要连接在kRecvPin上(wemosD1MINI和nodeMCU的D5引脚,通用ESP8266模块的14引脚)
| ESP8266 | KY-022 |
|---|---|
D5 | S |
| 5V | 中间引脚 |
| GND | - |

IRremoteESP8266库安装
- 下载地址

- 安装ZIP库

在打开的文件浏览器中定位到你刚刚下载zip的路径,双击打开,Arduino IDE中没有报错就证明库安装好了。

- 验证库安装的正确性

源代码IRrecvDemo.ino
/*
* IRremoteESP8266: IRrecvDemo - demonstrates receiving IR codes with IRrecv
* This is very simple teaching code to show you how to use the library.
* If you are trying to decode your Infra-Red remote(s) for later replay,
* use the IRrecvDumpV2.ino (or later) example code instead of this.
* An IR detector/demodulator must be connected to the input kRecvPin.
* Copyright 2009 Ken Shirriff, http://arcfn.com
* Example circuit diagram:
* https://github.com/crankyoldgit/IRremoteESP8266/wiki#ir-receiving
* --------------------------------------------------------
* 中文说明:
* -----------------------------------------------------
* IRremoteESP8266:IRrecvDemo-这个例子演示了如何利用这个库实现红外信号的接收
* 这是一个非常简单的演示
* 如果你要进一步解码你的信息可以参见IRrecvDumpV2.ino这个例子
* 红外接收模块的信号引脚需要连接在kRecvPin上(wemosD1MINI和nodeMCU的D5引脚,ESP8266模块的14引脚)
* 版权:2009 Ken Shirriff, http://arcfn.com
* Changes:
* Version 0.2 June, 2017
* Changed GPIO pin to the same as other examples.统一了不同例子所使用的引脚
* Used our own method for printing a uint64_t.
* Changed the baud rate to 115200.
* Version 0.1 Sept, 2015
* Based on Ken Shirriff's IrsendDemo Version 0.1 July, 2009
*/
#include <Arduino.h>
#include <IRremoteESP8266.h>
#include <IRrecv.h>
#include <IRutils.h>
// An IR detector/demodulator is connected to GPIO pin 14(D5 on a NodeMCU
// board).
// Note: GPIO 16 won't work on the ESP8266 as it does not have interrupts.
const uint16_t kRecvPin = 14;
IRrecv irrecv(kRecvPin);
decode_results results;
void setup() {
Serial.begin(115200);//设置波特率
irrecv.enableIRIn(); // 启动红外接收
while (!Serial) // 等待建立串口连接
delay(50);
Serial.println();
Serial.print("IRrecvDemo is now running and waiting for IR message on Pin ");//串口显示:接收装置已经就绪等待接收数据 这是你就发送红外信号了
Serial.println(kRecvPin);//讲接收的红外信息显示在串口显示器中
}
void loop() {
if (irrecv.decode(&results)) {
// print() & println() can't handle printing long longs. (uint64_t)
serialPrintUint64(results.value, HEX);
Serial.println("");
irrecv.resume(); // Receive the next value
}
delay(100);
}

822

被折叠的 条评论
为什么被折叠?



