How to Connect an IR Receiver to an Arduino

发布人是

It's only been a few decades since “traditional” TV/VCR/stereo control via infrared (IR) light came onto the scene in the 1980s. While not the most advanced remote-control method now available, it’s inexpensive, and it usually works. Its simplicity means that Arduino IR remote control projects can be implemented for around a dollar for the receiver, plus any spare remote that you have lying around unused.

IR Remote Arduino Library: Accessing Remote Code

Arduino IR Remote Image 2

Arduino IR Remote Image 3

To use an IR receiver with your Arduino board or other microcontrollers like the ATtiny85 or ATtiny84, first install the IRremote library by Ken Shirriff. This can be found by searching for irremotelibrary through the Arduino library manager, or it’s available on GitHub here. When installed, you’ll have access to several new examples under File-Examples-IRremote.

For this control experiment, you can use an Arduino Uno, along with a Vishay TSOP4838 IR Remote Receiver. This particular receiver is designed to work with signals in the 38kHz range, and filters out most naturally occurring light, while demodulating signals from standard consumer remote control units. The TSOP4838’s supply pin is connected to Arduino 5V, ground to ground, and its output pin to Arduino pin 11.

参阅相关产品

A000066 | Arduino Uno Rev3

Arduino Corporation 嵌入式系统开发板和套件 查看

参阅相关产品

TSOP4838

Vishay 红外线遥控接收器 查看

Open up the IRrecvDemo example and upload it to your board. With the Arduino still connected, open the serial monitor via Tools-Serial Monitor or Ctrl+Shift+M, and you’ll see a couple initial messages about the enabled IR input. Grab a remote—pretty much any remote—point it at the TSOP4838 and press a button. You’ll see the IR code pop up on the terminal in hexadecimal, indicating that it’s reading properly.

Arduino IR LED Control

To make this a little more fun, you can even add feedback from the built-in LED. You can probably figure out how to do that, but this lightly modified version of Shirriff's code produces LED feedback on the built-in LED with the push of any button. It’s not what you’d want in most situations, but it does prove that things are working.

Setting Arduino IR Remotes to Respond to Individual Codes

Arduino IR Remote Image 4

Of course, the real power of this type of remote is that it can change the channel, volume, robot position or anything else. The next step is to identify the button you want to use and have your Arduino respond when it sees this input. The earlier example identifies your particular remote codes, and this expanded version adds switch case statements to trigger different actions.

This code presents three code input options, as well as a default “Unknown code” scenario that’s activated when it doesn’t recognize what has been sent. These options can be copied, deleted and modified as needed, and you’ll probably want to set the output to something more interesting than giving you feedback about the button that was pressed. Substitute in your own remote codes to activate each option. Note that this setup can work with different types of remotes, even using different brands or styles in the same program.

Once you’ve mastered controlling an Arduino via an external infrared controller, you can also use the Arduino itself to generate these signals. This could allow it to control another custom receiver setup, or even act as a universal Arduino IR remote control.


最新消息

Sorry, your filter selection returned no results.

请仔细阅读我们近期更改的隐私政策。当按下确认键时,您已了解并同意艾睿电子的隐私政策和用户协议。

本网站需使用cookies以改善用户您的体验并进一步改进我们的网站。此处阅读了解关于网站cookies的使用以及如何禁用cookies。网页cookies和追踪功能或許用于市场分析。当您按下同意按钮,您已经了解并同意在您的设备上接受cookies,并给予网站追踪权限。更多关于如何取消网站cookies及追踪的信息,请点击下方“阅读更多”。尽管同意启用cookies追踪与否取决用户意愿,取消网页cookies及追踪可能导致网站运作或显示异常,亦或导致相关推荐广告减少。

我们尊重您的隐私。请在此阅读我们的隐私政策。