Author Topic: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial  (Read 24502 times)

0 Members and 1 Guest are viewing this topic.

Offline EEVblog

  • Administrator
  • *****
  • Posts: 31386
  • Country: au
    • EEVblog
EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« on: August 11, 2013, 09:44:17 pm »
How to capture and reverse engineer an infrared IR code and use an Arduino or other microcontroller to replay the command.
Oscilloscope and logic analyser capture, coding, troubleshooting, tounge angle, it's all here.
In this instance Dave capture the NEC (Japanese) code from his Canon video camera remote control on the digital oscilloscope, figures out all the bits and encoding, and writes an Arduino library to replay the code back, and verifies it with his Saleae Logic logic analyser.

CODE: http://gist.github.com/EEVblog/6206934

! Private video
« Last Edit: August 11, 2013, 09:50:29 pm by EEVblog »
 

Offline HardBoot

  • Regular Contributor
  • *
  • Posts: 161
  • Country: ca
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #1 on: August 11, 2013, 11:15:43 pm »
Hmm it's simpler than I thought it'd be, I'll have to try that.
 

Offline JoannaK

  • Frequent Contributor
  • **
  • Posts: 337
  • Country: fi
    • Diytao making blog
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #2 on: August 11, 2013, 11:20:43 pm »
IR communication (Irda and remote control) protocols are indeed quite easy. One of the messy detail is the lack of standards among manufacturers so one may need send 10's of different codes just to turn various televisions off.

Dave: For timing, IMHO it would be more reliable and elegant to use In-chip PWM for making the 38Khz carrier frequency. I'm not sure how many lines of code it's needed for setting it up, but it should not be too hard.
 

Offline EEVblog

  • Administrator
  • *****
  • Posts: 31386
  • Country: au
    • EEVblog
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #3 on: August 11, 2013, 11:25:42 pm »
Dave: For timing, IMHO it would be more reliable and elegant to use In-chip PWM for making the 38Khz carrier frequency. I'm not sure how many lines of code it's needed for setting it up, but it should not be too hard.

Then the code isn't as portable, nor usable in chips that don't have PWM, nor as easily understandable for beginners.
 

Offline notsob

  • Frequent Contributor
  • **
  • Posts: 648
  • Country: au
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #4 on: August 12, 2013, 12:43:10 am »
Just to add a bit of info for those interested, here's a quick pointer  on RC5 and NEC data formats

http://www.vishay.com/docs/80071/dataform.pdf
 

Offline crisr

  • Contributor
  • Posts: 45
  • Country: br
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #5 on: August 12, 2013, 12:42:00 pm »
Now, that's a better approach!  :-+

Just one note: I know the code is an example, but for time-sensitive stuff, such as 38KHz carrier, and even the bits themselves, I always try to use timer interrupts, since in C it's a little bit hard to know exactly how long an instruction / function call will take, and you generally have to account for loop overhead as well. Another advantage (or the main one) of using interrupts is that your main code can continue doing other things while the ISR takes care of IR transmission.

Here's the best resource on IR protocol info: http://www.sbprojects.com/knowledge/ir/ -- check the specific protocols on the left-hand menu.
 

Offline EEVblog

  • Administrator
  • *****
  • Posts: 31386
  • Country: au
    • EEVblog
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #6 on: August 12, 2013, 12:54:48 pm »
Just one note: I know the code is an example, but for time-sensitive stuff, such as 38KHz carrier, and even the bits themselves, I always try to use timer interrupts

Hardware PWM would be better.
 

Offline casper.bang

  • Frequent Contributor
  • **
  • Posts: 311
  • Country: dk
  • Pro SE, amateur EE.
    • BangBits
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #7 on: August 12, 2013, 01:32:20 pm »
Nice practical demonstration of DS20XX in action. I wonder how much data you are actually capable of capturing with this 14Mpts beast?! This is the sort of thing that has me looking beyond the entry level scopes.
 

Offline firewalker

  • Super Contributor
  • ***
  • Posts: 2368
  • Country: gr
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #8 on: August 12, 2013, 02:22:22 pm »
Two nice Ir AVR projects.

IRMP.
IRSND.

Alexander.
Become a realist, stay a dreamer.

 

Offline ddavidebor

  • Super Contributor
  • ***
  • Posts: 1166
  • Country: gb
    • Fermium
EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #9 on: August 12, 2013, 02:55:35 pm »
There is also a tweet library but it need wifi shield
Davide Bortolami,
Fermium LTD
 

Offline lgbeno

  • Frequent Contributor
  • **
  • Posts: 349
  • Country: 00
EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #10 on: August 12, 2013, 06:02:35 pm »
Dave, why didn't you just open up the remote and hack the button to simulate a real button press...  Maybe use an opto :)

Sorry, couldn't resist.  Please do not take this post seriously...

Great video!




Sent from my iPhone using Tapatalk 2
 

Offline crisr

  • Contributor
  • Posts: 45
  • Country: br
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #11 on: August 12, 2013, 07:18:48 pm »
Hardware PWM would be better.

Yes, but as you said yourself, not every chip has hardware PWM, such as PIC 12F series which I normally use for such applications. But AFAIK, most common MCUs these days do have interrupts (PIC10F series being an exception; don't know about AVRs as I am not familiar with them). Code portability might still be an issue, but I think the concept would be fairly similar even between different architectures.
 

Offline casper.bang

  • Frequent Contributor
  • **
  • Posts: 311
  • Country: dk
  • Pro SE, amateur EE.
    • BangBits
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #12 on: August 12, 2013, 07:59:44 pm »
Quote
PIC10F series being an exception; don't know about AVRs as I am not familiar with them

Even the tiniest AVR's have hardware PWM's as well as interupts.
 

Offline jnissen

  • Regular Contributor
  • *
  • Posts: 62
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #13 on: August 12, 2013, 09:08:56 pm »
Bravo! You did it right this time!  ;)
 

Offline squeakbat

  • Newbie
  • Posts: 4
  • Country: us
  • Hacking by echolocation
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #14 on: August 12, 2013, 10:54:52 pm »
For the scoped challenged (like me), a PC microphone jack works great for reverse engineering IR protocol.  It even has power (5V through a 200-ohm resister, I think) to drive the IR transistor.  To see the signal, use any audio recorder that lets you zoom in on the waveform (like Audacity).

