Controlling your Arduino Project with a Standard Remote Control

RSS
20141015_160145

Controlling your Arduino Project with a Standard Remote Control

Learning Outcomes: In this tutorial we will focus on using an infra-red receiver and an Arduino micro-controller to receive signals from any infra-red remote (such as your television remote).  We can then program the Arduino to react in unique ways to specific button presses, such as turning on an LED.   Components required for this tutorial: 1 Arduino (Any Arduino will do) 1 USB cable 1 Infra-red receiver 1 or more LEDs 1 Resistor (220-ohm) 1 Breadboard Assorted Jumper wires A remote control (such as a television remote)   Instructions: Step 1 – Setting up the Arduino: First, we need to connect the infra-red sensor to the Arduino so that it is ready to receive IR signals from your remote.  To do this, connect the left leg of your sensor to a digital pin (in this case we are using 11), the middle leg to ground and the right leg to +5V. 20141015_144730 ck_im1 Step 2 – Finding the IR values of your remote: This tutorial is assuming you are a least a little familiar with Arduino and have set up the environment .  Now we need to find a way to decode the IR signals with our sensor.  In order for the sensor to change the light it is receiving into a usable number, we need to measure the pulse of the light. The easiest way to do this is to download a pre-made external library for Arduino here.  To install the library, all you need to do is move the unzipped IRremote directory to your Arduino libraries folder (where you first installed the Arduino IDE). Now that we have our library, we can open Arduino.  I have provided the basic code below that we will use to get our values below, with explaining comments:
#include <IRremote.h> int IRpin = 11; IRrecv irrecv(IRpin); decode_results results; void setup() { Serial.begin(9600);  //open the serial port irrecv.enableIRIn(); // start receiving data } void loop() { if (irrecv.decode(&results)) { Serial.println(results.value, DEC); //print the value irrecv.resume(); // receive the next value } }
  Now we can begin to get IR values from our remote.  First, upload the sketch to your Arduino. Next open the Serial Monitor: ck_im2    Now, aim your remote control at the sensor and press a button.  You should see a decimal value appear on your serial monitor. 20141015_150934   ck_im3 Press the same button a few times to make sure the same value repeats itself. The value itself may look like gibberish, but be sure to make note of it (write it down!). Many times a remote button will have multiple functions (such as with a universal remote) and will give off multiple values, so it’s easiest if you stick with a button that consistently shows one value in the serial monitor.    Step 3 – Using our IR receiver values to turn on an LED: Once you’ve found the values of your remote control buttons that you wish to use in your project, the world is your oyster!  In this tutorial we will use turning an LED on and off as an example, but you can use the IR signals however you wish! First we must set up our LED circuit alongside our IR receiver, by connecting an LED to our breadboard.  In this case the output of the LED should be connected to pin 6 (using the resistor!) and the ground to the ground rail.  Note that we have modified our previous circuit to have a common ground and power. 20141015_153148 ck_im4 Now we can modify our code to use the inputted remote IR values to turn the LED on and off.  Using the value we made note of in the previous step, we can write a simple if statement to turn on the LED if that value is read.  See the code below with changes highlighted, and note the comments for a description. Make sure you use the value you found in the second step!
include <IRremote.h> int IRpin = 11; int ledpin = 6; //pin LED is connected to IRrecv irrecv(IRpin); decode_results results; void setup() { Serial.begin(9600);  //open the serial port irrecv.enableIRIn(); // start receiving data pinMode(ledpin, OUTPUT); //define LED as output } void loop() { if (irrecv.decode(&results)) { Serial.println(results.value, DEC); //print the value if(results.value==16679039) // your value here         {            digitalWrite(ledpin, HIGH);   // turn the LED on            delay(1000);               // wait for a second         } irrecv.resume(); // receive the next value } }
  ck_im5 Now if we upload this sketch, we can use our remote to turn on the LED! Make sure you use the value related to the button you pressed.  If the LED does not turn on, first check your serial monitor again to make sure the value matches the value in your if statement, then check your circuit wiring. 20141015_160145   Conclusion – Applying our IR receiver values to other projects: With this tutorial we learned the basics of using infra-red receiver sensors with Arduino micro-controllers.  Once you understand how to use the IR values to turn on an LED, you can apply it to your own projects.  It does not need to be limited to turning things on or off either.  For example, you could create a light sculpture with RGB LEDs and use the remote to choose the light color, or use it as a dimmer, etc. You can program the Arduino to use the remote control buttons however you wish!    

Next Post

  • 122
Comments 0
Leave a comment
Your Name:*
Email Address:*
Message: *

Please note: comments must be approved before they are published.

* Required Fields