Control an Arduino With a TV Remote - LEKULE

Breaking

19 Nov 2015

Control an Arduino With a TV Remote

Introduction

One fun way to control an Arduino is with a TV remote. In this project, I am going to show you how you can use any of the buttons on a standard infrared remote control to activate functions on an Arduino.

Required Materials


Arduino Microcontroller
38 kHz Infrared Receiver Module
Momentary Switch
100 kohm Resistor
2 x 100 ohm resistor
Green LED
Red LED
Relay (5V 20 mA )
Diode
Breadboard or Printed Circuit Board
Jumper Wires

Download and Install the IRRemote Library

This project uses a multi-protocol infrared remote library that was developed by Ken Shirriff. This library allows the Arduino to both decode and transmit the infrared signals that are used in most commercial remote control systems. I highly recommend reading his tutorial on how to use the library.
You can download a copy of the IRRemote Library by going to his GitHub page and clicking the “Download ZIP” button on the right side of the page.
Next extract all the files. Move the "IRRemote" folder that has been extracted to your Arduino libraries directory. In the most recent versions of the Arduino software, there is another folder already in the library directory called “RobotIRremote.” This has a subfolder in it that is also named “IRRemote.” If both folders are in the library, the Arduino won’t know which one to reference and it will generate an error. The easiest way to resolve this problem is to simply delete the RobotIRremote folder. If you don’t want to delete it, you can go into the subfolders and rename all the folders that cause conflicts.


Connecting the Infrared Receiver Module


The infrared receiver module has three pins. As illustrated in the picture below, the right pin connects to 5V. The center pin connects to GND. The left pin is the output pin and connects to one of the digital pin on the Aduino set to input mode. This pin configuration may be different depending on the manufacturer of your part. So always consult the manufacturers datasheet before hooking it up. This in the only part that you need in order to receiver infrared signals with your Arduino. Once you have made these connections, you are ready to set up code.


The Arduino Code

Using this code, the Arduino will constantly monitor the output of the IR receiver module. When it detects a signal from a remote, it decodes the signal and converts it into a numerical value. This value is stored in a variable and can be used to activate any functions that you wish to add into the code. Using the Serial Monitor tool, you can see the number values that are generated by each button on your remote. Once you know the values, all you have to do is add them into your code and set up conditional statements that will perform the desired action whenever this button is pressed on the remote. When writing the code, keep in mind that a lot of remotes will send the same code multiple times or a series of codes every time you press a button.

 

Example Project


To better illustrate how you can use this technique with your Arduino projects, here is an example. I set up my Arduino to activate a relay whenever a certain signal is detected. This would allow you to turn connected appliances on and off with your remote. I also added a “Program” button that would allow me to change the set remote code while the system is still operating.

First the IR receiver module is connected to 5V, GND and PIN 12. Then a 100 kohm resistor is connected between GND and pin 10. A momentary switch is connected between pin 10 and 5V. An LED and 100 ohm series resistor are connected to both pin 8 and pin 7. Lastly a relay and a flyback diode are connected between digital pin 4 and ground. In general the output pins of an Arduino shouldn’t output more than 20 mA. So if your relay requires more than 20 mA, then you should drive it with a power transistor.


I mounted the relay and diode on a separate circuit board and enclosed them inside an insulated project enclosure. This allows me to safely control AC appliances.
Next upload the attached code.
When you press the button, the first LED will turn on to indicate that the system is in “programming mode.” The next signal that the system receives from a remote will be stored as the activation code. So pick a button on the remote that you want use and press it. When the system receives the code, the second LED will turn on indicating that they code is set. Now whenever you press that button on the remote, the relay will turn on or off.


It should be noted that the programmed functions will be reset if the Arduino is turned off. If you want the programmed function to be permenant, you should write the values into the code.

No comments: