本文介绍使用红外遥控器向Arduino发送信号。

库文件:

IRremote

下载之后放到D:\Program Files (x86)\Arduino\libraries\RobotIRremote\src目录下即可(替换为自己安装Arduino IDE的路径),如果IRremoteTools.cpp出错,删除即可

硬件:

红外接收器

Arduino

红外遥控器

其中,红外接收器与Arduino的连接方式如下所示:

将接收器朝向自己:

最左边的一根线接11;中间的线接3.3V或5V;右边的线接GND

Arduino学习(4)

测试代码:

#include <IRremote.h>     // IRremote库声明  
  
int RECV_PIN = 11;        //定义红外接收器的引脚为11  
  
IRrecv irrecv(RECV_PIN);   
  
decode_results results;   //解码结果放在 decode results结构的 result中
    
void setup()  
  {  
      Serial.begin(9600);  
      irrecv.enableIRIn(); // 启动接收器  
  }  
  
void loop() {  
    if (irrecv.decode(&results))//解码成功,收到一组红外讯号   
    {  
      Serial.println(results.value, HEX);//以16进制换行输出接收代码  
      irrecv.resume(); // 接收下一个值  
    }  
    delay(100);  
  }  

结果

Arduino学习(4)

相关文章:

  • 2021-06-14
  • 2021-06-29
  • 2021-10-18
  • 2021-04-04
  • 2021-12-01
  • 2021-05-29
  • 2021-12-31
猜你喜欢
  • 2021-12-03
  • 2022-01-11
  • 2022-01-03
  • 2022-01-07
  • 2021-06-18
  • 2021-12-12
  • 2022-02-04
相关资源
相似解决方案