Subscribe to Arduino Academy and start learning today for FREE!

Arduino IR Receiver – Part 2

I have been successful in programming my Arduino to identify sets of digits transmitted from my Samsung remote. I used the excellent library at http://www.arcfn.com/2009/08/multi-protocol-infrared-remote-library.html as a starting point. I stripped out everything that wasn’t a raw number, and started logging what numbers came across the serial monitor as I pressed buttons.

I then created a Switch/Case statement that turns on (and off) particular LED’s when the appropriate button on the remote is pressed.

Not sure what sensor was in my VCR, but a TSOP4838 should work as well.

Become the Maker you were born to be. Try Arduino Academy for FREE!

This can now be easily used to control motors, lights and other equipment (optically isolated SSR). I’ve uploaded a video to youtube showing how it all works.

Code and schematics are available at https://docs.google.com/folder/d/0ByRIq5k2wjcSd2FWa3FfQzBib1k/edit

As always comments here and detailed discussion at https://groups.yahoo.com/neo/groups/arduinohome/info is encouraged.

We are reading:
Arduino Robotics, by John-David Warren, Josh Adams, & Harald Molle

/*
* IRremote: IRrecvDump – dump details of IR codes with IRrecv
* An IR detector/demodulator must be connected to the input RECV_PIN.
* Version 0.1 July, 2009
* Copyright 2009 Ken Shirriff
* http://arcfn.com
* JVC and Panasonic protocol added by Kristian Lauszus (Thanks to zenwheel and other people at the original blog post)
* Heavily modified by Steve Spence, http://arduinotronics.blogspot.com
*/

#include <IRremote.h>

int RECV_PIN = 19;

int reversePin = 4;                 // LED connected to digital pin 13
int forwardPin = 5;                 // LED connected to digital pin 13
int playPin = 6;                 // LED connected to digital pin 13
int pausePin = 7;                 // LED connected to digital pin 13

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
pinMode(reversePin, OUTPUT);      // sets the digital pin as output
pinMode(forwardPin, OUTPUT);      // sets the digital pin as output
pinMode(playPin, OUTPUT);      // sets the digital pin as output
pinMode(pausePin, OUTPUT);      // sets the digital pin as output
}

void loop() {
if (irrecv.decode(&results)) {

long int decCode = results.value;
Serial.println(decCode);
switch (results.value) {
case 1431986946:
Serial.println(“Forward”);
digitalWrite(forwardPin, HIGH);   // sets the LED on
break;
case -11780576:
Serial.println(“Reverse”);
digitalWrite(reversePin, HIGH);   // sets the LED on
break;
case -873913272:
Serial.println(“Play”);
digitalWrite(playPin, HIGH);   // sets the LED on
break;
case -1025287420:
Serial.println(“Pause”);
digitalWrite(pausePin, HIGH);   // sets the LED on
break;
case 1791365666:
Serial.println(“Stop”);
digitalWrite(forwardPin, LOW);   // sets the LED off
digitalWrite(reversePin, LOW);   // sets the LED off
digitalWrite(playPin, LOW);   // sets the LED off
digitalWrite(pausePin, LOW);   // sets the LED off
break;
default:
Serial.println(“Waiting …”);
}

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

Become the Maker you were born to be. Try Arduino Academy for FREE!

 

Subscribe
Notify of
guest
14 Comments
Inline Feedbacks
View all comments
Michal Dymel
9 years ago

Nice one, I used this library to control a rgb led strip and set its color with my remote.

kenny vanpaemel
9 years ago

I used this library too to control some led's and a fan! really like it's simplicity!

Jonathan Athey
9 years ago

I am a member of my high school FRC robotics team, and i was able to use this to create a testing platform to test our hardware with. I used relays going to motors. With some minor changes it worked like a charm! Thanks so much!!

Nick Temmerman
9 years ago

Hey, I have a question. For a project on my school I need the IR code of the power button from the remote samsung AK59-00104K (Blue-ray remote controller). We are making a remote with ardiuno uno and with an infrared LED. I searched a lot on the internet but no databases founded yet. Could you help me, please?

Steve Spence
9 years ago

If you run this script, you'll see the code being sent.

Juan Carlos Rivera
9 years ago

Hi!

I'm kinda new to the hardware scene. I programmed a few micros in college but that's about it. I will be using your post to control (turn off/on) my air conditioner with an android application. First I'll have to decode my AC IR codes and then program the arduino to send them.

I was wondering if this could work with an arduino UNO board because I was checking your documents and in the wiring diagram you say you used pin 19 (RX1) from your Arduino 2560 board but I dont see Arduino UNO schematic and I don't see any pin named like that. This will be my first hardware project so I wish to save some bucks in case I screw up/doesnt work.

Thanks in advance!

Steve Spence
9 years ago

The 2560 has 4 uarts, 0-3. The Uno has 1. You would use pin 0 (RX0).

Juan Carlos Rivera
9 years ago

Thanks to your post now I am able to control my AC over the internet with an Arduino and Android.

I made a tutorial for those interested. Its in spanish but its pretty straigh forward. Also you can use Google translate if you need help.

Thanks!!

http://techcontostones.blogspot.com/2013/04/arduino-android-como-controlar-un-aire.html

Matt Robertson
9 years ago

If you use a remote that is supported by the library, you can use the digital pins.

You would need to delete line:

long int decCode = results.value;

And replace line:

Serial.println(decCode);

with:

Serial.println(results.value);

Then, change the "int RECV_PIN = " accordingly.

Steve Spence
9 years ago

Pin 19 is a digital pin on the 2560.

Alexander Hsieh
9 years ago

Hi, I made a program through a PIC to program a IR Diode to flash at intervals high enough to activate a TSOP 4856 which is essentially the same TSOP that you used. I was wondering if there is a way to incorporate that in your code to turn on only a single LED?

Steve Spence
9 years ago

run the discover code, see if you get a repeatable set of numbers. then add them to the case statement, and you should be good.

Alexander Hsieh
9 years ago

I'm sorry for bothering you again. But where can I find the discover code.

Steve Spence
9 years ago

It's included in the sketch and displayed in this post, just watch the serial monitor while pushing buttons.

Archives

14
0
Would love your thoughts, please comment.x
()
x