You have no items in your shopping cart.



Profile Informations

Login Datas

or login

First name is required!
Last name is required!
First name is not valid!
Last name is not valid!
This is not an email address!
Email address is required!
This email is already registered!
Password is required!
Enter a valid password!
Please enter 6 or more characters!
Please enter 16 or less characters!
Passwords are not same!
Terms and Conditions are required!
Email or Password is wrong!
Captcha is required!
Captcha is wrong!

Hardware: Remote Control your Arduino

Have a giant Arduino powered killbot, but can’t fancy being right next to it when you unleash it on the unsuspecting populace?  Want to change the mood-lights in your dorm without having to get up off the couch?  Why not use IR remote controls to do the walking for you?  In this article, I will be covering how to use the IRremote Library written by Ken Shirriff for the Arduino to control a seven segment display as a proof of concept.  Killbot not included.

A bit on IR remotes:

Infrared remote controls work off the premise of modulation of a signal which is then demodulated and interpreted by the receiving unit, be it the TV, a cable box, or other device. When you hit a key on your remote, the remote’s microcontroller senses the keypress and then sends a code corresponding to that keypress to the receiver by way of an infrared LED.  The destination device on the other end receives the infrared light pulses and then translates that into a code that then performs an action such as turning off the TV or changing the channel, etc.

In order to prevent one remote from turning on ALL of your appliances with line of sight to the remote, different protocols are used.  This also helps to minimize infrared interference being received from other light sources like incandescent bulbs and the sun. For example, you have a Sony TV and a Motorola cable box, with a JVC DVD player.  When you hit the power button on the Sony remote, the TV sees the Sony protocol and decodes the power button then turns on the TV.  The JVC DVD player and the Motorola cable box disregard the pulses as noise and no action is taken.  Similarly, if you have a Sony remote and you go to the Sony TV store and hit the power button on the remote, you’re likely to get thrown out of the store as you will have turned off all their TVs. (Not recommended. )  For more information on the protocols and theory behind Remote Controls, please take a look at http://www.sbprojects.com/knowledge/ir/index.php

Universal Remotes:

The whole device specific protocol does make the use of a remote a lot easier however if you have many devices (like an AV cabinet with a VCR, DVD player, Blu-ray, Sound System, CD changer and a video streamer), your coffee table can quickly be overrun with remote controls.  The cure-all to this is a universal remote which can be programmed to control specific devices.  Using our earlier example, it can control your Sony TV, JVC DVD player and Motorola cable box by using function keys to switch which codes the remote sends out.  Universal remotes are a godsend when working with microcontrollers as you can then set the remote to the Sony protocol, arguably one of the most well documented protocols to date.

Getting Started:

