Clone a Remote With Arduino

126K54925

Intro: Clone a Remote With Arduino

I recently needed to use the Arduino to control a stereo system, so rather than hack open the remote and wire into it, I decided to simply clone the signal. This was incredibly easy to do. Basically, I read the signal from the remote with a 38khz receiver, and then played it back with an IR LED.

To start, I went to the IR Sensor Tutorial on Adafruit.com and loaded the following script onto my Arduino:
/* Raw IR decoder sketch!
 
 This sketch/program uses the Arduno and a PNA4602 to 
 decode IR received. This can be used to make a IR receiver
 (by looking for a particular code)
 or transmitter (by pulsing an IR LED at ~38KHz for the
 durations detected 
 
 Code is public domain, check out www.ladyada.net and adafruit.com
 for more tutorials! 
 */
 
// We need to use the 'raw' pin reading methods
// because timing is very important here and the digitalRead()
// procedure is slower!
//uint8_t IRpin = 2;
// Digital pin #2 is the same as Pin D2 see
// http://arduino.cc/en/Hacking/PinMapping168 for the 'raw' pin mapping
#define IRpin_PIN      PIND
#define IRpin          2
 
// the maximum pulse we'll listen for - 65 milliseconds is a long time
#define MAXPULSE 65000
 
// what our timing resolution should be, larger is better
// as its more 'precise' - but too large and you wont get
// accurate timing
#define RESOLUTION 20 
 
// we will store up to 100 pulse pairs (this is -a lot-)
uint16_t pulses[100][2];  // pair is high and low pulse 
uint8_t currentpulse = 0; // index for pulses we're storing
 
void setup(void) {
  Serial.begin(9600);
  Serial.println("Ready to decode IR!");
}
 
void loop(void) {
  uint16_t highpulse, lowpulse;  // temporary storage timing
  highpulse = lowpulse = 0; // start out with no pulse length
 
 
//  while (digitalRead(IRpin)) { // this is too slow!
    while (IRpin_PIN & _BV(IRpin)) {
     // pin is still HIGH
 
     // count off another few microseconds
     highpulse++;
     delayMicroseconds(RESOLUTION);
 
     // If the pulse is too long, we 'timed out' - either nothing
     // was received or the code is finished, so print what
     // we've grabbed so far, and then reset
     if ((highpulse >= MAXPULSE) && (currentpulse != 0)) {
       printpulses();
       currentpulse=0;
       return;
     }
  }
  // we didn't time out so lets stash the reading
  pulses[currentpulse][0] = highpulse;
 
  // same as above
  while (! (IRpin_PIN & _BV(IRpin))) {
     // pin is still LOW
     lowpulse++;
     delayMicroseconds(RESOLUTION);
     if ((lowpulse >= MAXPULSE)  && (currentpulse != 0)) {
       printpulses();
       currentpulse=0;
       return;
     }
  }
  pulses[currentpulse][1] = lowpulse;
 
  // we read one high-low pulse successfully, continue!
  currentpulse++;
}
 
void printpulses(void) {
  Serial.println("\n\r\n\rReceived: \n\rOFF \tON");
  for (uint8_t i = 0; i < currentpulse; i++) {
    Serial.print(pulses[i][0] * RESOLUTION, DEC);
    Serial.print(" usec, ");
    Serial.print(pulses[i][1] * RESOLUTION, DEC);
    Serial.println(" usec");
  }
}

24 Comments

The next "Instructable" with the topic: How to destroy electronic parts!

NEVER use LED's or even IR-LED's WITHOUT resistor. Yes, it will for for some time but then even IR-diode or the board is damaged.

pin 13 of arduino board have a integrated resistance in serie with the onboard led

...and is the IR LED connected to Pin 13?

No.

And the arduino won't give enough power for reasonable driving a IR LED. The range with 10-20mA is about one meter. Better doing a circuit with an 2N2222 NPN.

I would like to at least see a parts list since I don't have access to the PDF . Thanks

First instructable I've seen where you HAVE to download the PDF to get the full instructable - because I can't see anything beyond the first page here.

Do you need a resistor to go to the IR led?
Maybe. Not sure the specs on the LED. Nonetheless, I didn't use one. I figured it was being pulsed fast enough, and for short enough periods of time, that I could get away without it. For long-term use, it would probably be ideal.
I need to clone an antiquated tramsitter for a remote overhead crane control. The touch buttons are intermittantly responding.
How can I determine the frequency of the transmitter unit ?
What options would I have for a new transmitter ?
The reciever is about 30 feet above the ground on a crane motor.
Might just need to replace the buttons due to worn or corroded contacts.
1. Fix the buttons. Sounds like the transmitter & receiver might be just fine. If not (like, they work great when close) you've got a tuning or antenna problem.

2. Look on the transmitter or receiver for an FCC type acceptance tag that should tell you what the frequency is.

3. Measure the length of the receiver antenna, multiply by 4 and that should be the wavelength of the signal. f=c/lambda, where f is in hertz, c = 3x10^8 m/sec, and lambda is wavelength in meters. E.g. 3 meters to get 100 MHz.

4. If you just have an up/down, left/right, you might be able to buy a store-bought RF or IR system that has 4 buttons. But you need a rugged one.

5. After that, you're in design & build mode.
Is it IR pulses (line-of-sight) or radio? I have no clue how to begin to clone a radio signal. That is not quite as easy.
38 megahertz? No, it's 38 kilohertz (38KHZ)!
Great instructable! I've been wanting to do this for awhile. Very timely!

Unfortunately I'm having some sort of issue. I'd love your thoughts. I was able to receive and copy the codes from my remote, but when I try to play them back to the TV nothing happens. I can see (using a camera) that my LED is transmitting (weaker than the remote, but I'm trying at a range of just an inch or so). When I look at the LED on my remote with a camera I can see that the pulse is much longer, or perhaps repeated many times. It pulse length doesn't look the same as on my LED. The TV is a newer Panasonic (about a year old). Any thoughts? I tried to repeat the code five times, but nothing. Not sure if there needs to be a pause in the code between repeats, etc....

Thanks in advance!
The intensity should not matter too much, unless it is considerably weaker.

You shouldn't be able to see the real pulses it is transmitting as it is happening extremely fast.

There usually is some garbage bits before and after the entire transmission. Make sure that you don't include those and that you are putting in a delay of microseconds. It probably will take some fussing about with numbers to get it perfect.
Nice!
Put an intro to this on my Blog:
http://faz-voce-mesmo.blogspot.pt/2012/07/papel-metal-e-instructables.html
it would be much simpler to use this great IR Remote library here:

http://www.arcfn.com/2009/08/multi-protocol-infrared-remote-library.html

it is very easy to use and i was able to start cloning my remote pretty quickly, even for a beginner like me.

i am now working on a robot controlled by an old remote and an arduino using this library.

P.S. Thanks so much for your Motor Sheild Tutorial, it helped m start making a robot in no time using the Motor sheild, and a RC car (later replaced by Tamiya Tracked Vehicle Chassis modified with erector peices) like in your RC car to robot instructable. i am now making robots with some other H-bridge chips i had laying around without a purpose, but the instructable gave me a good start. Thanks!
Sounds interesting. You should post a Photo Instructable on how you used that IR library, and then enter it into the Electronics Tips and Tricks Contest.

Glad that tutorial was useful for you!
i am actually thinking of entering in the remote control challenge and that contest too with a project using it. i am still prototyping though. Its about time i did an instructable, I have been on instructables since I was 11 and still haven't posted.
More Comments