When I did my Arduino-driven IR remote, I used one timer to generate the carrier, which is fed to another timer to generate interrupts at the pulse period.  The Arduino library doesn't support any of this, of course, and the code was super messy in the end.  (Timer 0 is used for timing by the library internally, and repurposing it messes up calls like delay().)  So, Dave's way is great as long as it works.  (My code had to do other things in the mean time so couldn't block sending the IR sequence.)
— Ellen
 

Offline JoannaK

  • Frequent Contributor
  • **
  • Posts: 337
  • Country: fi
    • Diytao making blog
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #15 on: August 13, 2013, 12:32:37 am »
Dave: For timing, IMHO it would be more reliable and elegant to use In-chip PWM for making the 38Khz carrier frequency. I'm not sure how many lines of code it's needed for setting it up, but it should not be too hard.

Then the code isn't as portable, nor usable in chips that don't have PWM, nor as easily understandable for beginners.

And apparently it would not be possible to implement with basic Arduino without some 3rd party libhraries. Apparently there are no easy way to set PWM speed for analog outputs, and the alternative (tone command) does not have options for setting the the frequency (38KHz) high enough for carrier.  :palm:

Ah well.. we allays have 555.s ..  >:D
 

Offline IanJ

  • Supporter
  • ****
  • Posts: 1077
  • Country: scotland
  • Pro EE guy many years ago, now a hobby/home biz.
    • IanJohnston.com
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #16 on: August 13, 2013, 06:10:10 am »
Hi all,

Related.........For anyone wanting to Rx/Tx IR on the Arduino and using multiple protocols (NEC, Sony, RC5, RC6), I used Ken Shirrif's IR code library on one of my own projects.

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

Contains detailed explanation & usage.

Ian.

Ian Johnston
www.ianjohnston.com
Manufacturer of the PDVS2 & PDVS2mini
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 3196
  • Country: us
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #17 on: August 13, 2013, 06:26:44 am »
Quote
it would not be possible to implement with basic Arduino without some 3rd party libhraries.
Well, you could read the avr datasheet and set the timers up yourself; you don't always have to have a library do something for you...

There are plenty of things that could be changed in the software, and it's tempting to "improve" it.  But instead, I think I'll comment that I thought this was a great example of how capable the arduino environment IS.  An application that is pretty much "on the edge" of the capabilities; you can't assume that library functions take "zero time", but there is plenty of speed available...
 

Offline squeakbat

  • Newbie
  • Posts: 4
  • Country: us
  • Hacking by echolocation
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #18 on: August 13, 2013, 07:25:09 am »
Well, you could read the avr datasheet and set the timers up yourself; you don't always have to have a library do something for you...

There are plenty of things that could be changed in the software, and it's tempting to "improve" it.  But instead, I think I'll comment that I thought this was a great example of how capable the arduino environment IS.  An application that is pretty much "on the edge" of the capabilities; you can't assume that library functions take "zero time", but there is plenty of speed available...

I totally agree that the tutorial is at just the right level.

About programming the hardware directly, that's at little harder than just reading the datasheet because certain things interact badly with the library.  For example, timer 0 is used for internal time keeping, so it can't be reprogrammed to generate the IR carrier (or not easily anyway).  And you wouldn't know this without reading the source.

I'm not at all criticizing the Arduino.  It's not meant for programming the AVR from scratch.  At the same time, the source is freely available and not too hard to read and modify.  So it's a reasonable compromise: fairly easy to use without locking out low-level features.

The same goes for the hardware.  It works out of the box, and is at the same time easily hackable:  schematics are available, and the two-layer board is easy to modify.
— Ellen
 

Offline JoannaK

  • Frequent Contributor
  • **
  • Posts: 337
  • Country: fi
    • Diytao making blog
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #19 on: August 13, 2013, 08:27:49 am »
Quote
it would not be possible to implement with basic Arduino without some 3rd party libhraries.
Well, you could read the avr datasheet and set the timers up yourself; you don't always have to have a library do something for you...

I have never used Arduinos myself (started coding on C64 era, with HC11 were first embedded), so it's not (yet) 100% clear to me how much the user is allowed to mess outside of the official sandbox.

Quote
There are plenty of things that could be changed in the software, and it's tempting to "improve" it.  But instead, I think I'll comment that I thought this was a great example of how capable the arduino environment IS.  An application that is pretty much "on the edge" of the capabilities; you can't assume that library functions take "zero time", but there is plenty of speed available...

Ok, so it's hackable for those who can and want to. And it's really difficult to blame a platform that 10€ price point.

 

Offline sagdahl

  • Contributor
  • Posts: 26
  • Country: se
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #20 on: August 13, 2013, 03:38:13 pm »
Brilliant video again.
You are the champ!
That, that is, is. That, that is not, is not. Is that it? It is!
 

Offline mjkuwp

  • Supporter
  • ****
  • Posts: 223
  • Country: us
  • mechanical engineering defector
    • The Mz Lab
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #21 on: August 14, 2013, 02:30:25 am »
I like the video!

 I made an IR repeater using Arduino except that I set up and used the timers my own way.  The Arduino environment will not stop you doing things your own way; one just has to understand that some functions will break.  I looked at Ken Shirriff's stuff closely but did my own thing mainly for the sake of learning.

I used Timer0 for timing slow functions - such as holding a pin low for 4 seconds to reboot my PC.
I used Timer 2 in PWM mode to create the 38khz carrier frequency

totally disabled Timer1

so delay() probably doesn't work and millis() doesn't work.  I don't like those Arduino functions anyway so I don't mind those breaking.


 

Offline Stonent

  • Super Contributor
  • ***
  • Posts: 3824
  • Country: us
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #22 on: August 14, 2013, 07:39:39 am »
Quote
it would not be possible to implement with basic Arduino without some 3rd party libhraries.
Well, you could read the avr datasheet and set the timers up yourself; you don't always have to have a library do something for you...

I have never used Arduinos myself (started coding on C64 era, with HC11 were first embedded), so it's not (yet) 100% clear to me how much the user is allowed to mess outside of the official sandbox.

Quote
There are plenty of things that could be changed in the software, and it's tempting to "improve" it.  But instead, I think I'll comment that I thought this was a great example of how capable the arduino environment IS.  An application that is pretty much "on the edge" of the capabilities; you can't assume that library functions take "zero time", but there is plenty of speed available...

Ok, so it's hackable for those who can and want to. And it's really difficult to blame a platform that 10€ price point.

It's still basically C++ but there are standard things that the Arduino software includes that shield you from having to do a lot of the setup routines. It also assumes you're running the chip at 16MHz so there's no issues there.

Also you can still program the AVR chip using Atmel Studio but you have to make sure your code matches your clock speed otherwise things will not run at the right speed.

I haven't written anything too complex yet but I did successfully convert one Arduino sketch to standard C in Atmel Studio. The first time it ran too slow but I realized I had the clock set wrong, just another 10 seconds and a recompile and everything was great.
The larger the government, the smaller the citizen.
 

Offline jnissen

  • Regular Contributor
  • *
  • Posts: 62
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #23 on: August 14, 2013, 06:29:50 pm »

I have never used Arduinos myself (started coding on C64 era, with HC11 were first embedded), so it's not (yet) 100% clear to me how much the user is allowed to mess outside of the official sandbox.


I was in the same boat a few years ago and just picked one up. Amazed at how easy the platform was. I was used to old school assembler and getting your hands dirty with code and hardware. I still do that from time to time as needed. The tools support a huge amount of shared knowledge with the various libraries and code examples. My son actually turned me onto the Arduino after I gave him about 1% chance of being successful designing an LCD enabled tachometer. He got his proto working in two days! Made a believer of me!
 

Offline David_AVD

  • Super Contributor
  • ***
  • Posts: 2607
  • Country: au
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #24 on: August 14, 2013, 10:28:27 pm »
I've used the Arduino boards as a project proof of concept.  I'd probably not use one in a sold product, but they are perfectly fine for R&D.
 

Offline open loop

  • Regular Contributor
  • *
  • Posts: 52
  • Country: gb
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #25 on: August 15, 2013, 06:30:43 pm »
Excellent video and came at the pefect time.

I was messing about with an IR based project where I wanted to time 100 IR beam breaks. The LEDs arrived in the post but not the photo transistor. So I thought, "I know... I tore down an old sky HD box a while ago for the HDD I'll use that IR receiver". Worked out the connections but it didn't work with anything except the stero remote checked the LED with my phone camera and it worked!

What was happening? - now I know my LED did not generate the required 38kHz carrier! .... As David says "I hope your project doesn't work"!. I have noticed that newer phone cameras now have an IR filter so you can't see the IR LEDs working anymore.




 

Offline Legit-Design

  • Frequent Contributor
  • **
  • Posts: 562
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #26 on: August 15, 2013, 06:56:27 pm »
I have noticed that newer phone cameras now have an IR filter so you can't see the IR LEDs working anymore.
This smells like bullshit.
All digital cameras still have IR cut filter, it just doesn't block IR remote signals too well. I find it more plausible that your project isn't sending IR signals, than they have included ir cut filters that completely cut all IR, even remote signals. What phone are you using?
 

Offline open loop

  • Regular Contributor
  • *
  • Posts: 52
  • Country: gb
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #27 on: August 15, 2013, 09:32:45 pm »
I do agree with you that digital cameras have an IR and that the average remote would be seen due to it not blocking these particularly well.

I often used my iPhone 3GS to test remotes to see if the problem was with the remote or the appliance. When our cable box played up I tried this trick on my wife's iPhone 4S and my iPad 3 and I could not see the tell tale flashing you normally see so there must be something going on with the newer cameras, why I am not sure...

The reason my project did not work was because I was trying to use a constantly lit IR LED with a IR receiver not a photo transistor. Which Dave's video explained perfectly.



 

Offline Legit-Design

  • Frequent Contributor
  • **
  • Posts: 562
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #28 on: August 15, 2013, 09:42:35 pm »
I do agree with you that digital cameras have an IR and that the average remote would be seen due to it not blocking these particularly well.

I often used my iPhone 3GS to test remotes to see if the problem was with the remote or the appliance. When our cable box played up I tried this trick on my wife's iPhone 4S and my iPad 3 and I could not see the tell tale flashing you normally see so there must be something going on with the newer cameras, why I am not sure...

The reason my project did not work was because I was trying to use a constantly lit IR LED with a IR receiver not a photo transistor. Which Dave's video explained perfectly.

http://www.instructables.com/id/See-Infrared-LED-Light-with-an-iPhone-4/?ALLSTEPS
Use the front facepalm camera on your iDevices. I understand you like to use the simple iDevices, but occasionally you have to press a button.  :-/O
 

Offline HeyTom

  • Contributor
  • Posts: 17
  • Country: us
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #29 on: August 16, 2013, 02:03:44 pm »
Hardware PWM would be better.

For hardware PWM, I have a Pic PWM Calculator you might find handy at http://micro.alleypress.org/  It also works in a browser on a smart phone.

It let's you find stuff like
  • min/max frequencies
  • periods and "On Times"
  • how many bits of resolution
  • number of steps


I'm open to any feedback to make it better
-Tom
 

GalvanicResonse

  • Guest
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #30 on: August 18, 2013, 02:15:19 am »
Re: IR receiver and phototransistor examination of carrier and stripped carrier :
"Traps For Young Players" file.

Hi - I am new to the blog and forum.
The video was very informative. I don't have the fancy pants equipment but I wanted to view the output of some of the remotes around the house on an analog scope. I scrounged up a photo tranny and an IR receiver from the junk box. This note is just to add to the "TFYP" file on this aspect of the subject.

There are two things that I bumped into while trying this out.

1) IR receivers - I was unaware of what these things do, so the video encouraged me to try one out. The trap here is that the pin-outs are not uniform across manufacturers. I had a few that had been removed from consumer gear but they have no part number to look up. My solution was to remove another one that was still in place on some junk board, but paying attention to the circuit traces as to which ones are the likely suspects ( example, an electro cap across two pins was good evidence that I had Vcc and ground). So my advice to a beginner on this is to pay attention when you remove it and store it away with a bit of documentation.

