Let's Make Robots!

Phase 3 Part 1 - IR Receiver/Remote Sketch

In-Depth photos and videos of this project are available on my photobucket library.

You can download the IRremote library by clicking here and following the instructions. 

Before I even began trying to get the IR values from my remote, I had to test the receiver to make sure it even worked because it traveled a long time on a slow boat to get to me. Adafruit has a good tutorial on testing, but unlike their tutorial, I wired power & ground straight into my arduino like in the photo below. For some reason an artifact uploaded from my iphone (green horizontal line), so ignore that. You don't need a sketch loaded into the arduino to test your receiver. I simply loaded the "bare minimum" sketch. To see if your receiver is working, just press a button on your remote and the LED lights up. Easy.


Now that I know the receiver is working, it's time to get some meaningful info from it.

Install the library, wire the receiver for testing as shown in this photo and copy/paste the sketch below. You'll need to change a few values based on what pins you're using and what button you need info on. Run the sketch.

The sketch I cobbled up is as simple as it gets. When you press a button on the IR remote, the signal gets decoded and prints that button's hex code to the Serial Monitor. Press any button a couple times and see what number pops up for your particular remote and it's corresponding button. It will be a string of several numbers (either positive or negative) looking like this: -1386468558

Press any button you want info on several times. If you press it too fast, you'll get a -1 as a result. Wait a second and try again. After you locate the value of the button in the serial monitor, paste that number into the code's case value and re-upload the sketch. I wanted to make sure that I had this functioning as intended and not just a fluke, so I wired up a second LED. The sketch is written to light up a blue LED when the power button is pressed and a red LED when the play button is pressed. Here's a video showing it in action.

This shows my project with both lights.



I'm not sure exactly how many remote brands it reads from in the library, but it worked with the IR remote from a SainSmart Arduino Kit. I also tested a Sony BlueRay and Vizio TV remote and got results from both. The library seems pretty powerful.

Below is the sketch for detecting and serially displaying the IR Remote's Signal. 

#include <IRremote.h>

int RECV_PIN = 2;

int powerPin = 7; //i have the blue LED wired to D7 with a 220 ohm resistor

int playPin = 8; //i have the red LED wired to D8 with a 220 ohm resistor


IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()



irrecv.enableIRIn(); // Start the receiver

pinMode(powerPin, OUTPUT); 

pinMode(playPin, OUTPUT); 


void loop() {

  if (irrecv.decode(&results)) {

    long int decCode = results.value;


    switch (results.value) {

      case -484956645:   // change this number to whatever results you are getting for the button pressed


        digitalWrite(powerPin, HIGH);   // sets the LED on

        delay(1000); // one second delay

        digitalWrite(powerPin, LOW);   // sets the LED off


     case 1386468383:  // change this number to whatever results you are getting for the button pressed


        digitalWrite(playPin, HIGH);   // sets the LED on

        delay(1000); // one second delay

        digitalWrite(playPin, LOW);   // sets the LED off


        Serial.println("Waiting ...");


    irrecv.resume(); // Receive the next value



Now that the Receiver and Remote are working to control something, I can continue with the project.

End Phase 3 Part 1