wemos D1 mini / nodeMCU(ESP8266)利用ky-022和 IRremoteESP8266库接收红外编码

wemos D1 mini / nodeMCU(ESP8266)利用ky-022和 IRremoteESP8266库接收红外编码

这个帖子拖了很久,,,久到我都不记得我还没有写,哈哈哈。其实这个实验特别简单,ESP8266 IRremote的官方例程就有。还有nodeMCU版本的接线图。具体位置见下图。稍有变化的就是开发板从nodeMCU换成Wemos D1 mini而已。(所以可以看懂官方例程真的贼拉拉重要~~~
在这里插入图片描述
在这里插入图片描述

硬件电路图

红外接收模块的信号引脚需要连接在kRecvPin上(wemosD1MINI和nodeMCU的D5引脚,通用ESP8266模块的14引脚)

ESP8266KY-022
D5S
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);
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值