IRTest
It is a great extra for your microcontroller project to be able to control it through an infrared remote control instead of classical push buttons. This article describes the process of how to make your project remote friendly.
Parts
First you need a microcontroller. I used a really cheap Arduino Nano board. Besides that an infrared (IR) receiver is required, which accepts the IR signal coming out from a remote control. You can use the IR Receiver Sensor - TSOP38238 and the Mini Remote Control from Adafruit. In order to get some feedback about the incoming signal I added a LED to the project with an 220 OHM resistor.
Wiring
The electrical connections among the project components can be seen on the following Fritzing diagram:
In real life the project will look like this on a solderless breadboard:
Code
The code was written in Arduino IDE. At first the required Arduino IRremote Library has to be install. The installation instructions can be found here.
Once it is done the communication protocol of the Remote Control has to be determined. In order to do that the IRrecvDump.ino example has to be uploaded to your microcontroller. Once you click some buttons on your remote control you will see the following output on the Serial Monitor:
The red highlights indicates the IR communication protocol, which is NEC in our case. The blue highlights are the button codes.
If you upload the IRTest.ino to your microcontroller and press any key on your remote control the LED will blink and the key will be displayed on the Serial Monitor:
Improvements
By default all send and decode protocols are turned on in the IRremote library. Now we know that all our remote controls support the NEC protocol and we only want to decode the incoming IR signals. This means that all other protocols can be turned off in the IRremote library. In order to do that the IRremote.h file has to be edited. Everything has to be set as 0 except the NEC decode functionality:
This will significantly reduce the size and the execution time of our sketch.
Arduino Mega support
The timer interrupts used in the IRremote library are in conflict with the Arduino tone() method, which is used for sound generation. In order to fix it go to IRremoteInt.h and find the following lines:
The 158 line has to be commented and the 161 line has to be commented out as indicated on the screenshot above.
Repository
The IRTest GitHub repository contains all project related materials.