2) Detecting the carrier. My first circuit for this was a simple grounded emitter ( Vcc - 2k2 - photo-t collector , photo-t emitter grounded). This detected IR from a remote but I didn't see a carrier. I then tried 4 other remotes - same results. The output looked about the same as that from the IR recevier. I thought that I was unlucky and none of my remotes used modulation. But unlucky 5 times ?? I cranked up the volts/div on the scope and could see tiny sawtooth waves on the low going parts of the signal. I started to wonder if the lone photo-t was not fast enough to follow 38 khz. I googled 'phototransistor circuits' and got a few hits that were real app notes. When I built the circuit in the Sharp app note ( figure 11a ) the response was fast enough that I could see ( and measure the period of ) the  carrier (36 k in 5 out of 5) .   That made for a fun evening. Thanks. 

If the URLs don't work, google
 
'Photodiode/Phototransistor Application Circuit' for the Sharp app note and
'application note an-3005 design fundamentals' for the Fairchild one

Fairchild app note

http://www.fairchildsemi.com/an/AN/AN-3005.pdf?

Sharp app note ( this had the solution that I needed )

http://physlab.lums.edu.pk/images/1/10/Photodiode_circuit.pdf

GR
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 3196
  • Country: us
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #31 on: August 18, 2013, 07:45:51 am »
Quote
it's not (yet) 100% clear to me how much the user is allowed to mess outside of the official sandbox.
It *is* a microcontroller with no "protection."  "Arduino" is little more than an IDE, some initialization code, and some libraries.  Anything is "allowed"; you can reinitialize all the peripherals, ignore the libraries, and write code in assembler if you want.  (of course, once you start re-programming the peripherals, all bets are off WRT the official libraries continuing to work...)
 

Offline mrwildbob

  • Newbie
  • Posts: 3
  • Country: us
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #32 on: June 28, 2015, 09:37:42 pm »
Hello Everyone,  I'm slowly getting back into programming after watching Dave/EEVblog over the years.  Very inspiring.  I need a little help.  I would like to use this code for a different project but with out the 38KHz carrier frequency.  I've tried editing the code to work with my application but can not seem to get the desired results.  Can someone help me with this?  I just need to send out a 550 byte code out pin 2.  thanks
-boB
 

Offline ftonello

  • Contributor
  • Posts: 37
  • Country: br
    • FTTENG
Re: EEVblog #506 - IR Remote Control Arduino Protocol Tutorial
« Reply #33 on: February 28, 2016, 08:05:55 pm »
Doing some tests here....Now i understand what Dave said about capturing these waveforms in a 2.5K oscilloscope (a TBS 1072B-EDU).
Do the job,but with small resollution and losing some carrier freq.





Any ideas to improve the signal capturing?

Capturing the data from a Samsung DVD remote controler, with a ZILOG Crimzon  ZLR2802GR54WL controller on board.





Att
« Last Edit: February 28, 2016, 08:07:32 pm by ftonello »
Hi from Brazil!!!
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf