EEVblog #506 - IR Remote Control Arduino Protocol Tutorial - Page 1
Forum section: electronics / general

author: EEVblog
author_rank: Unknown
timestamp: August 11, 2013, 09:44:17 pm
content: 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

author: HardBoot
author_rank: Regular Contributor
timestamp: August 11, 2013, 11:15:43 pm
content: Hmm it's simpler than I thought it'd be, I'll have to try that.

author: JoannaK
author_rank: Frequent Contributor
timestamp: August 11, 2013, 11:20:43 pm
content: 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.

author: EEVblog
author_rank: Unknown
timestamp: August 11, 2013, 11:25:42 pm
content: Quote from: JoannaK on August 11, 2013, 11:20:43 pmThen the code isn't as portable, nor usable in chips that don't have PWM, nor as easily understandable for beginners.

author: notsob
author_rank: Frequent Contributor
timestamp: August 12, 2013, 12:43:10 am
content: Just to add a bit of info for those interested, here's a quick pointer on RC5 and NEC data formatshttp://www.vishay.com/docs/80071/dataform.pdf

author: crisr
author_rank: Contributor
timestamp: August 12, 2013, 12:42:00 pm
content: 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.

author: EEVblog
author_rank: Unknown
timestamp: August 12, 2013, 12:54:48 pm
content: Quote from: crisr on August 12, 2013, 12:42:00 pmHardware PWM would be better.

author: casper.bang
author_rank: Frequent Contributor
timestamp: August 12, 2013, 01:32:20 pm
content: 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.

author: firewalker
author_rank: Super Contributor
timestamp: August 12, 2013, 02:22:22 pm
content: Two nice Ir AVR projects.IRMP.IRSND.Alexander.

author: ddavidebor
author_rank: Super Contributor
timestamp: August 12, 2013, 02:55:35 pm
content: There is also a tweet library but it need wifi shield

author: lgbeno
author_rank: Frequent Contributor
timestamp: August 12, 2013, 06:02:35 pm
content: Dave, why didn't you just open up the remote and hack the button to simulate a real button press... Maybe use an optoSorry, couldn't resist. Please do not take this post seriously...Great video!Sent from my iPhone using Tapatalk 2

author: crisr
author_rank: Contributor
timestamp: August 12, 2013, 07:18:48 pm
content: Quote from: EEVblog on August 12, 2013, 12:54:48 pmYes, 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.

author: casper.bang
author_rank: Frequent Contributor
timestamp: August 12, 2013, 07:59:44 pm
content: QuoteEven the tiniest AVR's have hardware PWM's as well as interupts.

author: jnissen
author_rank: Regular Contributor
timestamp: August 12, 2013, 09:08:56 pm
content: Bravo! You did it right this time!

author: squeakbat
author_rank: Newbie
timestamp: August 12, 2013, 10:54:52 pm
content: 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.)

author: JoannaK
author_rank: Frequent Contributor
timestamp: August 13, 2013, 12:32:37 am
content: Quote from: EEVblog on August 11, 2013, 11:25:42 pmAnd 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.Ah well.. we allays have 555.s ..

author: IanJ
author_rank: Unknown
timestamp: August 13, 2013, 06:10:10 am
content: 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.htmlContains detailed explanation & usage.Ian.

author: westfw
author_rank: Super Contributor
timestamp: August 13, 2013, 06:26:44 am
content: QuoteWell, 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...

author: squeakbat
author_rank: Newbie
timestamp: August 13, 2013, 07:25:09 am
content: Quote from: westfw on August 13, 2013, 06:26:44 amI 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.

author: JoannaK
author_rank: Frequent Contributor
timestamp: August 13, 2013, 08:27:49 am
content: Quote from: westfw on August 13, 2013, 06:26:44 amI 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.QuoteOk, so it's hackable for those who can and want to. And it's really difficult to blame a platform that 10€ price point.

author: sagdahl
author_rank: Contributor
timestamp: August 13, 2013, 03:38:13 pm
content: Brilliant video again.You are the champ!

author: mjkuwp
author_rank: Unknown
timestamp: August 14, 2013, 02:30:25 am
content: 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 frequencytotally disabled Timer1so 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.

author: Stonent
author_rank: Super Contributor
timestamp: August 14, 2013, 07:39:39 am
content: Quote from: JoannaK on August 13, 2013, 08:27:49 amIt'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.

author: jnissen
author_rank: Regular Contributor
timestamp: August 14, 2013, 06:29:50 pm
content: Quote from: JoannaK on August 13, 2013, 08:27:49 amI 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!

author: David_AVD
author_rank: Super Contributor
timestamp: August 14, 2013, 10:28:27 pm
content: 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.

author: open loop
author_rank: Regular Contributor
timestamp: August 15, 2013, 06:30:43 pm
content: 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.

author: Legit-Design
author_rank: Frequent Contributor
timestamp: August 15, 2013, 06:56:27 pm
content: Quote from: open loop on August 15, 2013, 06:30:43 pmThis 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?

author: open loop
author_rank: Regular Contributor
timestamp: August 15, 2013, 09:32:45 pm
content: 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.

author: Legit-Design
author_rank: Frequent Contributor
timestamp: August 15, 2013, 09:42:35 pm
content: Quote from: open loop on August 15, 2013, 09:32:45 pmhttp://www.instructables.com/id/See-Infrared-LED-Light-with-an-iPhone-4/?ALLSTEPSUse the front facepalm camera on your iDevices. I understand you like to use the simple iDevices, but occasionally you have to press a button.

author: HeyTom
author_rank: Contributor
timestamp: August 16, 2013, 02:03:44 pm
content: Quote from: EEVblog on August 12, 2013, 12:54:48 pmFor hardware PWM, I have a Pic PWM Calculator you might find handy athttp://micro.alleypress.org/It also works in a browser on a smart phone.It let's you find stuff likemin/max frequenciesperiods and "On Times"how many bits of resolutionnumber of stepsI'm open to any feedback to make it better-Tom

author: Unknown
author_rank: Unknown
timestamp: August 18, 2013, 02:15:19 am
content: 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 oneFairchild app notehttp://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.pdfGR

author: westfw
author_rank: Super Contributor
timestamp: August 18, 2013, 07:45:51 am
content: QuoteIt *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...)

author: mrwildbob
author_rank: Newbie
timestamp: June 28, 2015, 09:37:42 pm
content: 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

author: ftonello
author_rank: Contributor
timestamp: February 28, 2016, 08:05:55 pm
content: 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