In this how-to, we will be using the IRremote Library for the Arduino to test our remote, get the key codes for the keys we want to use, and finally testing it out with lighting up a seven segment LED display.  You will need the following items:

  • An Arduino (I use an Arduino Uno
  • Breadboard (any size)
  • A USB A-B cable for the Arduino
  • Jumper wires
  • A three pin IR receiver module like this one from Sparkfun
  • An IR remote control  (If you don’t have a receiver or a remote control, I recommend using this kit instead as it comes with everything you need.)
  • A seven segment LED display (common cathode or – )
  • A 74HC595 shift register
  • Seven 220 ohm resistors (Red – Red – Brown)
  • An LED (any color)
  • (Optional) A camera with an LCD preview screen or camera phone.
  • (Optional) A breadboard power supply ( I recommend this one )  If you don’t have one, you can use the Arduino’s 5V pin.
  • A PC with the Arduino software pre-loaded and operational.

Let’s get to testing.

Test the remote control

In this test, we will do a basic check to ensure our  IR remote works. Nothing sucks worse than going through a howto wondering why it’s not working only to find out that a part’s busted. Turn on your camera and point your IR remote at it then press a key on your remote.  You should see something flashing in the front of the remote.  If you do, then the remote works and you can proceed with confidence.  If you don’t, check some other keys and replace the batteries in the remote just to be on the safe side.  You don’t have to take a picture of the remote to be able to see the IR light coming out of the remote.  In some remotes it may show up red and in others it may be purple.  If you have a remote that has multiple IR LEDs in the front, you may get a lot of white light.    My remote is a “mini” remote control and the IR LED is visible on the front.  In the picture below, I am holding down the POWER button, and you can see by the purple light that my remote is working.

If your camera doesn’t show the flashing LED and you replaced the batteries on it, try another camera or see if the remote operates the device it is supposed to work with.  Some cameras have an IR blocking film on the lens which will not allow the IR from the LED through.  Cameras in cellphones usually do not have this film.

Testing the IR receiver

Now we know that the IR remote works, it’s time to test the IR receiver. You will need to check your receiver’s datasheet to be sure however most three-wire IR receivers use the same wiring method.  With the bulb (curved part) of the receiver facing you, the left most pin is signal out.  The middle pin is Ground (Vss) and the rightmost pin is +5V (Vcc)  Set up your breadboard like the image below.  The right pin should go to your power rail on your breadboard, the middle pin should go to the ground rail on your breadboard.  The left pin goes to a resistor which goes to the cathode side (look for the flat part) of the LED while the anode side should go to your power rail.  Look at the image below for layout.

Now for the moment of truth. Turn on your power supply and the LED should stay off.  Point your remote control at the receiver and press a button.  The LED should blink rapidly as long as you hold down the button.  If it does not, shut off your power supply and check your connections.  In the image below, the LED is lit up however it was flashing when I took the image.

Importing the Library

Now that we have determined that the remote and the IR receiver work, it’s time to get the IR library.  Head over to Ken Shirriff’s Blog and download the IRremote.zip file.  Look for the link under the image of the Arduino and Remote.

When you download the file, extract it and you should have a directory called “IRremote”.  You will want to copy this into your Libraries directory for the Arduino program:

  • Windows users: Copy the directory into arduino-XXXX/Libraries (wherever you have copied the Arduino directory to). Since mine’s on the Desktop, it’s Desktop/Arduino-2200/Libraries.
  • Linux users:  Copy the directory into /usr/share/arduino/libraries
  • Mac users:  I don’t know.  If you figure it out, drop me a comment and I’ll add it here.

Connecting Hardware and getting your key codes

Now that the library is imported, we need to hook up the IR receiver to the Arduino so we can read the codes for our remote.  If you haven’t already done so, bridge the +5V and the GND lines from the Arduino over to your breadboard, then hook up the center pin of the IR receiver to the GND rail and the right most pin to the +5V rail pretty much like we had it connected for testing. Instead of using a resistor and LED for the output pin, we will connect a jumper from the output pin to pin 11 of the Arduino. Use the above images as a guide.

Load the example code from File -> Examples -> IRremote -> IRrecvDemo then click the “Upload” button. (second from the rightmost icon on the toolbar).  This will push the code to the Arduino.

Click the “Serial Monitor” button to bring up a window that will allow us to see the codes being returned to us by the Arduino.  Start mashing buttons and you should see a lot of numbers scroll by like in the image below.

In the above screenshot (click for larger image), you can see several codes.  The ones that start off with FF and then have numbers or letters are the codes we are after. A FFFFFFFF is a continuation code and the 0 on its own line is a read error.  This code will spit out the hex value of the protocol being used by your remote for the button you pressed.  It is recommended to “map out” all the buttons you plan on using for your project and write them down.

My remote has a total of 21 buttons however I am only interested in the keypad buttons (0-9) and power. In case anyone else has this same remote, here are the hex values for my remote (generic chinese knockoff, model number YK-001 ).

  • POWER – FFA25D
  • MODE – FF629D
  • MUTE – FFE21D
  • PREV – FF22DD
  • NEXT – FF02FD
  • PAUSE – FFC23D
  • VOL – – FFE01F
  • VOL + – FFA857
  • EQ – FF906F
  • Digit 0 – FF6897
  • 100+ – FF9867
  • Go Back – FFB04F
  • Digit 1 – FF30CF
  • Digit 2 – FF18E7
  • Digit 3 – FF7A85
  • Digit 4 – FF10EF
  • Digit 5 – FF38C7
  • Digit 6 – FF5AA5
  • Digit 7 – FF42BD
  • Digit 8 – FF4AB5
  • Digit 9 – FF52AD

Your values will probably differ from what I’ve listed above.

Now for something fun

Moar Hardware!

Once we have obtained our key codes, we can then set about to do something with it. As an example, we will be using the 74HC595 shift register and the seven segment display to light up the corresponding digit when we press a key on the remote.  For those of you that have never used a shift register, it is a well known chip that allows you to use the arduino command shiftOut to send a sequence to the 74HC595 which will then show that sequence via the eight pins that form its output port.   For example, sending it “01001001″ would cause the 595′s output pins 1,4 and 7 to go into a high state.   The advantage is that the shift register only requires three lines from the Arduino in order to be able to control 8 lines on the 595 making it an easy way to expand the Arduino’s limited pins.  For more details about daisy chaining the 74HC595, check out http://bildr.org/2011/02/74hc595/ which describes the 74HC595 in detail. Below is a schematic diagram of a 74HC595.

In order to connect the shift register to the Arduino, we will use pin 14 (Data), pin 12 (Latch) and pin 11 (Clock).  The output port (q0-q7, pin 15 and pins 1-7) are what we will hook up to the LED display. The Reset line (pin 10) must be connected to +5V in order for the chip to work and the output pin (Pin 13) should be sent to ground.  Your board will turn into a spaghetti bowl, however it will be worth it when the project is complete.

This is the pinout of a seven segment LED display.  Since the shift register has 8 output pins and the seven segment LED only has seven, (not counting the decimal point), we will be hooking up the pins one-to-one starting with Q0.  In the above two images, Q0 will go to element “a”, Q1 will go to element “b” and so on.  We will not be using Q7 or the decimal point, so you can allow these to float (not connected). Between each of the 74HC595 output pins and the pins of the 7segment LED display, we will need to add a 220 ohm resistor.  This will ensure that neither the 595 nor the LED display are damaged from overcurrent.  Because there are many different styles of LED displays with varying pinouts, I did not show my configuration however there are pictures below.

Moar Software!

With the hardware defined, we need to know what to shift out to the 595 in order to light the segments.  Since the 74HC595 works in binary but we are allowed to shift out a decimal number thanks to the arduino, the number to shift out is something that can be solved with some quick math.  This method of calculation applies to any device using a shift register, not just for this project so it may come in handy later on.    Each element has a value assigned to it that will light it.  “A” for example (top center) has the value of “1″ while element “G” (center) has a value of 64 which gives us the following chart:

  • A = 1
  • B = 2
  • C = 4
  • D = 8
  • E = 16
  • F = 32
  • G = 64

In order to form the characters we want, we have to come up with a “truth table”  This table shows how we convert each number into a desired format, then convert that format into the elements desired, then we get the values we need to light the segments we want.   Below is the truth table for this project:
(Triple dash) = Elements a,g,d = 1+64+8 =  73

  • 0 = a,b,c,d,e,f = 1+2+4+8+16+32 = 63
  • 1 = b, c = 2+4 = 6
  • 2 = a, b, d, e, g = 1+2+8+16+64 = 91
  • 3 = a,b,c,d,g = 1+2+4+8+64 = 79
  • 4 = b,c,f,g = 2+4+32+64 = 102
  • 5=a,c,d,f,g = 1+4+6+32+64 = 109
  • 6=a,c,d,e,f,g = 1+4+8+16+32+64 = 125
  • 7=a,b,c = 1+2+4 = 7
  • 8=a,b,c,d,e,f,g = 1+2+4+8+16+32+64 = 127
  • 9=a,b,c,f,g = 1+2+3+32+64 = 103

The best way to use this truth table and the key values used earlier would be with a “switch” statement.  This is computationally faster than using a nested chain of if… then statements as shown below.  Copy and paste the below text into your Arduino environment and upload it.


int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
int latchPin = 4;
int clkPin = 3;
int dataPin = 2;
int digit = 0;

void setup()
  pinMode(latchPin, OUTPUT);
  pinMode(clkPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  irrecv.enableIRIn(); // Start the receiver
  digitalWrite(latchPin, LOW);
  digitalWrite(latchPin, HIGH);

void loop() {
  if (irrecv.decode(&results)) {
    switch (results.value)  {
      case 0xFFA25D:
      case 0xFF6897:
      case 0xFF30CF:
      case 0xFF18E7:
      case 0xFF7A85:
      case 0xFF10EF:
      case 0xFF38C7:
      case 0xFF5AA5:
      case 0xFF42BD:
      case 0xFF4AB5:
      case 0xFF52AD:
     digitalWrite(latchPin, LOW);
     digitalWrite(latchPin, HIGH);
  irrecv.resume(); // Receive the next value

Once uploaded, your LED display should show the triple dash like in the image below

If you get the triple dash, you should be able to hit any number on the keypad and change the number on the LED display.  In the below image, I’m hitting the digit 5, and the number 5 is displayed.

Currently, the code will allow you to hit any digit between 0 and 9 and the LED display will show the number you pressed. Pressing the POWER button will give you the triple dash again.


  • If the LED display is disfigured but you get three segments lit, chances are you got two of the pins reversed. Cycle through the numbers on your remote and you should be able to identify the two pins that need to be swapped.
  • If you get nothing from the LED display, check your wiring.  Make sure you wired the 595 chip correctly to the LED display and to the Arduino.
  • If your LEDs are extremely bright, disconnect power immediately, you have shorted the LED display straight to the +5V rail and you may blow a segment.
  • If your LED display does not change from the triple dash, check your Serial Monitor and ensure that commands are being received by the Arduino.
  • If you are getting readouts on the Serial Monitor but nothing on the LED display, check that the Clock, Data and Latch pins are correct on the 74HC595.

Code Analysis

The code is not very complex.  Basically, it checks to see if there is any data in the results from the irrecv.decode process (included in the library) and if so, it runs the switch statement against it.  If the code matches any of the case statements, it will set “digit” to that value and send out a small description of what button was pressed.  At the end of the switch statement, but still inside the if.. then statement, it will shift out the resulting digit, even if it’s the same.  Because of the if.. then statement, the Arduino will only shift out if there is something in the results variable and the digit will only change if the results variable matches any of the predefined case statements.This will eliminate the issue of noise interfering with the defined code values.  Be sure to not specify a default result in your case statement, as you do not want to process any erroneous or noisy IR signals.  The “Serial.println” statements can be removed, this is primarily a debugging and proof of concept code.

Keep in mind, after irrecv.decode has been called, you must restart the receiver by using the syntax “irrecv.resume();” otherwise your code will read once from the IR receiver and exit which would render your Arduino uncontrollable.

What to do next?

Now that you have the proof of concept and the library, you can do tons of things now.  The IRremote library we used has transmission capabilities as well as receiver capabilities so you could use your Arduino to control your TV and other appliances or perhaps, you could go with the idea in the summary and build a killbot to conquer Earth. Barring that, you could always use the remote to turn on and off appliances that don’t have a remote control.   Personally, I can see multiple applications, one specifically involving a light dimmer and an Arduino controlled servo. Instead of using VOL+ and VOL- for sound, it can control the lighting instead.

Via firestorm_v1