【小组成员】
五组:王韵淇 冯怡 吴瑶 褚冉 王澍 宋格格
一、实验目的
本次实验旨在通过Arduino Uno板和红外接收模块(Infrared-Receiver)实现对LED灯的控制。具体目标是通过遥控器的按键操作,控制连接在Arduino板上的LED灯的亮灭。通过本实验,可以加深对红外传感器工作原理和Arduino编程的理解。
二、实验器材
- Arduino Uno开发板
- 红外接收模块(Infrared-Receiver)
- 双色LED灯模块
- 9V电池
- 面包板
- 连接导线若干
- 遥控器
三、实验原理
红外传感器通过接收红外信号来识别遥控器的按键操作。Arduino Uno板通过编程解析接收到的红外信号,并根据信号的值控制LED灯的亮灭。实验中,当接收到特定的红外信号(0xFFA25D)时,LED灯亮起;接收到其他信号时,LED灯熄灭。
四、实验步骤
1. 硬件连接:
将红外接收模块的SIG引脚连接到Arduino Uno板的数字引脚7。
将双色LED灯模块的正极连接到Arduino Uno板的数字引脚13,负极接地。
使用9V电池为Arduino Uno板供电。
将所有元件按照电路图连接到面包板上。

2. 编写程序:
打开Arduino IDE,编写如下代码:
```cpp
#include <IRremote.h>
const int irReceiverPin = 7; // the SIG of receiver module attach to pin7
const int ledPin = 13; // pin 13 built-in led
IRrecv irrecv(irReceiverPin); // Creates a variable of type IRrecv
decode_results results;
void setup()
{
pinMode(ledPin, OUTPUT); // set ledpin as OUTPUT
Serial.begin(9600); // initialize serial
irrecv.enableIRIn(); // enable ir receiver module
}
void loop()
{
if (irrecv.decode(&results)) // if the ir receiver module receiver data
{
Serial.print("irCode: "); // print"irCode:
Serial.print(results.value, HEX); // print the value in hexadecimal
Serial.print(", bits: "); // print", bits:
Serial.println(results.bits); // print the bits
irrecv.resume(); // Receive the next value
}
delay(600); // delay 600ms
if(results.value == 0xFFA25D) // if receiver module receive
{
digitalWrite(ledPin, HIGH); // turn on the led
}
else
{
digitalWrite(ledPin, LOW); // turn off the led
}
}
```
3. 上传程序:
将编写好的程序上传到Arduino Uno板。
4. 测试验证:
使用遥控器按下CH-键,观察LED灯是否亮起。
按下其他键,观察LED灯是否熄灭。
五、实验结果
实验结果表明,当按下遥控器的CH-键时,LED灯能够正常亮起;按下其他键时,LED灯熄灭。这说明红外接收模块和Arduino Uno板能够正确解析红外信号,并根据信号值控制LED灯的亮灭。
六、实验总结
通过本次实验,我们成功实现了基于Arduino的红外传感器控制LED灯的功能。实验过程中,我们学习了红外传感器的工作原理、Arduino编程的基本方法以及硬件连接技巧。实验结果验证了设计的正确性和可行性,为进一步学习和应用Arduino打下了坚实的基础。
七、实验体会
本次实验让我深刻理解了红外传感器的工作原理和Arduino编程的基本方法。通过实际操作,我掌握了硬件连接和程序编写的基本技能,增强了动手能力和解决问题的能力。在实验过程中,我也遇到了一些问题,如信号解析不准确等,通过查阅资料和调试程序,最终解决了问题,这让我更加坚定了学习的信心和决心。