You are on page 1of 85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

Thissiteusescookiestohelpdeliverservices.Byusingthissite,youagreetotheuseofcookies.

Learnmore

Gotit

Ken Shirriff's blog


Chargers,microprocessors,Arduino,andwhatever

AMultiProtocolInfraredRemote
LibraryfortheArduino
NoteforArduino1.0
Anupdatedversionwith1.0supportisavailableongithub.
Installationinstructionsareatthebottomofthatpage.Let
meknowifyouencounteranyproblems.
DoyouwanttocontrolyourArduinowithanIRremote?Do
youwanttouseyourArduinotocontrolyourstereoorother
devices?ThisIRremotelibraryletsyoubothsendand
receiveIRremotecodesinmultipleprotocols.Itsupports
NEC,SonySIRC,PhilipsRC5,PhilipsRC6,andrawprotocols.
Ifyouwantadditionalprotocols,theyarestraightforwardto
add.Thelibrarycanevenbeusedtorecordcodesfromyour
remoteandretransmitthem,asaminimaluniversalremote.

PopularPosts
Bitcoinminingona55
yearoldIBM1401
mainframe:80seconds
perhash
Adozen
USB
chargersin
thelab:
Appleis
verygood,butnotquite
thebest
TheTexas
Instruments
TMX1795:
thefirst,
forgotten
microprocessor
AMultiProtocolInfrared
RemoteLibraryforthe
Arduino
Mining
Bitcoinwith
penciland
paper:0.67
hashesper
day
AppleiPhonecharger
teardown:qualityinatiny
expensivepackage
iPad
charger
teardown:
inside
Apple's
chargerandarisky
phony
12minuteMandelbrot:
fractalsona50yearold
IBM1401mainframe

Labels

6502 8085 apple arc


arduino bitcoin c# calculator
Tousethelibrary,downloadfromgithubandfollowthe
installationinstructionsinthereadme.

Howtosend
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

css

electronics

f#

fractals genome haskell html5


ibm1401 ipv6 ir java javascript

math

oscilloscope

photo
1/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

Thisinfraredremotelibraryconsistsoftwoparts:IRsend
transmitsIRremotepackets,whileIRrecvreceivesand
decodesanIRmessage.IRsendusesaninfraredLED
connectedtooutputpin3.Tosendamessage,callthesend
methodforthedesiredprotocolwiththedatatosendandthe
numberofbitstosend.Theexamples/IRsendDemo
sketchprovidesasimpleexampleofhowtosendcodes:

power supply

random

reverseengineering
sheevaplug snark spanish
teardowntheory Z80

#include<IRremote.h>
IRsendirsend;
voidsetup()
{
Serial.begin(9600);
}
voidloop(){
if(Serial.read()!=1){
for(inti=0;i<3;i++){
irsend.sendSony(0xa90,12);//SonyTVpower
code
delay(100);
}
}
}
ThissketchsendsaSonyTVpoweron/offcodewhenevera
characterissenttotheserialport,allowingtheArduinototurn
theTVonoroff.(NotethatSonycodesmustbesent3times
accordingtotheprotocol.)

Howtoreceive
IRrecvusesaninfrareddetectorconnectedtoanydigitalinput
pin.
Theexamples/IRrecvDemosketchprovidesasimple
exampleofhowtoreceivecodes:

Powersupplyposts

#include<IRremote.h>

iPhonechargerteardown

intRECV_PIN=11;
IRrecvirrecv(RECV_PIN);
decode_resultsresults;

Magsafehacking

AdozenUSBchargers
InsideafakeiPhone
charger
Powersupplyhistory

voidsetup()
{
Serial.begin(9600);
irrecv.enableIRIn();//Startthereceiver
}
voidloop(){
if(irrecv.decode(&results)){
Serial.println(results.value,HEX);
irrecv.resume();//Receivethenextvalue
}
}
TheIRrecvclassperformsthedecoding,andisinitialized
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

BlogArchive
2015(5)
2014(13)
2013(24)
2012(10)
2011(11)
2010(22)
2/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

withenableIRIn().Thedecode()methodiscalledto
seeifacodehasbeenreceivedifso,itreturnsanonzero
valueandputstheresultsintothedecode_results
structure.(Fordetailsofthisstructure,seethe
examples/IRrecvDumpsketch.)Onceacodehasbeen
decoded,theresume()methodmustbecalledtoresume
receivingcodes.Notethatdecode()doesnotblockthe
sketchcanperformotheroperationswhilewaitingforacode
becausethecodesarereceivedbyaninterruptroutine.

Hardwaresetup
Thelibrarycanuseanyofthedigitalinputsignalstoreceive
theinputfroma38KHzIRreceivermodule.Ithasbeentested
withtheRadioShack276640IRreceiverandthePanasonic
PNA4602.Simplywirepowertopin1,groundtopin2,andthe
pin3outputtoanArduinodigitalinputpin,e.g.11.These
receiversprovideafilteredanddemodulatedinvertedlogic
leveloutputyoucan'tjustuseaphotodiodeor
phototransistor.Ihavefoundthesedetectorshavepretty
goodrangeandeasilyworkacrossaroom.

2009(22)
December(2)
November(5)
September(1)
August(3)
AMultiProtocol
InfraredRemote
LibraryfortheA...
Arc+Arduino+ARM:
Temperature
monitoring
World'ssmallestArc
server
July(1)
June(3)
April(1)
March(3)
February(2)
January(1)
2008(27)

ARDUINO
Compatible37in1
SensorMo...
SHANHAI
New$39.92
Best$26.47

Foroutput,connectanIRLEDandappropriateresistorto
PWMoutputpin3.MakesurethepolarityoftheLEDis
correct,oritwon'tilluminatethelongleadispositive.Iuseda
NTE3027LED(becausethat'swhatwashandy)and100
ohmresistortherangeisabout15feet.Foradditionalrange,
youcanamplifytheoutputwithatransistor.

SomebackgroundonIRcodes
AnIRremoteworksbyturningtheLEDonandoffina
particularpattern.However,topreventinteferencefromIR
sourcessuchassunlightorlights,theLEDisnotturnedon
steadily,butisturnedonandoffatamodulationfrequency
(typically36,38,or40KHz).Thetimewhenamodulated
signalisbeingsentwillbecalledamark,andwhentheLEDis
offwillbecalledaspace.
Eachkeyontheremotehasaparticularcode(typically12to
32bits)associatedwithit,andbroadcaststhiscodewhenthe
keyispressed.Ifthekeyishelddown,theremoteusually
repeatedlybroadcaststhekeycode.ForanNECremote,a
specialrepeatcodeissentasthekeyishelddown,rather
thanrepeatedlysendingthecode.ForPhilipsRC5orRC6
remotes,abitinthecodeistoggledeachtimeakeyis
pressedthereceiverusesthistogglebittodeterminewhena
keyispresseddownasecondtime.
Onthereceivingend,theIRdetectordemodulatesthissignal,
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

ArduinoUNOR3
Boardwith
ATmega328P...
Arduino
New$27.79
Best$4.47
ArduinoUno
UltimateStarterKit
...
Vilros
New$54.99
Best$54.99
TheArduino
StarterKit
Arduino.org
New$90.50
Best$86.81

IEIKUNOR3
Board
ATmega328Pwith
US...
IEIK
New$12.19
Best$12.19

PrivacyInformation

Quicklinks
ArduinoIRlibrary
3/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

andoutputsalogiclevelsignalindicatingifitisreceivinga
signalornot.TheIRdetectorwillworkbestwhenitsfrequency
matchesthesender'sfrequency,butinpracticeitdoesn't
matterawholelot.

6502reverse
engineering

ThebestsourceI'vefoundfordetailsonthevarioustypesof
IRcodesisSBIRknowledgebase.

Handlingrawcodes
Thelibraryprovidessupportforsendingandreceivingraw
durations.Thisisintendedmainlyfordebugging,butcanalso
beusedforprotocolsthelibrarydoesn'timplement,orto
provideuniversalremotefunctionality.
TherawdataforreceivedIRmeasuresthedurationof
successivespacesandmarksin50usticks.Thefirst
measurementisthegap,thespacebeforethetransmission
starts.Thelastmeasurementisthefinalmark.
TherawdataforsendingIRholdsthedurationofsuccessive
marksandspacesinmicroseconds.Thefirstvalueisthefirst
mark,andthelastvalueisthelastmark.
Therearetwodifferencesbetweentherawbuffersforsending
andforreceiving.Thesendbuffervaluesarein
microseconds,whilethereceivebuffervaluesarein50
microsecondticks.Thesendbufferstartswiththedurationof
thefirstmark,whilethereceivebufferstartswiththeduration
ofthegapspacebeforethefirstmark.Theformatsare
differentbecauseIconsidereditusefulforthelibraryto
measuregapsbetweentransmissions,butnotusefulforthe
librarytoprovidethesegapswhentransmitting.Forreceiving,
50usgranularityissufficientfordecodingandavoidsoverflow
ofthegaps,whilefortransmitting,50usgranularityismore
than10%errorso1usgranularityseemedbetter.

Obtainingcodesforyourremote
Theeasiestwaytoobtaincodestoworkwithyourdeviceisto
usethislibrarytodecodeandprintthecodesfromyour
existingremote.
Variouslibrariesofcodesareavailableonline,oftenin
proprietaryformats.TheLinuxInfraredRemoteControlproject
(LIRC),however,hasanopenformatfordescribingcodesfor
manyremotes.Notethatevenifyoucan'tfindcodesforyour
exactdevicemodel,aparticularmanufacturerwillusuallyuse
thesamecodesformultipleproducts.
Bewarethatothersourcesmaybeinconsistentinhowthey
handletheseprotocols,forinstancereversingtheorder,
flipping1and0bits,makingstartbitsexplicit,dropping
leadingortrailingbits,etc.Inotherwords,iftheIRremote
libraryyieldsdifferentcodesthanyoufindlistedelsewhere,
theseinconsistenciesareprobablywhy.

Detailsofthereceivinglibrary
TheIRrecvlibraryconsistsoftwoparts.Aninterruptroutineis
calledevery50microseconds,measuresthelengthofthe
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

4/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

marksandspaces,andsavesthedurationsinabuffer.The
usercallsadecodingroutinetodecodethebuffered
measurementsintothecodevaluethatwassent(typically11
to32bits).
Thedecodelibrarytriesdecodingdifferentprotocolsin
succession,stoppingifonesucceeds.Itreturnsastructure
thatcontainstherawdata,thedecodeddata,thenumberof
bitsinthedecodeddata,andtheprotocolusedtodecodethe
data.
Fordecoding,theMATCHmacrodetermineifthemeasured
markorspacetimeisapproximatelyequaltotheexpected
time.
TheRC5/6decodingisabitdifferentfromtheothersbecause
RC5/6encodebitswithmark+spaceorspace+mark,rather
thanbydurationsofmarksandspaces.ThegetRClevel
helpermethodsplitsupthedurationsandgetsthe
mark/spacelevelofasingletimeinterval.
Forrepeatedtransmissions(buttonhelddown),thedecoding
codewillreturnthesamedecodedvalueoverandover.The
exceptionisNEC,whichsendsaspecialrepeatcodeinstead
ofrepeatingthetransmissionofthevalue.Inthiscase,the
decoderoutinereturnsaspecialREPEATvalue.
Inmoredetail,thereceiver'sinterruptcodeiscalledevery
timetheTIMER1overflows,whichissettohappenafter50
microseconds.Ateachinterrupt,theinputstatusischecked
andthetimercounterisincremented.Theinterruptroutine
timesthedurationsofmarks(receivingamodulatedsignal)
andspaces(nosignalreceived),andrecordsthedurationsin
abuffer.Thefirstdurationisthelengthofthegapbeforethe
transmissionstarts.Thisisfollowedbyalternatingmarkand
spacemeasurements.Allmeasurementsarein"ticks"of50
microseconds.
Theinterruptroutineisimplementedasastatemachine.It
startsinSTATE_IDLE,whichwaitsforthegaptoend.Whena
markisreceived,itmovestoSTATE_MARKwhichtimesthe
durationofthemark.Itthenalternatesbetween
STATE_MARKandSTATE_SPACEtotimemarksand
spaces.Whenaspaceofsufficientlylongdurationis
received,thestatemovestoSTATE_STOP,indicatingafull
transmissionisreceived.Theinterruptroutinecontinuesto
timethegap,butblocksinthisstate.
TheSTATE_STOPisusedaaflagtoindicatetothedecode
routinethatafulltransmissionisavailable.Whenprocessing
isdone,theresume()methodsetsthestatetoSTATE_IDLE
sotheinterruptroutinecanstartrecordingthenext
transmission.Thereareafewthingstonotehere.Gaptiming
continuesduringSTATE_STOPandSTATE_IDLEsoan
accuratemeasurementofthetimebetweentransmissions
canbeobtained.Ifresume()isnotcalledbeforethenext
transmissionstarts,thepartialtransmissionwillbediscarded.
Themotivationbehindthestop/resumeistoensurethe
receivebufferisnotoverwrittenwhileitisstillbeing
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

5/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

processeddebuggingbecomesverydifficultifthebufferis
constantlychanging.

Detailsofthesendinglibrary
Thetransmissioncodeisstraightforward.Toensureaccurate
outputfrequenciesanddutycycles,IusethePWMtimer,
ratherthandelayloopstomodulatetheoutputLEDatthe
appropriatefrequency.(SeemyArduinoPWMSecretsarticle
formoredetailsonthePWMtimers.)Atthelowlevel,
enableIROutsetsupthetimerforPWMoutputonpin3atthe
properfrequency.Themark()methodsendsamarkby
enablingPWMoutputanddelayingthespecifiedtime.The
space()methodsendsaspacebydisablingPWMoutputand
delayingthespecifiedtime.
TheIRremotelibrarytreatsthedifferentprotocolsasfollows:
NEC:32bitsaretransmitted,mostsignificantbitfirst.(protocol
details)
Sony:12ormorebitsaretransmitted,mostsignificantbitfirst.
Typically12or20bitsareused.Notethattheofficialprotocol
isleastsignificantbitfirst.(protocoldetails)Formoredetails,
I'vewrittenanarticlethatdescribestheSonyprotocolinmuch
moredetail:UnderstandingSonyIRremotecodes.
RC5:12ormorebitsaretransmittedmostsignificantbitfirst.
Themessagestartswiththetwostartbits,whicharenotpart
ofthecodevalues.(protocoldetails)
RC6:20(typically)bitsaretransmitted,mostsignificantbitfirst.
Themessagestartswithaleaderpulse,andastartbit,which
isnotpartofthecodevalues.Thefourthbitistransmitted
doublewide,sinceitisthetrailerbit.(protocoldetails)
ForSonyandRC5/6,eachtransmissionmustberepeated3
timesasspecifiedintheprotocol.Thetransmissioncode
doesnotimplementtheRC5/6togglebitthatisuptothe
caller.

Addingnewprotocols
Manufacturershaveimplementedmanymoreprotocolsthan
thislibrarysupports.Addingnewprotocolsshouldbe
straightforwardifyoulookattheexistinglibrarycode.Afew
tips:Itwillbeeasiertoworkwithadescriptionoftheprotocol
ratherthantryingtoentirelyreverseengineertheprotocol.
Thedurationsyoureceivearelikelytobelongerformarks
andshorterforspacesthantheprotocolsuggests.It'seasyto
beoffbyonewiththelastbitthelastspacemaybeimplicit.

Troubleshooting
TomakeiteasiertodebugproblemswithIRcommunication,I
haveoptionaldebuggingcodeinthelibrary.Add#define

DEBUGtothebeginningofyourcodetoenabledebugging
outputontheserialconsole.Youwillneedtodeletethe.o
filesand/orrestarttheIDEtoforcerecompilation.
ProblemswithTransmission
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

6/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

Ifsendingisn'tworking,firstmakesureyourIRLEDisactually
transmitting.IRwillusuallyshowuponavideocameraorcell
phonecamera,sothisisasimplewaytocheck.Tryputting
theLEDrightuptothereceiverdon'texpectalotofrange
unlessyouamplifytheoutput.
Thenextpotentialproblemisifthereceiverdoesn't
understandthetransmitter,forinstanceifyouaresendingthe
wrongdataorusingthewrongprotocol.Ifyouhavearemote,
usethislibrarytocheckwhatdataitissendingandwhat
protocolitisusing.
AnoscilloscopewillprovideagoodviewofwhattheArduino
oraremoteistransmitting.YoucanuseanIRphotodiodeto
seewhatisgettingtransmittedconnectitdirectlytothe
oscilloscopeandholdthetransmitterrightuptothe
photodiode.Ifyouhaveanoscilloscope,justconnectthe
oscilloscopetothephotodiode.Ifyoudon'thavean
oscilloscope,youcanuseasoundcardoscilloscopeprogram
suchasxoscope.
TheSonyandRC5/6protocolsspecifythatmessagesmust
besentthreetimes.Ihavefoundthatreceiverswillignorethe
messageifonlysentonce,butwillworkifitissenttwice.For
RC5/6,thetogglebitmustbeflippedbythecallingcodein
successivetransmissions,orelsethereceivermayonly
respondtoacodeonce.
Finally,theremaybebugsinthislibrary.Inparticular,Idon't
haveanythingthatreceivesRC5/RC6,sotheyareuntested.
ProblemswithReceiving
Ifreceivingisn'tworking,firstmakesuretheArduinoisatleast
receivingrawcodes.TheLEDonpin13oftheArduinowill
blinkwhenIRisbeingreceived.Ifnot,thenthere'sprobablya
hardwareissue.
Ifthecodesaregettingreceivedbutcannotbedecoded,
makesurethecodesareinoneofthesupportedprotocols.If
codesshouldbegettingdecoded,butarenot,someofthe
measuredtimesareprobablynotwithinthe20%toleranceof
theexpectedtimes.Youcanprintouttheminimumand
maximumexpectedvaluesandcomparewiththeraw
measuredvalues.
Theexamples/IRrecvDumpsketchwilldumpoutdetails
ofthereceiveddata.Thedumpmethoddumpsoutthese
durationsbutconvertsthemtomicroseconds,andusesthe
conventionofprefixingaspacemeasurementwithaminus
sign.Thismakesiteasiertokeepthemarkandspace
measurementsstraight.
IRsensorstypicallycausethemarktobemeasuredaslonger
thanexpectedandthespacetobeshorterthanexpected.
Thecodeextendsmarksby100ustoaccountforthis(the
valueMARK_EXCESS).Youmayneedtotweaktheexpected
valuesortolerancesinthiscase.
Thelibrarydoesnotsupportsimultaneoussendingand
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

7/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

receivingofcodestransmittingwilldisablereceiving.

Applications
I'veusedthislibraryforseveralapplications:
Controllingapedestriansignwitharemote.
Iextendthelibrarytoarbitraryremotes.
Controllingmystereoovertheweb.
I'veusedthislibrarytoimplementa"Universal
remote"torecordandplaybackIRcodes.
Idemonstrateturningsomethingonandoffvia
remoteinmyinfraredbubblemakerproject.
UsingthelibrarytodetectIRbeambreaks

Otherprojectsthatusethislibrary
electrostheticsusedthelibrarytocontrolahome
theaterreceiver.
Arduino:RedefiningtheTVRemoteusingthe
libraryandanultrasonicsensortocontrolaTVby
wavingyourhand.

OtherArduinoIRprojects
IwasinspiredbyBuildingaUniversalRemotewithan
Arduinothisdoesn'tliveuptobeingauniversalremote,but
hasalotofinformation.TheNECIRrcvlibraryprovidedthe
interrupthandlingcodeIuse.

+53 Recommend this on Google

Labels:arduino,ir

804comments:
Jacksaid...

1200of804NewerNewest

Wowthisisgreat,Ihavebeenlookingforsomethinglike
thisforawhilenow.
Thankssomuchforposting!!!
Iamhavingtroublesendingthevaluesfrommyremote
throughthesendfunction.
SpecificallyIrecordedthe"volumedown"signalfrommy
macbookremote(77E130DA).
Ithentriedsendingthatwiththiscode:
irsend.sendRaw(0x77E130DA,12,36)
Butthatwouldnotcompile.
MyprogrammingskillsarelowtomediumsoIcouldbe
missingsomethingcompletelyobvioushere.Anyhelp
wouldbemuchappreciated.
MyprojectistoturnmyiPhoneintomytelevisionremote
usingsafariontheiphone>iobridge>arduino>theTV
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

8/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

YourcodeseemsperfectforthissoIamreallyexcitedto
getthecodestransmittingproperly.
Thanksinadvanceforyourhelp
September1,2009at3:42PM

KenShirriffsaid...
HiJack!Thanksforyourcomments.sendRawonly
workswhenyouexplicitlygiveanarrayofonandoff
durations.IthinkthemacbookusestheNECprotocol,so
tryusingirsend.sendNEC(...).
September1,2009at4:24PM

Jacksaid...
ThanksKenI'lltinkeraroundwiththat.
Isthereawaytocapturetherawsignaltoresendwith
sendRaw?
Basicallysoyoucouldcopyandpastethecodes
September2,2009at12:24PM

Harrisonsaid...
Thisisgreat!
CouldyoupleasetellmehowIcanchangetheoutput
pin?(Ihaveanarduinoclonewithpin13asLEDandIR
Tx)
September5,2009at2:42PM

KenShirriffsaid...
Jack:trytheIRdumpexampletodumpouttherawdata.
Harrison:youhavetousepin3astheIRLEDoutput
becausethat'sthePWMpin.(Youcoulduseadifferent
PWMpin,butitwouldtakesubstantialmodificationtothe
code.)
September5,2009at3:36PM

alstergsaid...
Greatwork!Doesthislibrarysupportalsooperationwith
multipleIRreceivers?
September6,2009at5:29AM

Arvinsaid...
I'vebeenusingapicaxetotx\rxirbutthatonlyworks
withsony.Your'swouldallowmetodootherremote
controls.
SoIputthecodeyoushowintheIRrecvintoaarduino
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

9/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

sketchanditerrorson"lessthanresults".Can'tuse
lessthan!
I'vetried*andnothingthereandgeterrorsbothways.
Whatshoulditbe?
September13,2009at8:06AM

Arvinsaid...
Backagain.Readthecodeinoneofyourexamplefiles.
Itused&infrontofthe"result".Thatgivesmea
"redefinitionof'intRECV_PIN'"error.
September13,2009at8:26AM

KenShirriffsaid...
Thiscommenthasbeenremovedbytheauthor.
September13,2009at9:08AM

KenShirriffsaid...
Arvin:PleaselookatthecodeinthezipfileIthinkI
messeduptheHTMLformattinginthecodesnippetin
thearticle.
September13,2009at9:38AM

GiorgioOsaid...
Thanksforthelibrary!
I'mtryingtousetheexampleIRrecord.pde.
Everythingworksfineonasuperficiallevel:theelctronic
circuitisok,I'mreceivingtheinfrareddatafromthe
remotecontrolofasatdecoderboxandI'mprintingiton
theserialwindow...ThenwhenItrytoplayitback
nothingshappens(I'mnotabletotriggerthesatellite
decoderwithmyIRledfromthearduino).IfIlookatthe
irledwithmycameraIseeitpulsing...somyquestionis:
sincethelibraryissamplingtheirsignalfromtheremote
controlwitharesolutionof50microseconds,isitpossible
thattherawdatarecordedisnotusablefortheplayback
ofthesamesignal?Woulditbepossibletoincreasethe
samplingresolution?
September16,2009at6:35PM

australopitecussaid...
Hi.
Ireallylikethisproject.Thankyouverymuch.Ithelps
mealot.
ButIhaveoneproblem.Everythingworks,except
sendingtheIRpulse.NeitherintheexampleIRrecord
norwithIRsendDemo.
TheresnooutputatthePWMpin3.Ivetesteditwitha
camera,aLEDinsteadoftheIRdiodeandthe
oscilloscope.Theresdefinitelynosignal.
Firstimentionedtheressomethingwrongwiththe
sourcecode.Butitsprogrammedreallysophisticated
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

10/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

andicouldntfindamistake,thoughiconsidermyselfa
quiteacceptableprogrammer.Sorryforselfpraise.
ButGiorgioOwrote,thediodeissending.Sotheres
anotherproblem.
IsthereanythingIcouldhaveforgotorhasanybodyelse
hadasimilarproblem?Imtryingfor4days....
IusetheArduinomegaboardwiththe0017software.
ExcusemymistakesinEnglish.Imnotanativespeaker.
Thanksforhelp..
September17,2009at12:47AM

Wolfgangsaid...
IaddedthePanasonicIRprotocol.
Constants:
#definePANASONIC_HDR_MARK3502
#definePANASONIC_HDR_SPACE1750
#definePANASONIC_BIT_MARK502
#definePANASONIC_ONE_SPACE1244
#definePANASONIC_ZERO_SPACE370
Sendingfunction:
voidIRsend::sendPanasonic(unsignedlongaddress,
unsignedlongdata){
enableIROut(38)
mark(PANASONIC_HDR_MARK)
space(PANASONIC_HDR_SPACE)
for(inti=0i<32i++){
mark(PANASONIC_BIT_MARK)
if(address&0x80000000){
space(PANASONIC_ONE_SPACE)
}else{
space(PANASONIC_ZERO_SPACE)
}
address<<=1
}
for(inti=0i<16i++){
mark(PANASONIC_BIT_MARK)
if(data&0x8000){
space(PANASONIC_ONE_SPACE)
}else{
space(PANASONIC_ZERO_SPACE)
}
data<<=1
}
mark(PANASONIC_BIT_MARK)
space(30000)
space(30000)
space(14000)
}
Receivingfuntion:
longIRrecv::decodePanasonic(decode_results*results){
unsignedlongdata=0
intoffset=1
if(!MATCH_MARK(results>rawbuf[offset],
PANASONIC_HDR_MARK)){
returnERR
}
offset++
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

11/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

if(!MATCH_MARK(results>rawbuf[offset],
PANASONIC_HDR_SPACE)){
returnERR
}
offset++
//decodeaddress
for(inti=0i<32i++){
if(!MATCH_MARK(results>rawbuf[offset++],
PANASONIC_BIT_MARK)){
returnERR
}
if(MATCH_SPACE(results
>rawbuf[offset],PANASONIC_ONE_SPACE)){
data=(data<<1)|1
}elseif(MATCH_SPACE(results
>rawbuf[offset],PANASONIC_ZERO_SPACE)){
data<<=1
}else{
returnERR
}
offset++
}
results>address=data
data=0
for(inti=0i<16i++){
if(!MATCH_MARK(results>rawbuf[offset++],
PANASONIC_BIT_MARK)){
returnERR
}
if(MATCH_SPACE(results
>rawbuf[offset],PANASONIC_ONE_SPACE)){
data=(data<<1)|1
}elseif(MATCH_SPACE(results
>rawbuf[offset],PANASONIC_ZERO_SPACE)){
data<<=1
}else{
returnERR
}
offset++
}
results>value=data
results>decode_type=PANASONIC
results>bits=48
returnDECODED
}
September17,2009at12:42PM

KenShirriffsaid...
Giorgio:thereareseveralreasonsyoursatdecoderbox
maynotrespond.Atthelowlevel,itmightbeusinga
differentmodulationfrequencythan38KHz,oradifferent
IRwavelength.Higherlevel,itmaybeexpectingmore
thanjusttheplayedbacksignal.Forinstance,RC5
alternatesbetweentwodifferentcodes,sosimple
playbackwon'twork.Sonycodesrequirethecodetobe
transmittedatleasttwice.Yourboxmayhaveitsown
strangerequirements,suchasdifferentcodeswith
particulartimings.Itcouldbethe50usresolution,but
I'vefoundthatgenerallyisn'taproblem.MorelikelyisIR
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

12/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

sensorstypicallyextendtheontimeandshrinktheoff
timemycodetriestocorrectforthis,butthecorrection
factorcouldbedifferentforyoursensor.Unfortunately,
therearealotofvariablestoinvestigate.Also,trythe
circuitwithyourTVorstereo,toseeifitworksthere.If
youletmeknowwhatmodelsatelliteboxyou'retryingto
control,Icouldinvestigateabit.
australopitecus:Mycodewon'tworkwithanArduino
megaasithasadifferentprocessorandthepinsareall
different.(SorryIdidn'tmentionthatinmyoriginal
article.)Youcouldseeifthere'sanythingonPWMpin9
Ibelievethat'swheretheOC2Boutputconnectsonthe
mega.Probablyyou'llneedtostudytheatmega1280
datasheetandseehowthePWMflagsaredifferentfor
themega'sprocessor,andchangethecode
appropriately.UnfortunatelyIdon'thaveamega,soI
can'ttrythismyself.
Wolfgang:thanksforthecodeupdate.
September17,2009at11:28PM

australopitecussaid...
Hi.
Thatwastheproblem,yes.
TodayIfoundintheofile"pins_arduino.c.o"thepathto
the"cores"folderandafilenamed"pins_aruino.c".
Accordingtothis,inthedigital_pin_to_timer,whichisa
partoftheprogrammemory,Ithink,Timer2Bisrelated
toPWM9.Itrieditanditworked.Ihadonlytochange
theoutputofthepinMode.
Idontknowifthatsexactlythesameyoumentioned,
butIhaveasignalnow.SoIcanreceiveandsend.
Thankstoyou,thissavedmyweekend.
Ilovetheinternet.
AndalsothankstoWolfgangforthePanasonicprotocol.
September18,2009at2:55AM

reconnnnsaid...
Hi
ItrytocontrolmyLGtvusingaarduinoandIfoundyou
libandithinkitwouldworkgreat.Ialsofoundmytvir
codesonLIRCbutIhavenoideahowimgoingtouse
theinformationatLIRCtocontrolemytv.
Thanksinadvanceforyourhelp!!
September26,2009at5:17AM

KenShirriffsaid...
Hireconnnn:I'mintheprocessofwritinganexplanation
ofLIRCdata,butforyourcaseLGusuallyuses32bit
NECprotocol.Takethepre_databytesintheLIRCfile
andjointhemtothebytesforthebuttonyouwantto
controltomakea4bytehexnumber,anduse
sendNEC.Poweronisprobably0x20df10efsomeLG
devicesuse0x897641beor0x34347887.Ifyouhavean
IRdetector,youcanreadoutwhatyourremotesends,
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

13/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

ratherthanlookingintheLIRCfiles.
September26,2009at3:17PM

reconnnnsaid...
HiThanksforthatquickanswerKenShirriff
Ifoundthis
http://lirc.sourceforge.net/remotes/lg/MKJ40653802
documentanditsaythatpowershouldbe0x10EFami
rightthen?
Andshouldiuse0xD02Fforinput?
Thanksagainforthehelp!!
//Reconnn
September26,2009at4:03PM

KenShirriffsaid...
reconnn:TheNECprotocolusesconstantfirsttwobytes
toindicatethedevice(lircpre_data0x20dfinyourcase),
anddifferentlasttwobytes(thelircbuttoncode)to
indicatetheaction.
Sopoweron/offforyourLGTVwouldprobablybe
irsend.sendNEC(0x20df10ef,32),volumeupwouldbe
irsend.sendNEC(0x20df40bf,32),volumedownwould
beirsend.sendNEC(0x20dfc03f,32),etc.
September26,2009at4:31PM

ToddTreecesaid...
Thanksforpostingthis!Ihavebeenlookingforinfoon
howtodothis,butIthoughtIneededanoscilloscopeto
decodetheIRsignals.
Ihavegottenalmostallofmydevicestoworkwithyour
code,butIcan'tseemtofigureoutwhatprotocolmy
SharpLCDTVisusing.
IbelievethatthisLIRCremotefileisclosetomymodel:
http://lirc.sourceforge.net/remotes/sharp/GA538WJSA
DoyouhappentoknowhowIcouldcontroltheTVusing
yourlibrary?
October15,2009at9:48PM

MicMacsaid...
ThanksforthisgreatgreatLibrary.
AfewobservationsImade:
ReceivingdoesnotworkwithofficialEthernetShield,but
Ihadnoproblemssending.TheProblem(Iguess)is
thatSPI(pins1013)isneededforcommucationwith
theethernetshieldandalsousedfortheir
communication.Butitmightalsobeinterruptortimer
related.
Iwilltakeadeeperlookatit,butatmI'mcoveredin
"lookat's",sonopromises.
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

14/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

Againthanksandkeepthegoodworkflowing)
November9,2009at7:44PM

KenShirriffsaid...
MicMac,theEthernetshieldusespins1013,sotheIR
libraryshouldworkifyouuseanyotherpinsforinput.
Thelibraryrequirespin3foroutput,butcanuseany
digitalI/Opinforinput.
November10,2009at7:54AM

Anonymoussaid...
Hi,
Thanksforthelibrary.Ireadthroughthecodeand
understanditsfunctions,sendingandreceiving.Butjust
onequestion:
Why"MARK"isdefinedas0and"SPACE"isdefinedas
1?Ithoughtitwouldbetheotherwayaround,sincethe
sendingfunctionsturnONthePWMpinwhensendinga
MARKandOFFwhensendingaSPACE.
Thanks.
November24,2009at8:36PM

Anonymoussaid...
Nevermind.IgotitnowwhytheMARKisdefinedas1
andSPACEisas0forthereceivingside.It'sbecause
thethereceiverisactivelow.(Itshouldbeasnamed.
Don'tpayattentiontotheactualvaluesforeasier
understanding.)
IhadrefactoredthecodeintolittletinyCmodulesfor
sendingandreceiving,sothatyoucanchoosetolinka
particularsenderandreceiverwithverysmallflashsize
thatfitsto2KATTINIES,suchas,theATTINY25.
Also,thecodeisnowArduinofree,meaningrunningon
anyAtmelchip,aslongasyouchnageinterruptpartof
thecode.(Ihadtowriteonesimplemodulethatsupport
digitalWrite()/digitalRead()/pinMode()functions.)
Ihadalsooptimizedtocodetodobitpackingoftheport
infointo16bits,aswellasmiscinfo,forexample,when
usinguint8_tinsteadofuint16_t.
Thecorefunctionalityisexactlythesameastheoriginal
code,withoutchange.
Ifranklyhaven'ttestedtheoriginalcodebyKen,the
author,becausethecompiledhexfilewon'tfitintoan
ATMEGA8/ATTINY25.
ButItestedoutmystuff.
Idohaveonequestioningeneral.

http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

15/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

ThemomentthereceiverreceivessufficentIRdatato
getitintotheSTATE_STOPstate,Ihavenoticedthatit
tookalmost4secs(SECSwithanATMEGA8at16Mhz)
toactuallytohaveirparams>timer>GAP_TICKS,which
iscalculatedouttobe100,thus,100*50us=5000us=
5ms,butitreallyshouldn'tbe4secsbetweenthe
momentIfinishsendingsomeIRdata(viaaremote
control)tothetimeSTATE_STOPisset.Why?
Thanksforanytips.
November26,2009at7:34PM

edwardsaid...
Icompiledthedemo(SonyTVpower),andmodifieditto
sendaon/offevery1second.Onlyoneinabout60work
andI'm3feetfromtheTV.ItookapeekattheLED
outputviaadigitalcameraanditlooksverydim.I've
removedtheresistorontheLEDandit'sstillnoticably
lessbrightthanaregularremote(viewedthroughthe
camera,anditonlyworksatallthisway).Swappedin
anotherLEDsamething.
Ideas?
December6,2009at3:01AM

KenShirriffsaid...
Edward:twoideasonyourproblem.First,Sonycodes
needtobesentatleasttwiceorthereceiverwillignore
it.Trysomethinglike:
irsend.sendSony(code,12)
delay(50)
irsend.sendSony(code,12)
delay(50)
irsend.sendSony(code,12)
Second,addadrivertransistortoincreasetheIRpower,
becausetheArduinochipoutputshavelimitedcurrent.
See,forexampletheTVBGonedesign.
December6,2009at8:25AM

edwardsaid...
Ahha!
Youindirectlyrevealedthe"bug".Iwassendingthecode
3x(yourSonypowercodesnippet)withthe100msdelay
betweenpulses,everyonesecond.Ireducedyour
100msto50msanditworked.Soyoumightconsider
changingeyoursamplesnippetto50msdelaysbetween
pulses.
Thanksatonforthequickresponse.I'mnowunblocked.
CheersfromSeattle,WA
Edward
December6,2009at2:18PM

http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

16/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

RandyWallacesaid...
I'vebeenusingthislibraryforawhileI'mdoingaproject
thatinvolvesusingtheArduinoasawebserverfor
controllingIRoutput.SomeinterestingthingsI'm
implementingarethewebduinolibraries,EEPROMfor
storingreceivedvalues,anda8x2LCD.
OnereallyimportantthingI'venoticedisthattheArduino
cannotprovideenoughpowerfromtheDigitalOutpins.
I'musingaStockIRLEDfromRadioShack,whichcan
operateatupto100mAat1.2Volts.Formorepower,I
amusinga2N2222transistor:thebaseisinserieswith
a2Kresistorandthedigitaloutputpintheemittergoes
togroundand,thecollectorisinserieswitha47ohm
resistor,theIRLED,andthe5Vsupply.Ihaven'tranthis
throughaammeterregardless,onpaperthereismore
thanenoughpower,anditworkswellforme,regardless
ofhowmuchpoweri'mdrawingfromthepowersupply.
Letmereport,also,thatIhaven'texperiencedacode,
receivedandsentbytheselibraries,thatdoesn'twork.
Kudos,myfriend,Kudos!
December12,2009at8:35AM

Anonymoussaid...
IwasreceivingcodesandthensendingcodesandI
couldn'tfigureoutwhyitwouldhangaftersendinga
code.ThereasonisthatIdidn'tknowthatyouneededto
usetheirrecv.enableIRIn()aftereverysendbeforeyou
canreceiveagain.Spentmanyhourstryingtofigureout
whatwasgoingon.
Thanksforthegreatlibrary!
December15,2009at11:35AM

Jekosaid...
YesterdayifinallydiscoveredyouramazingIRLibraryfor
Arduino...Iwouldliketothankyouforsharingyourjob...
it'sbyfarbestIRLibraryforArduino,itworksveryvery
wellandit'sveryeasytouse,too.
Afterplayingwithitabit,controllingleds,switchesand
anythingthatcouldbeattachedtomyarduino,Itriedto
useitforcontrollingsomeDMXdevices...itwouldbe
amazingformetocontrolmyhouseilluminationwithan
IRRemoteandsomestandardDMXequipment(I'vegot
alotofDMXdevicesandilovetodealwiththem,DMX
worksveryverywellinmanyenvironments)
IusethisDMXLibrary
http://code.google.com/p/tinkerit/wiki/DmxSimple
Sadly,isoondiscoveredthatboththeIRLibraryandthe
DMXlibraryuseTimer2,inadifferent,differentway,and
asfarasI'veseentheywon'tworktogether
myprogrammingskillsarenotadvancedenoughtoget
outofthisissue...andiwaswonderingifyouhavesome
ideas
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

17/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

Ithinkitwouldbeveryusefultousearduinotocontrol
DMXdevicesviaIRRemote,becauseDMXcontrollers
areusuallyveryexpensiveandnotsocustomizable,and
therearehundredsofDMXdevicesthatasksonlytobe
controlled:)

Thankyouagainforsharingyourgreatjob,andhappy
newyear!
December30,2009at8:38AM

MichaelGoldsaid...
Lovethislibrary!Iranintoalittlehitchthatcausedme
someconfusion,butIeventuallyfoundaworkaround
thatIwantedtomentionhere.Whileusingthelibraryto
enableanIRreceiver(salvagedfromanoldVCR)while
elsewhereinmycodealsodrivinganRGBLEDusing
otherPWMpins(onpin9,10,11forr,g,b)Igotsomeodd
behavior:Icouldn'tcontrol'green'onpin11).I'mabitof
anewbieatthis,butitseemedlikeatimingissue
affectingthePWM.
Lookingatthelibrarycode,Icouldseethatit
manipulatesoneofthemicrocontroller'stimers(timer2,
viaTCCR2AandTCCR2B)inordertoproperlysense
theincomingIRsignal.ThroughGooglingIcameacross
thePWMcheatsheetonthearduinoplayground
(http://www.arduino.cc/playground/Main/TimerPWMChea
tsheet)whichmentionsthattimer2handlesPWMtiming
forpin3and11.SinceIoriginallyhadmy'Green'
connectiononpin11,thecheatsheetseemedtoindicate
thatitwasaffectedbythelibrary'suseoftimer2.Sure
enough,movingtheGreenconenctiontotoanother
PWMpin(nothandledbytimer2)seemedtosolvemy
issue.
So,ifoneusesthislibrary,lookslikePWMonpin11is
notpossible,giventhelibrary'suseoftimer2.Asmall
limitationonanotherwiseincrediblyusefullibrary!
Manythanks,
Michael
ps:IsawthecommentaboveregardingtheDMX
controllerlibraryconflictbecauseitusestimer2.
Wondering:Inordertosolvetheconflictor,asabove,if
oneabsolutelyneedsPWMonpin11couldonemodify
theIRlibrarytojustusetimer1(ex:TCCR1A,TCCR1B,
OCR1A,OCR1Betc)ortimer0(ex:TCCR0A,TCCR0B,
OCR0A,OCR0Betc)?
January6,2010at10:55AM

insulatedcopperwiresaid...
Ireallylikethisproject.Thankyouverymuch.Ithelps
mealot.
ButIhaveoneproblem.Everythingworks,except
sendingtheIRpulse.NeitherintheexampleIRrecord
norwithIRsendDemo.TheresnooutputatthePWMpin
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

18/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

3.Ivetesteditwithacamera,aLEDinsteadoftheIR
diodeandtheoscilloscope.Theresdefinitelynosignal.
January6,2010at11:28AM

Jonsaid...
Awesomelibrary!
I'veconfirmedthatthePanasoniccodepostedabove
worksbutthereareafewquirks.
YouneedtomodifytherawbuffersizeinIRremote.hto
accommodatethelonginputasfollows:
#defineRAWBUF100
Afterthatitworkedfineindebugmode.
ThenIhadtoremovethematchmacrosandadd
standardfunctionsinIRremote.cppasfollows:
#ifndefDEBUG
intMATCH(intmeasured,intdesired){returnmeasured
>=TICKS_LOW(desired)&&measured<=
TICKS_HIGH(desired)}
intMATCH_MARK(intmeasured_ticks,intdesired_us)
{returnMATCH(measured_ticks,(desired_us+
MARK_EXCESS))}
intMATCH_SPACE(intmeasured_ticks,intdesired_us)
{returnMATCH(measured_ticks,(desired_us
MARK_EXCESS))}
#endif
Beforethemodificationitwouldonlysuccessfullydecode
apanasonicsignalindebugmode.Iassumethisis
becauseMacrosarenottypesafenordotheyhandle
expressionsenteredasargumentsperfectlyinallcases.
Ididn'tlooktoodeeplyintothefailurebutthisfixworked
forme.
January9,2010at2:19PM

Jonsaid...
IaddedtheJVCprotocol:
Constants:
#defineJVC_HDR_MARK8000
#defineJVC_HDR_SPACE4000
#defineJVC_BIT_MARK600
#defineJVC_ONE_SPACE1600
#defineJVC_ZERO_SPACE550
#defineJVC_RPT_LENGTH60000
Sendingfunction:
voidIRsend::sendJVC(unsignedlongdata,intnbits,int
repeat)
{
enableIROut(38)
data=data<<(32nbits)
if(!repeat){
mark(JVC_HDR_MARK)
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

19/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

space(JVC_HDR_SPACE)
}
for(inti=0i<nbitsi++){
if(data&TOPBIT){
mark(JVC_BIT_MARK)
space(JVC_ONE_SPACE)
}
else{
mark(JVC_BIT_MARK)
space(JVC_ZERO_SPACE)
}
data<<=1
}
mark(JVC_BIT_MARK)
space(0)
}
Receivingfuntion:
longIRrecv::decodeJVC(decode_results*results){
longdata=0
intoffset=1//Skipfirstspace
//Checkforrepeat
if(irparams.rawlen1==33&&
MATCH_MARK(results>rawbuf[offset],
JVC_BIT_MARK)&&
MATCH_MARK(results>rawbuf[irparams.rawlen1],
JVC_BIT_MARK)){
results>bits=0
results>value=REPEAT
results>decode_type=JVC
returnDECODED
}
//Initialmark
if(!MATCH_MARK(results>rawbuf[offset],
JVC_HDR_MARK)){
returnERR
}
offset++
if(irparams.rawlen<2*JVC_BITS+1){
returnERR
}
//Initialspace
if(!MATCH_SPACE(results>rawbuf[offset],
JVC_HDR_SPACE)){
returnERR
}
offset++
for(inti=0i<JVC_BITSi++){
if(!MATCH_MARK(results>rawbuf[offset],
JVC_BIT_MARK)){
returnERR
}
offset++
if(MATCH_SPACE(results>rawbuf[offset],
JVC_ONE_SPACE)){
data=(data<<1)|1
}
elseif(MATCH_SPACE(results>rawbuf[offset],
JVC_ZERO_SPACE)){
data<<=1
}
else{
returnERR
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

20/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

}
offset++
}
//Stopbit
if(!MATCH_MARK(results>rawbuf[offset],
JVC_BIT_MARK)){
returnERR
}
//Success
results>bits=JVC_BITS
results>value=data
results>decode_type=JVC
returnDECODED
}
*NoteinsteadofsendingtheREPEATconstantifyou
wanttheJVCrepeatsignalsent,sendtheoriginalcode
valueandchangetherepeatargumentfrom0to1.JVC
protocolrepeatsbyskippingtheheaderNOTbysending
aseparatecodevaluelikeNECdoes.
January9,2010at2:39PM

Anonymoussaid...
HiJustaquicknotetosayIusedyourlibtoimplementa
protoypeethernetbasedremoteformyTV&DVDR
whichIaccessfrommyiPhoneviawifi.Ialsomakeuse
ofalocalwebserverbetweenmyIphone&theIRremote
arduno/ethernetshield.Hopefully,Iwillbeabletodo
withoutthewebserverinbetweenbyusingajaxonthe
iPhone.TheIRreceivercomponentwasveryusefulfor
decodingmyDVDremote.TheTVandDVDRarefrom
philipsandbothuseRC6.TheTValsoacceptsabase
setofRC5codesaswell.
ThanksforyourgreatworkfromDublin,Ireland:)
January13,2010at6:17PM

KenShirriffsaid...
Assomepeoplementionedabove,thelibraryuses
timer2soitwillconflictwithothersoftwarethatuses
timer2.Timer0isusedbytheArduinoframeworkfor
millis()anddelay(),sothelibrarycan'teasilyusetimer0.
Timer1isa16bittimer,soit'snotdirectlycompatible
withtimer2.I'mlookingintomodifyingthelibrarytouse
timer1.
January18,2010at9:57AM

MichaelGoldsaid...
(Fromthehavemycakeandeatittoodepartment):If
youweretoundertakeaddingsupportfortimer1,mightit
beworthwhiletomakeituserconfigurablesothelib
coulduseeithertimer1ortimer2basedonsomesortof
configurationdirective/variablesetting?
Thinkingthatifyousubstitutedtimer1support*inplace
of*supportfortimer2,thatmightfixtheissuesonpin3
and11butitwouldprobablynegativelyaffectthose
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

21/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

usingPWMonpins9and10(sincetimer1controlsPWM
on9and10)...
againthanksforcreatingthislibrary!
Michael
January19,2010at7:16PM

KenShirriffsaid...
Michael,thanksforyourcomment.Iwasplanningtouse
acompiletime#ifdeftoselectthetimer(assumingIget
supportfortimer0andtimer1working).
January19,2010at7:23PM

ToddTreecesaid...
Iamnotsureifthiswillhelpanyone,butusingan
oscilloscopeIwasabletocreatesendingfunctionsfora
SharpLCDTVandaDISHNetworkreceiver.
TheDishsendfunctionneedstoberepeated4times
andtheSharpfunctionhasthenecessaryrepeatsbuilt
in.Iknowthatit'snotconsistent,butIdon'thavethe
timetoupdatemycode.
HerearetheLIRCfilesthatIfoundthatseemtomatch
theremotecodesfromtheoscilloscope:
SharpLCDTV:
http://lirc.sourceforge.net/remotes/sharp/GA538WJSA
DISHNETWORK(echostar301):
http://lirc.sourceforge.net/remotes/echostar/301_501_31
00_5100_58xx_59xx
FortheDISHcodes,onlysendthelastforcharactersof
thehex.
i.e.use0x1C10insteadof0x0000000000001C10which
islistedinthelinkedLIRCfile.
Ifanyonecanhelpcreatethereceivingfunctions,that
wouldbegreat!KeepinmindthattheDishremote
operatesat56hz.
Herearetherelevantmodstothelibrary(sorryifit's
sloppycode):
//IRremote.h
#defineDISH5
#defineSHARP6
voidsendDISH(unsignedlongdata,intnbits)
voidsendSharp(unsignedlongdata,intnbits)
//IRremoteInt.h
#defineSHARP_BIT_MARK245
#defineSHARP_ONE_SPACE1805
#defineSHARP_ZERO_SPACE795
#defineSHARP_GAP600000
#defineSHARP_TOGGLE_MASK0x3FF
#defineSHARP_RPT_SPACE3000
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

22/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

#defineDISH_HDR_MARK400
#defineDISH_HDR_SPACE6100
#defineDISH_BIT_MARK400
#defineDISH_ONE_SPACE1700
#defineDISH_ZERO_SPACE2800
#defineDISH_RPT_SPACE6200
#defineDISH_TOP_BIT0x8000
#defineSHARP_BITS15
#defineDISH_BITS16
//IRremote.cpp
voidIRsend::sendSharp(unsignedlongdata,intnbits){
unsignedlonginvertdata=data^
SHARP_TOGGLE_MASK
enableIROut(38)
for(inti=0i<nbitsi++){
if(data&0x4000){
mark(SHARP_BIT_MARK)
space(SHARP_ONE_SPACE)
}
else{
mark(SHARP_BIT_MARK)
space(SHARP_ZERO_SPACE)
}
data<<=1
}
mark(SHARP_BIT_MARK)
space(SHARP_ZERO_SPACE)
delay(46)
for(inti=0i<nbitsi++){
if(invertdata&0x4000){
mark(SHARP_BIT_MARK)
space(SHARP_ONE_SPACE)
}
else{
mark(SHARP_BIT_MARK)
space(SHARP_ZERO_SPACE)
}
invertdata<<=1
}
mark(SHARP_BIT_MARK)
space(SHARP_ZERO_SPACE)
delay(46)
}

voidIRsend::sendDISH(unsignedlongdata,intnbits)
{
enableIROut(56)
mark(DISH_HDR_MARK)
space(DISH_HDR_SPACE)
for(inti=0i<nbitsi++){
if(data&DISH_TOP_BIT){
mark(DISH_BIT_MARK)
space(DISH_ONE_SPACE)
}
else{
mark(DISH_BIT_MARK)
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

23/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

space(DISH_ZERO_SPACE)
}
data<<=1
}
}
January21,2010at9:05AM

ArduEve(Maple=ARMArduino)said...
Simplyfabulous!
IwassearchingforanArduinoIRlibrary&foundyour
blogonlyacoupledaysafteryou1stpostedit.Been
usingiteversince,ofcourse.I'veseenotherIRcode
here&therebutnothingasgoodasyours.
Thankyouverymuchforsharingthis&yourcontinued
workonit.
Alsothankstoallwhohaveaddedmoreprotocols.
I'msuremanypeoplehaven'tfoundthisyet.Wouldyou
mindifIaddalinkintheArduinoPlaygroundwiki?
http://www.arduino.cc/playground/Main/GeneralCodeLibr
ary
January22,2010at9:54PM

KenShirriffsaid...
I'veputtheIRremotesourceongithubat
http://github.com/shirriff/ArduinoIRremote.I'mhoping
thiswillhelpintegratefixesandextensionsfromother
people.
January22,2010at10:46PM

simonjtaylor212said...
HiKen!
Lovethis,Ihavesofarmanagedtocompiletheexample
anduploadtomybrandnewarduinoandturnmySony
TVoff!
So....couldyouhelpme,andexplainwhatIneedtodo
tofindmorecodesfromLIRCandusethemwithyour
code?I'mabitstucknow..IcanonlyturnmyTVoff!:)
Thanks
SimonTaylor,London,UK
January27,2010at6:57AM

KenShirriffsaid...
Simon:therearetwowaysyoucangetthecodes.First,
youcanlookattheSonyLIRCfilesandtrytofindone
withcodesthatworkonyourTV.Onecomplication:the
SonyLIRCcodesareabitambiguousaboutthelastbit.
Alotdropthelastbit,sotheyare11bitslonginsteadof
12,andyouneedtomultiplythemby2.Othersendin1
andyouneedtosubtract1(trytheRMS609codesand
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

24/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

subtractone).
Alternatively,ifyouhaveanIRreceivermodule,youcan
runtheIRrecvDumpexampletoprintoutthecodesfrom
yourexistingremote.
January28,2010at9:00PM

dariosaid...
Higuys!howcanIusethepanasoniccodepostedhere?
doihavetopasteitinthehfilelibrary?
January29,2010at7:58AM

Juansaid...
ILOVEthislibrary,Ihavebeenplayingtheentireweek
withit.Ihaveoneissue.ThefirsttimeItriedthecodeI
runallthesamples,thefirstsampleIRSendDemowas
notworkingforme,ItriedtheIRRecordanditworked
perfecltly,pressedabutton,savedthecodeandthen
submittingthatcodetomyTV.Great!Thethingisthat
I'mnotabletoJUSTsendacode.Itrytousethe
sendNecmethodbutnooutputonpin3,whatI'mmissing
here?Thanks!!!
January30,2010at7:36PM

Juansaid...
mmmmsorryforthepreviouspost,Itriedagainand
removethefirstifonIRSendDemo....andirworked
PERFECTLY...sadly,IwasusingtheentireblockonALL
mytests...removingtheIFfortheSerial.readsolvedit...
I'MVERYHAPPY!!:)
(postingthisincasesomebodyelseranacrossthesame
problem!)
January30,2010at7:50PM

Anonymoussaid...
TotalArduinonewbie:
WhenItrytocompileIRSendDemo,Igettheerror:
22:error:IRremote.h:NosuchfileordirectoryIn
function'voidloop()':
Anyonecananswer...thanks
January31,2010at12:35AM

Anonymoussaid...
Newbie:
Ididn'tfollowtheinstallinstructions...
January31,2010at9:44AM

Anonymoussaid...
HelloKen,thislibraryisreallygreat.Ijustliketohave
thePanasonicOptionbutIdontknowhowtointegrate
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

25/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

theCodesabove(Wolfgangandnext).IgetmanyErrors
andpersistenly"indecodethereisnoaddress"The
decodingfunctionmaybeedifferentfromtheothers.
SorryImaNewbieandthereshouldbesome
adapptionsIdontunderstandfornow.Couldsomeone
explaintheintegrationofthePanasonicCode(Stepby
StepinDetailwitheveryassociatedFile:)
thanksChristopher
February2,2010at3:15AM

Anonymoussaid...
Ok,IfixedtheProblemabove(justthevariableaddress
toadd).ButnowIvegotserioustrouble.Iamtryingto
implementtheRECS80(averyold,butcheapchip
protocol)andgotstuck.ImodifiedtheNECCode(for
theRECS80ispulsewidthmodulated)butcantgeta
reaction.TheMarksareveryshort(158us)andthe
spacesverylong(4900us=0,7432us=1).The
DurationoftheSignalmaybetolong?Coulditbea
problemwithirparam.timerorRAWBUFFER?
ThanksforreplyChristopher
February3,2010at8:47AM

irkgreensaid...
I'man00bhere,butisthiseasilyportabletothe
ATMEGA168usingAVRstudio4?IhaveanSTK500
andseethatIcanmakeanarduniodevkit,butit
requiresa16MHzxtal(ihave7.3728and12).
February4,2010at12:09PM

simonjtaylor212said...
BewaryoflaptopIR!
Iwasgettingalotofrandom
"0,
couldnotdecodemessage"
resultsontheIRDumpexample.
Thereason?
Mylaptop'sIRportwassendingrandomdata,whichthe
IRreceiverwaspickingup!
I'vetapedoveritfornow.Musthavealookinthecontrol
panel!
Cheers
Simon
February7,2010at7:00AM

Anonymoussaid...
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

26/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

Ican'tseemtocompilethislibraryforsomereason,I
keepgettingalltheseerrors:
IRremote.cpp:Inmemberfunction'void
IRsend::mark(int)':
IRremote.cpp:172:error:'TCCR2A'wasnotdeclaredin
thisscope
IRremote.cpp:172:error:'COM2B1'wasnotdeclaredin
thisscope
plusabout15more...anyideawhatscausingthis?
February12,2010at6:11AM

GlenHsaid...
HiThere.I'mwantingtousethisbrilliantlibrarytocontrol
myAcerprojector.IhavereceivedtheIRcodesfrom
Acerandtheylooklikethis:
PowerOnOKOKOKOKOK
PowerOff*0IR001
Keystone*0IR002
Mute*0IR004
Freeze*0IR006
Menu*0IR007
Up*0IR008
Down*0IR009
Right*0IR010
Left*0IR011
AnyyhintsonhowIcanaddtheseintothelibrary?
Manythanks!
February15,2010at2:05PM

CrYoPyResaid...
Hi,Iwasrecentlytryingtouseyourlibraryonmy
AtMega8basedNGFreeduinoboard.
ItseemsyourlibrarywasmadekeepingtheAtmega168
inmindandhencegiveserrorsincompilationformy
boardtype.
WouldyouknowofanalternativeforAtmega8based
boards?
February19,2010at3:14AM

kenssaid...
GlenH:Idon'tknowwhatthecodesforanAcer
projectorwouldbe.I'dsuggestusingIRDumpandseeif
yougetluckyenoughthatAcerusesanencodingthat
thelibraryhandles.
CrYoPyRe:Idon'thaveanAtmega8soIcan'tportthe
library.You'dhavetochangethecodetousethe
appropriateregisters.Anearliercommentsaidthecode
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

27/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

istoobigtofitinanAtmga8inanycase,soitmight
needtobecutdowntosizetoo.
February21,2010at6:05PM

anshulsaid...
IamworkingonaprojectinwhichIwanttocontrolhome
appliancesusinganyTV/DVDremote.Iamusing
Atmega8forthispurposeandIdonthaveanyArduino
Board.IhavedownloadedAurduinoSoftwareandurIR
decodinglibrariesareworkingonit.
NowtheproblemisthathowIburnmicrcontrollerwith
hexfilegeneratedfromurlibraries?Inwhichdirectory
theArduinoSoftwaresavethesehexfiles?
February27,2010at12:16PM

Anonymoussaid...
ThanksforthisawesomeIRlibrary.
IwasabletouseitforanIRtranslatorapplication.
IdidwanttomentionthatoneproblemthatI
encounteredwasthatIneededtodoreceiveIRand
sendIRformyapplication,andittookmeawhileto
realizethatthesendIRroutineDISABLESthereceiveIR
function.
SoanyonewhoneedtosendandreceiveIR,makesure
todo"irrecv.enableIRIn()"rightafteryoufinishsending
IR.OtherwiseourArduinowouldstopreceivingIR.
March4,2010at11:10AM

Bukssaid...
Brilliant!,IhaveVatelyAirconditionerremotewhichis
stillworkingifyoubendthePCBinjusttherightway.I
wanttoseeifcanreadthecodesandthenbuilda
replacementremote.
Ihaveatotallyunrelatedquestionthough...Whatare
thosenicelookingconnectingwiresyouusedinyour
project?IliveinSouthAfrica,andgettinglocalsuppliers
forhobbyelectronicsstuffcanberatherfrustratingat
times.
Thanxforagreatblog.
March7,2010at1:32PM

KenShirriffsaid...
Buks:thewiresareAdafruit'sbreadboardingwire
bundle.
March7,2010at8:58PM

MikeSsaid...
Verynicework.Ipostthisincasesomeoneelsehas
beenstruggling.

http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

28/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

ThisallowsyoutocontrolaSamsungTVusingOBCto
provideadditionalfunctionsnotontheremote(OBC's
canbefoundonline).
Firstchange9000to4500.
ThenforexampleOBC190switchestoHDMI#2.
Convert190tobinaryandREVERSEtheorder(Igotthis
ideafromlookingatNECexamples),THENconvertto
hex,e.gthisbecomes7D.Invertthebinaryandand
converttohex82.Thuswebpagevaluebecomes
NE0E07D82.
March9,2010at3:56PM

Anonymoussaid...
HiMikeS,
CouldyoupleasedoanotherexampleforOBCcode
converiontotheIRlibraryhexcode?
FormyNECIRcode,Ihave8hexdigits.IfIhavethe
JP1OBCcode,howdoItranslateittotheIRlibraryhex
codeforthesendfunction?
Thanksinadvance.
March9,2010at5:04PM

Bukssaid...
ThebustedAirconRemoteSaga:
1)WhenIputthecircuittogetherasexplaineditwouldat
firstnotwork.Afterreadingthedatasheetformy
particularIRreceiver,Idiscoveredthatpins1,2and3
arenotthesameastheonesdescribedatbeginningof
theblog.OnceIgotthatsortedout,theRcvDump
examplejuststreamedrandomjunkthewholetime.
Backtothedatasheet.Itseemslikeitsalwaysgoodidea
tousethesamplecircuityourmanufacturersuggestsin
thedatasheet.1capand2resistorslateranditworked
likeacharm(theextracomponentsfiltersoutpower
supplynoise).
2)ThenextweirdthingInoticedthatmyairconremote
wasalwayssendingthesamesequencenomatterwhat
settingsIusedonit.Afterdigginginthecodeof
IRremote.cppIfoundthislittlesectionofcode:
if(irparams.rawlen>=RAWBUF){
//Bufferoverflow
irparams.rcvstate=STATE_STOP
}
IRremote.hhadRAWBUFsetto76,whichjusthappened
tobeexactlythesamenumberofvaluesIwasgettingin
thedump.Ihadtoincreaseitallthewayto200tofitin
thewholemessagefromtheairconditionerremote.It
seemslikeairconditionerremotessendallthesettings
(temperature,fanspeed,mode,swingetc)allinonego
everytimeyoupressabutton.
Next:IhavetoreverseengineerthecodessothatIcan
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

29/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

buildareplacementremote.Ihavealreadyfiguredout
which4bitsisusedfortemperature.
Iamalreadyenvisioningvoicecontrolformyaircon...
muahahaha
March10,2010at10:22AM

Ioansaid...
Hi,
I'mcuriousifIcanusethislibrarytomakeabeambreak
detector,sotheIRLEDtransmitscontinuousandthe
receiverdetectswhenthebeamisbroken,whenan
objectisbetweenthetwo.Isthispossible?
March11,2010at3:59PM

MikeSsaid...
Reanotherexample,Ijustusedanonlineconvertat
mathisfuncom.TryitwiththeexampleI'veprovidedand
Ithinkyoucanmakeitwork.ByreversingtheorderI
meanforexample10110000becomes00001101,then
convertthistohex.Thesecondhexistheinverted
11110010converttohex.IthelpstogoogletheNEC
codeformat.Hopethishelps.
March11,2010at4:16PM

Anonymoussaid...
HELP!
Ican'tgetthePanasonicdecodetowork.ThisiswhatI
get:
AttemptingPANASONICdecode
Testingmark3500vs3502:54<=70<=91
Testingmark1700vs1750:27<=34<=47
Testingmark500vs502:9<=10<=16
Testingspace400vs1244:17<=8<=29
Testingspace400vs370:4<=8<=7
Couldnotdecodemessage
Raw(100):1324350017005004004501250500
400450400450450450400450400500400
450400450450450400500350500400450
1250500400450400500400450400450400
5004004504004504504504004501300450
400450450450400450400500400450400
4504504504004501300450400450450450
40045040050012505004004504004501300
4504004504504504004504005001250500
4004501250500
0
CananyonetellwhythePanasoniccodecan'tdecode
thissignalfrommyPanasonicremote?
March11,2010at8:47PM

http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

30/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

KenShirriffsaid...
Replytoloan:forabeambreakdetector,youcoulduse
thislibrarytogeneratethemodulatedsignalfortheIR
source.Iwouldn'trecommendusingthelibrarytodetect
thebreaksyoucouldjustreadthedetectordirectlyona
digitalinput.
Panasonicdecode:itlookslikeit'salmostworking:
Yourlogshows"Testingspace400vs370:4<=8<=7"
Thatmeansyourvalueis400us(8ticks),andit's
expecting370usandwillacceptanythingbetween4and
7.Yourvalueisjustabittoobig(8vs7),sothedecode
fails.
TryincreasingPANASONIC_ZERO_SPACEfrom370to
400or450.Youcanalsoloosenupthecomparisonby
increasingTOLERANCEfrom25%tomaybe35%.
Ishouldwriteupapostingabouthowthisallworks,but
hopefullythisisenoughtogetyougoing.
March13,2010at9:29PM

Anonymoussaid...
HiKen,
ThanksforthehintsforthePanasoniccode,butit'sstill
notworking...
Ididincreasethespaceto450,andchangethe
toleranceto35%.
It'sgettingfurther,butstillcouldn'tdecode.ThisiswhatI
getnow:
Testingmark450vs502:7<=9<=17
Testingspace400vs1244:14<=8<=31
Testingspace400vs450:4<=8<=10
Testingmark450vs502:7<=9<=17
Testingspace450vs1244:14<=9<=31
Testingspace450vs450:4<=9<=10
Testingmark400vs502:7<=8<=17
Testingspace450vs1244:14<=9<=31
Testingspace450vs450:4<=9<=10
Testingmark450vs502:7<=9<=17
Testingspace400vs1244:14<=8<=31
Testingspace400vs450:4<=8<=10
Testingmark450vs502:7<=9<=17
Testingspace1300vs1244:14<=26<=31
Testingmark450vs502:7<=9<=17
Testingspace450vs1244:14<=9<=31
Testingspace450vs450:4<=9<=10
Testingmark400vs502:7<=8<=17
Testingspace450vs1244:14<=9<=31
Testingspace450vs450:4<=9<=10
Testingmark450vs502:7<=9<=17
Testingspace1300vs1244:14<=26<=31
Testingmark450vs502:7<=9<=17
Testingspace400vs1244:14<=8<=31
Testingspace400vs450:4<=8<=10
Testingmark450vs502:7<=9<=17
Testingspace450vs1244:14<=9<=31
Testingspace450vs450:4<=9<=10
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

31/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

Testingmark400vs502:7<=8<=17
Testingspace450vs1244:14<=9<=31
Testingspace450vs450:4<=9<=10
Testingmark450vs502:7<=9<=17
Testingspace400vs1244:14<=8<=31
Testingspace400vs450:4<=8<=10
Testingmark450vs502:7<=9<=17
Testingspace1300vs1244:14<=26<=31
Testingmark450vs502:7<=9<=17
Testingspace450vs1244:14<=9<=31
Testingspace450vs450:4<=9<=10
Testingmark400vs502:7<=8<=17
Testingspace1350vs1244:14<=27<=31
Testingmark450vs502:7<=9<=17
Testingspace0vs1244:14<=0<=31
Testingspace0vs450:4<=0<=10
Anychanceyoucanspotwhat'swrong?Thanks!
March14,2010at8:57PM

KenShirriffsaid...
AnonymousPanasonic:itlookslikethecodeisdesigned
toreceive48bitsandyou'rereceivingabout16bits.
(You'rerunningoutofdatatoosoonandgettingthe0
timevalue.)Youcouldtrycuttingoutallthedecode
addresscode.Oryoucouldreplacethe"returnERR"
with"break"insidetheloops,andthenitwouldsucceed
ratherthanfailwhenitrunsoutofdata.
March14,2010at9:22PM

Ioansaid...
HiKen,
Canyoupostashortexampleonhowusethislibraryto
generatethemodulatedsignalfortheIRsourceat
38kHz(continuoussendforobjectdetection).
TIA!
March15,2010at12:10PM

Anonymoussaid...
Ken,
Thanksforthetips.IfinallygothePanasonicdecode
working.Ihadaccidentallymodifiedtheoriginal
Panasoniccodeduringthecourseofdebugging.The
originalPanasoniccodewithtweaksthatyousuggested
(space,andtolerance)madeitwork.
ThanksagainforthehelpandthisawesomeIRlibrary.
HeyLoan,Iwouldnotsuggestusingthesendfunctions
fromthelibrarytodotheIRbreakdetection.TheIR
sendfunctionDISABLESthereceivefunction.Soyouwill
notbeabletoreceiveandwhenyouaresendingIR.
Iguessingthatyoucandoasimpleanalogwriteona
pwmpintogetaconstant38khzIRoutput.
ButmaybeKenhasbetterideas.
March15,2010at11:35PM
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

32/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

KenShirriffsaid...
Loan:Iwroteupdetailsonusingthelibrarytodetectan
IRbeambreak.Seemylatestpostingatarcfn.com.
March16,2010at10:45PM

BenNorlingsaid...
Ken,
Thisalllooksgreat.IsthereanyreasonIcouldn'tusea
productionqualityIrReceiver?I'vehookedoneup(Niles
m220)andIgettheflashinglight,butitcan'tdecodethe
IR.Iranthedumpprogramanditjustsays"can't
decodemessage"andabunchofnegativenumbers....
Thoughts?
Thankds
April13,2010at10:08PM

KenShirriffsaid...
Ben:IcanthinkofacouplereasonswhyyourM220
receivermightnotwork:
a)Maybethereceiverisactivehighinsteadofactive
low?
b)Maybethecodeyourremoteistransmittingisn'tone
thelibraryunderstands?Inthatcase,lookat
http://www.arcfn.com/2010/01/usingarbitraryremotes
witharduino.html
c)Maybethetolerancesofyourreceiverareabit
differentthantheonesIuse?
Canyousendmetheoutputfromthedumpprogram?I
cantakealookandseewhat'shappening.
April13,2010at10:40PM

BenNorlingsaid...
Ken,
Belowareoutputsfromthedumpprogramandtheraw
program.
I'musingtheM220inanattempttobeabletocoverall
remotes.Thisreceiverisnotlimitedtoa38.1kHz
remote.I'mabitunclearontheactivehigh/lowthing.To
clarify,theoutputfromthem220isnormallyhighand
goeslowasitreceivesimpulsesfromaremote.Asa
resultIhadtocobbletogetheranotgatefroma3input
nandgatewithbothotherinputsforcedhigh..Withthe
outputfromthem220goingdirectlytotheinputpinon
thearduino,Igotabsolutelynoresponse.
Iamahometheatercontractorandhavebeenamazed
athowmuchtheremotecompanieschargetodofairly
simplethings.IfIweremoreofaprogrammer,Icould
probablyuseanarduinoandafewcentsworthofother
bitsandreplacea600dollarremoteprocessor.It'sa
dream..
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

33/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

Thanksforyourhelp,
Ben
'real'decode:0,hashdecode:F3FED56D
'real'decode:0,hashdecode:AC9BB4FA
'real'decode:0,hashdecode:8E46808
'real'decode:0,hashdecode:C439C7D8
'real'decode:0,hashdecode:F692C022
'real'decode:0,hashdecode:F3FED56D
'real'decode:0,hashdecode:2D9CE207
0
Couldnotdecodemessage
Raw(42):10526100290010017501001100100
11001001750100170015017001501700100
11001001750100110010017001501700150
17001001100150105015017001001100150
10501501700100
0
Couldnotdecodemessage
Raw(42):7328100290010017501001100100
11001001750100175010017001501700100
11001001750100110010017501001700150
17001501050150105015017001501050150
10501501700150
April14,2010at7:46AM

BenNorlingsaid...
Ken,
Additionally,Iampressingthesamebuttononasony
dvdremoteseveraltimestogetthisoutput.
Ben
April14,2010at8:03AM

KenShirriffsaid...
Ben:Iseetworeasonsthatyourcodesaren'tdecoding.
First,Icantellfromthepositiveandnegativepattern
thatonandoffarereversed.Mylibraryexpectsan
activelowsignal,whichyourM220provides,soremove
theinverter.
Second,youroffdurationsare~100mswhenthey
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

34/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

shouldbe~600us,andyourondurationsare~500ustoo
long.Inotherwords,yourreceiveristakingabout500us
toswitchfromontooff.Mycodeallows100usforthis
transition(basedontheIRreceiversI'veused),but
500uswillprobablythrowoffthedecoding.Inthefile
IRremote.h,changetheconstantto#define
MARK_EXCESS500
Ithinkwiththesechangesyoushoulddecode
successfully.Icouldmanuallydecodethedumpoutput
andseethatyou'repressingtheUPbuttononyourSony
DVDremote,right?
April14,2010at9:08PM

Anonymoussaid...
Manythanksforprovidingthisforfreeithassavedme
alotoftimeandtrouble.
IthinkthatIhaveabugfixforyouthoughregardingthe
NECprotocol.
InIRremoteInt.hyouhavedefinedNEC_ONE_SPACEas
1600.Ithinkthatthisshouldbe1690(2250ms560uS=
1690msnot1600ms).Theoriginalvaluewasnot
recognisedbyanInFocusprojector,buttheamended
valuedidwork.
April16,2010at9:23AM

DrNeonsaid...
Hithere,I'mtryingtousethislibrarytoresetthelamp
hourstimeronmyPlusU21130projector(which,for
somestupidreasonrequirestheremotetoresetthe
timer,andtheremoteislost).IgottheArduinoboard
andthe950nmIRLEDfromRobotShop,andhave
startedplaying.TheLEDblinksasverifiedwitha
camera,butI'mnotgettinganyresponsefromthe
projector.Fromthemanufacturer,Ihaveafilethatsays
customcode18E9(thoughI'vebeentoldonRCforums
itshouldbe1816),andOncode08F7.I'vetriedsending
(withsendNEC,sincethemanufacturersaysitisNEC
protocol)0x18E908F7,(ieirsend.sendNEC(0x18e908f7,
32))butI'mnotseeinganyresponseontheprojector.
AmImissingsomething?Doesthebitorderneedtobe
reversed,ordoessomethingneedtobecomplemented?
Idon'thavetheremote,soIcan'tuseareceivertoget
thetruecode.I'veheldtheLEDupagainsttheprojector
incaseitisalowpowerissue,stillnoresponse.OnceI
cangetittoturnon,IwillneedtosimulatetheOnbutton
helddownfor10sec,whichIimagineinvolves
somethinglikeirsend.sendNEC(REPEAT,32)being
repeatedeverysomenumberofms.Thanksforthe
awesomelibrary,andthehelp!
April17,2010at10:06AM

Vishalsaid...
HiKen!
Thanksforpostingthislibrary!

http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

35/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

I'mtryingtosendthepoweroncodeforan
Xbox360...I'musingtheLIRCfilefromhere:
http://lirc.sourceforge.net/remotes/microsoft/Xbox360
Usingthedatainthisfile,IfiguredthatIneededtosend
thefollowingcode:
irsend.sendRC6(0x37ff086f3,37)
Thiscomesfromthefactthatthepre_dataislistedas
0x37ff0with21bits,andthepoweron/offcodeis
0x86f3,with16bits.Iclearlyhavesomethingwrong,
becausetheArduinosoftwarespitsouttheerror:
"integerconstantistoolargefor'long'type."I
understandthatthecodeI'mtryingtosendistoolong,
butwhatshouldIdotogetthistoworkcorrectly?
April17,2010at6:43PM

Anonymoussaid...
Thiscommenthasbeenremovedbyablog
administrator.
April23,2010at3:08AM

Anonymoussaid...
Thiscommenthasbeenremovedbyablog
administrator.
April23,2010at3:08AM

spl23said...
Justwantedtosaythankyouverymuchforthelibrary
it'senabledmetosetupanIRcontrollerformySonos
system.Italljustworkedfirsttimemanythanks!
April23,2010at5:12AM

Anonymoussaid...
I'vejustaboutthrownallthisoutthewindowin
frustrationsoIwasexcitedtofindapromisinglibrary.
(Thankyou,btw)
Unfortunatelyseemsthelibraryisn'tworkingforme
eithersoImustbemissingsomethingsomewhere.Hope
youcanprovidesomeideas.
WhenIrunthesendandreceivedemosIonlygetthree
0'sforoutput.TheIRappearstobesending(seenvia
camera)butnotgettinganythingvalid.ItriedaSony
remotealsobutallIgetis0'sforanybutton.
I'musingasharpIRreceiver(38KHz)
(http://media.digikey.com/pdf/Data%20Sheets/Sharp%20
PDFs/GP1UE261X,267X,26X.pdf).Testingwithtwo
ArduinoProMini's.Notsureifitmattersbutthesedorun
at3.3vand8MHz.DoesthatchangethePWMstuff?
BeforetryingthislibraryIwasgettingsomewhat
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

36/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

consistent(althoughnoisy)resultsusingtheclassic
oscillationWriteandpulseInfunctionssoI'mprettysure
thewiringiscorrect.However,it'sfarfromreliablesoI'm
goingcrazy.
Thanksinadvanced!
April23,2010at8:57PM

Anonymoussaid...
Itriedthereceivedumpwiththesenddemoandthisis
whatIcomeupwith:
0
Couldnotdecodemessage
Raw(26):76201200350600300300300600300
300300600300350250350300600300300
300300300300300300
0
Couldnotdecodemessage
Raw(26):146861200300600300300300600300
300300650300300300300300600350250
350300300300300300
0
Couldnotdecodemessage
Raw(26):35241200350600300300300600300
300300600300350300300300600300300
300300300300350250
Thanks(again)inadvanced!
April23,2010at9:10PM

KenShirriffsaid...
Anonymous:beforeyouthroweverythingoutthe
window,trychangingtheclockspeedininIRremoteInt.h
to:#defineSYSCLOCK8000000.Ithinktheproblemis
yourclockspeedis8MHz,andmycodeisdesignedfor
16MHz.
Vishal:ifyouneed37bitNECcodes,trychanging
sendNECtotakeauint64_ttype,sincelongislimitedto
32bits.
Anonymous:yes,youarerightNEC_ONE_SPACE
shouldbe1690.
DrNeon:Idon'thaveanygoodsuggestionsforyou.
MaybetryAnonymous'schangetoNEC_ONE_SPACE
above.
April26,2010at8:44PM

Bobriksaid...
HiIhaveproblemwithlibrary,firstpressisgood
decoded,secondisbad,nextgood,bad,repeately
DecodedRC5:5(12bits)
Raw(24):74695080018508009508001000750
9508001000750100075010007501000750
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

37/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

1000160019001600950
'real'decode:5,hashdecode:33157B67
DecodedRC5:805(12bits)
Raw(24):33901000750100075019007501000
7501000750100075010007501000800950
800950165018501650950
'real'decode:805,hashdecode:6E6E8FBB
DecodedRC5:5(12bits)
Raw(24):75369008501800850900850900850
900850900850900900850900900850900
1700180016501000
'real'decode:5,hashdecode:33157B67
DecodedRC5:805(12bits)
Raw(24):746690080095080018508001000750
10007501000800950800950800950800950
165018501650950
'real'decode:805,hashdecode:6E6E8FBB
May1,2010at2:55AM

SimonLongsaid...
HiKen,
Yourlibraryisgreat,andworksverywellinmySonos
controlproject.However,Idohaveonerecommendation
foryou.
InIRremoteInt.h,yousetthetoleranceforpulsewidth
usingthecode
#defineTOLERANCE25//percenttolerancein
measurements
#defineLTOL(1.0TOLERANCE/100.)
#defineUTOL(1.0+TOLERANCE/100.)
Thisistheonlyfloatingpointcodeusedinthelibrary,
anditmeansthatthecompilerpullsintheArduino
floatingpointlibraries,whichareratherlarge,anditis
wastefulofmemorytousethemforthissimple
calculation.
Ifyoudeletethesethreelines,andmodifythedefinitions
ofTICKS_LOWandTICKS_HIGH(theonlylinesthatuse
them)to
#defineTICKS_LOW(us)((((us)*3)/(4*
USECPERTICK)))
#defineTICKS_HIGH(us)((((us)*5)/(4*
USECPERTICK)+1))
yougetexactlythesamebehaviour,butyoudon'tneed
theFPlibrariesanymore.Onmysketch,thisone
changereducedthememoryusedfrom16404bytesto
15220bytesasavingofwellover1kbyte,whichisvery
worthwhileintheArduino'slimitedmemoryfootprint.
Ingeneral,onembeddedsystems,youshoulduse
integermathswhereverpossiblefloatingpointis
invariablyexpensiveintermsofmemoryandprocessing
power.
May1,2010at3:43AM
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

38/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

KenShirriffsaid...
Bobrik:that'showRC5andRC6codeswork.Theyhave
atogglebitthatisseteveryothertimeyoupressthe
button.Youcansubtract(AND)offthetogglebitifyou
don'twantit.FordetailsseePhilipsRC5Protocol.
SimonLong:that'sagoodpointaboutusingfloating
point.I'llreplacethatwithintegerarithmeticinmynext
release(wheneverthatis).
May1,2010at10:48AM

artinsaid...
HiKen,Ijusttrieditandfoundyourlibraryreallyuseful
andwelldocumented.I'musingittogaincontroloveran
LGDVX482HDVDplayerforanartsinstallation(replace
itsAKB35840202remote).TheRemoteseemstouse2
differentversionsofNECProtocolsforTVcontroland
DVDcontrol.TVProtocolusesaMARKof9000,the
DVDpartworkswhenIchangeNEC_HDMARKto4500
(triedthisvaluebyguessingfromrawvaluereadings).
SinceIdon'tusetheTVpartthischangeisfineforme.
Maybethisisofuseforsomeoneelse.I'mboth
successfullyreceivingandtransceivingrightnow.
Thanks!
May5,2010at5:40PM

Scottsaid...
awesomeproject!anyupdateonwhenthenewlibrary
willbereleased?
May5,2010at8:57PM

Anonymoussaid...
GreatLibrary.I'mdevelopingaremotecontrolfor
watchingTV.Isetahomechannel,thenwhena
commercialcomeson,Icansurfalloverfor2minutesor
so,thentheArduinosendsthesignaltoreturntothe
homechannel.IcallittheAdBlaster.
ForthosewhowanttomeasureIRLEDcurrent,don't
forgetthattheArduinohas6ADCinputs.IturntheIR
LEDon,andmeasurevoltageatbothendsoftheseries
resistor.TheIRLEDvoltagecanalsobemeasured.
ThetypicalIRLED'sareratedfor100mA+continuous
current,sobymakingthedutycycle25to30percent,
highercurrentsareeasilytolerated.
May6,2010at11:46PM

TiStylesaid...
HelloKen,
I'manInteractionStudentontheHKUinHilversum,the
Netherlands.I'm
currentlybusywithaprojectthatrequiresconstantIR
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

39/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

communicationandI
haveaquestionabouttheIRremotelibrary.
I'musinganYamaharemote.NowIwanttousethe
volume+button(5EA158A7),
thattheremoteissending,topoweraledandthe
volumebutton(5EA1D827)
todisabletheled,butthatdoesn'twork..
if(results.value=='5EA158A7'){
Serial.println("+")
digitalWrite(ledPin,HIGH)
}
elseif(results.value=='5EA1D827'){
Serial.println("")
digitalWrite(ledPin,LOW)
}
Couldyouhelpmewiththe
problem?
Kindregards,
TiborDujmovic
InteractionDesign2
HKUHilversum,theNetherlands
May7,2010at12:43PM

Halosaid...
HiTiStyle
ThoughtIwouldtrytohelp.
irrecv.resume()
isattheendofyourcoderight?
IRrecvDumpdecodesyourremotewithoutissueevery
time?
May7,2010at6:17PM

Halosaid...
Oh...try
if(results.value==0x5EA158A7){
Serial.println("+")
digitalWrite(ledPin,HIGH)
}
elseif(results.value==0x5EA1D827){
Serial.println("")
digitalWrite(ledPin,LOW)
}
May7,2010at6:26PM

TiStylesaid...
YES!!!Thankyousomuchman!That'sallIneeded!=D
May8,2010at6:02AM

Vishalsaid...
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

40/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

HiKen!
I'vebeenplayingwithyourIRRecvDumpexample...the
timingdatamakesmylifeSOmucheasier.BeforeIgot
yourcode,Iwasmeasuringpulsewidthsfrommy
receiverchipusingaoscilloscopeinthelab...
I'mstillhavingtroublewiththeXbox360remote.Ihave
ascertainedthattheremoteusestheRC6IRProtocol,
andIhaveusedaphotodiode/opampsetupinthatlab
withanoscilloscopetoverifythatthetimingdatayour
programreceivesisaccurate,andthatthemodulation
frequencyisinspecforRC6(36kHz).
WhenIpressthepowerbuttonontheXbox360remote,I
gotthefollowingresponse:
800FF40C
DecodedRC6:800FF40C(36bits)
Raw(68):274962750850500350550350550800
5008501400800500400500400500350550
350550350500400500350550350550350
550350950350550350550350500400500
400500350550350550800950800550350
5503505004005004005003501000350500
850500350550
Then,InoticedIgotadifferentresponsewhenIpressed
itagain:
800F740C
DecodedRC6:800F740C(36bits)
Raw(66):140442750800550350500400500
8005508001400800550350550350500400
500400500350550350550350500400500
4005003501000350500400500350550800
9504005004005008001000800500400500
350550350550350500400950400500800
550350500
MyassumptionisthatthiswasthetogglebitthatIwas
seeing.Notingthatyourcodedoesn'tcallthetogglebit,I
figuredthatifIputthefollowingcodeinmysketch,the
ArduinowouldindeedturnontheXbox:
Serial.print("SendingXBOXPower...\n")
for(inti=0i<4i++)
{
irsend.sendRC6(0x800FF40C,36)
delay(50)
irsend.sendRC6(0x800F740C,36)
delay(50)
}
Serial.print("Sent.\n")
Itdidn't.=(
I'vetestedtheLEDcircuitI'musing(IRLEDwithforward
voltage1.2V,andforwardcurrent100mA,inserieswith
39Ohmresistor)withIRcodeI'vewrittenforadifferent
(andmucheasiertounderstand)remoteprotocol,andit
works.Ofcourse,IhaveconnectedtheLEDtodigitalpin
3,asyousaid,soI'mcertainit'snotahardwarefailure.
Iknowyou'vestatedthatyoudonothaveanyhardware
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

41/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

thatsupportsRC5/RC6,andarethusunabletotestthe
codeyourself.However,youappeartobequite
knowledgeableonthissubject,andit'smyhopethatyou
canpointoutsomethingI'veoverlooked.
Thanksagainfortakingthetimetohelppeopleuseyour
software,andcontinuingtorespondtocommentslike
mine.Yourcodeisagreathelptotinkerers(andcollege
EEmajorstryingtofinishtheirdesignprojects)
everywhere.=D
VishalKotcherlakota
B.S.ElectricalEngineering,2010
UCSanDiego
May9,2010at4:57PM

KenShirriffsaid...
HiVishal!LetmetrytoexplaintheRC6togglebit.Ifyou
pressandholdabuttononaremote,thecodewillbe
transmittedmultipletimeswithoutthetogglebitaslong
asyouholddownthebutton.Ifyouthenreleasethe
buttonandpressandholditagain,thecodewillbe
transmittedmultipletimeswiththetogglebitset.Ifyou
releaseandholdthebuttonagain,itwillbetransmitted
multipletimeswithoutthetogglebitset.Thepointofthis
isthatifyou'reholdingdownthepowerbutton,theTV
(orotherreceiver)cantellifyou'vepresseditonceor
twice,evenifthesignalisinterrupted(e.g.someone
walksinfrontoftheTV).
Yourcodefragmentwillflipthetogglebitoverandover,
whichwon'twork.
Ifthetogglebitistheissue,youshouldbeabletosenda
codeonce,butthenitwon'tworkagainunlessyouuse
theremote(whichwillflipthereceiver'sexpectedtoggle
bit).
Idon'tknowifthetogglebitisyourproblemornotthe
36bitXboxcodesareoutsidewhatI'vedealtwith,so
lotsofthingscouldgowrongwiththecode.Maybeif
someoneloansmeanXbox:)
Yousaidyou'reusinganoscilloscopeyoushouldbe
abletocomparethecodestheArduinotransmitstothe
codetheremotetransmitsandseewhat'sdifferent.A
couplethingstolookfor:somereceiversexpectthe
codetobetransmittedmultipletimeswithaparticular
spacing(expeciallySony),soseehowmanytimesthe
remotetransmitsthecodeifyoupressthebuttononce.
Also,makesurethetransmittedcodesarethesame,
especiallyattheend.Iwouldn'tbesurprisedifthere'san
offbyoneproblemandtheArduinoistransmittingone
lastpulsetoomanyortoofew.
Goodluck!
Ken
May9,2010at9:01PM

http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

42/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

TiStylesaid...
Helloguys!
I'mback,butwithanotherquestionthistime...Iwantto
usemultipleIRreceiversandIthoughtitwouldbea
pieceofcake..WhenIwantedtotestthecode,only1of
the2receiversresponded.It'snotthereceiverbecause
I'vealreadyswitcheditwiththepins...Iguessthatthe
codeisn'tcorrect.
********************************
#include
intRECV_PIN=2
intRECV_PIN2=3
IRrecvirrecv(RECV_PIN)
IRrecvirrecv2(RECV_PIN2)
decode_resultsresults
voidsetup()
{
Serial.begin(9600)
irrecv.enableIRIn()
irrecv2.enableIRIn()
}
voidloop(){
if(irrecv.decode(&results)){
if(results.value==0xFF0AF5){
Serial.println("1")
}
Serial.println(results.value,HEX)
irrecv.resume()
}
if(irrecv2.decode(&results)){
if(results.value==0xFF0AF5){
Serial.println("2")
}
Serial.println(results.value,HEX)
irrecv2.resume()
}
May12,2010at4:00AM

ToddTreecesaid...
@TiStyle
IhavejustconnectedthedatapinfrommultipleIR
receiverstothesameArduinoreceivepininthepast.I'm
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

43/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

notsureifthiscouldcauseproblems,butitseemsto
workforme.
May12,2010at10:39AM

TiStylesaid...
@ToddTreece
I'mnotsureifIunderstandyou..WhatI'vedoneisput2
receiversin2differentpinsandonlyoneofthemworks,
butIcan'tfigureoutwhy.
May13,2010at6:58PM

ToddTreecesaid...
@TiStyle
I'msayingIhaveconnectedmultipleIRreceiverstoone
Arduinopin,andIjusttoldtheArduinotolistenonthat
onepinforbothreceivers.Myreceiversareinseparate
rooms,sotheyneveroperateatthesametime.
May13,2010at7:12PM

greenembracesaid...
Hi...
I'mtryoutyourIRstuff,Cangetareponsebutit's
always"0"zero,mutchtomyfrustration.
TheDumpoutputis:
0
Couldnotdecodemessage
Raw(68):905045005501650650500600500
600550600500600550600500650500550
5506001650600165065016006001650600
1650650160060016506005006001650600
55060050065016006005506001600650500
650160060050065016006001650600550600
1650600500600165060039850
andalwaysthesamenomatterwhatbuttonipress,and
ihavetryedanumberofdifferentcontrols.
Anythoughtswhereishouldstartlooking.
regards
greenembrace
May14,2010at1:20AM

KenShirriffsaid...
TiStyle:Thecodedoesn'tcurrentlysupporttworeceivers
ondifferentpins,mainlybecauseIneverthoughtof
implementingthat.Theinterrupthandlerwouldneedto
bemodifiedslightlytocheckthestatusofeachpin,not
justonepin.Maybeinthemythicalversion2.0:)
greenembrace:itlookslikeyourinputisinvertedthe
codeexpectsanactivelowinput,soitcan'tinterpretthe
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

44/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

datait'sreceivingfromyour(NEC?)remote.Areyou
usingsomestrangetypeofIRdetector?Stickinan
inverteranditshouldwork.
May14,2010at10:45AM

TiStylesaid...
@ToddTreece
I'vedidthatbefore,butthat'snotwhatIneed..I'mgoing
touseamaximumof30to50receiversandthey'llall
needanotheridformyproject.Pleasehelp..
May14,2010at10:59AM

KenShirriffsaid...
TiStyle:running3050independentreceiverssoundslike
alot!Itsoundslikeaninterestingprojectdoyouwantto
givemoredetails?
Tooutlinewhatyou'dneedtodotosupportmultiple
independentIRreceivers...
Thecodecurrentlyusesasingleirparamsglobal
structuretokeeptrackofthereceivedcode.Thetimer2
interruptcodechecksthestatusoftheinputpinand
updatestheirparamsstructure.
You'dneedaseparateirparamsstructureforeachpin.
Youcouldhaveanarrayofthem,ormaybehave
irparamspartoftheIRrecvclass.Thearraywouldmake
iteasierfortheinterrupthandler,butputtingitinthe
classwouldbearchitecturallycleaner.Thentheinterrupt
codewouldneedtoloopthroughallofthem,updating
eachoneaccordingtotheinput.
Thenthedecodingroutineswouldneedtoprocessa
particularirparamsstructure,ratherthantheglobalone.
I'mnotsurehowmanyinputsyoucouldprocessbefore
you'drunoutoftimeintheinterrupthandler.
Hopefullythisallmakessenseletmeknowifthere's
anythingelseIcanhelpexplain.
AreyouplanningtouseanArduinoMegatosupportall
theseinputs?
May14,2010at12:10PM

TiStylesaid...
Thiscommenthasbeenremovedbytheauthor.
May15,2010at4:20AM

TiStylesaid...
HeyKen,
Thanksfortheadvice,I'mgoingtotryitoutasfarasI
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

45/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

could.
We'llprobablyuseaMegaormaby2seperated,westill
needtotestitout.We'llbemakingabiglightthathas
about50powerLEDS.You'llhavebeaconsthatwill
emmitapulseandthereceiverswillbeusedasdirection
trackers.Therewherethebeaconis,thelightwillshine
uppon(Soundsabitmythical)...
I'mnotsureifIgetwhatyoumean...Sointhe
IRremote.cpp/.hI'llneedtomakeanarrayforthe
"irparams"?
May15,2010at4:21AM

KenShirriffsaid...
I'veimplementedanewversionofthelibrarywitha
wholebunchofchangesincludingmultipleinputsupport
(TiStyle,thisisforyou),supporttosendandreceive
codesforarbitraryspaceencodedremotes(notjust
NECandSony),andsomeotherfeaturesandcleanup.
Thisisanalphaversionofthecode,soyougettofind
outaboutitherefirst.Ifyouwanttotryitout,goto
http://github.com/shirriff/ArduinoIRremote/tree/dev(the
developmentbranch)andclickonDownloadSourceat
theupperright.
Letmeknowhowitgoes...
May16,2010at9:16PM

TiStylesaid...
Ken...Itworkslikebutter!Thankyousomuch!=D
I'llsendavideooftheprojectwhenwe'refinished.
May17,2010at5:06AM

greenembracesaid...
Hi,Iknowthati'mabitboringtoreplytocomparedwith
theothers,butyouhaveasmallerrorittheIRremote.h
classdecode_results{
public:
intdecode_type//SPACE_ENC,RC5,RC6,
NEC_REPEAT,UNKNOWN
unsignedlonglongvalue//Decodedvalue
intbits//Numberofbitsindecodedvalue
volatileunsignedint*rawbuf//Rawintervalsin.5us
ticks
intrawlen//Numberofrecordsinrawbuf.
classspace_enc_dataspaceEncData
}
valueisalonglong
May18,2010at8:11PM

http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

46/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

tilluigisaid...
wearetryingthisherewithanarduinomegaandcould
getittowork(physically,meaningwehaveoutputonthe
LED)settingthepinModeinthelibrary(asdescribed
hereinthecomments).
howevernomatterwhichhexvaluewe'retryingtosend,
itwillalwaysoutputthesamebitsequence(weareusing
anoscilloscopetomonitorit).weareusingtheRC5
protocoland(meanwhile)thelatestsourcefromgithub.
hasanybodyencounteredthesameproblemoranyidea
whatthecausecouldbe?
May19,2010at12:35PM

KenShirriffsaid...
tilluigi:thelatestgithubcode(dev)isreallyuntestedif
you'rehavingproblems,I'dsuggestusingtheoriginal
codeathttp://arcfn.com/files/IRremote.zip.Also,I
haven'ttriedanyofthisonamega,soIwouldnotbe
surprisedifthereareproblems.TheonlyboardIhaveis
theArduinoDuemilanove,soit'spureluckifthecode
workswithanythingelse.
greenembrace:thanksforlettingmeknowaboutthe
typeissue.Ihopeyourpreviousproblemwithinverted
codesgotsolved.
May19,2010at8:42PM

Cameronsaid...
Iamhavingproblemsgettingtheirrecvdemosampleto
run.Itseemstobecrashingruntimeat
irrecv.enableIRIn()inthesetupmethod.Ihaveonly
modified"intRECV_PIN=6"Doyouhaveanyideas
whatmightbecausingthis?Iamrunningwindows7with
arduino0018(butIhavealsotried0017withno
success).
May22,2010at6:02PM

Cameronsaid...
Iamhavingproblemsgettingtheirrecvdemosampleto
run.Itseemstobecrashingruntimeat
irrecv.enableIRIn()inthesetupmethod.Ihaveonly
modified"intRECV_PIN=6"Doyouhaveanyideas
whatmightbecausingthis?Iamrunningwindows7with
arduino0018(butIhavealsotried0017withno
success).
May22,2010at6:02PM

TiStylesaid...
Ken:
HeyKen,I'mbackwithanotherproblem(I'msosorryto
botheryoulikethis)...Thenewcodeworksfine,butas
soonasIdefine5ormorereceiversthearduinostartsto
laggorsomethinglikethat..Ireallycan'tfigureoutwhat
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

47/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

itis...
I'vecheckedyourlibraryandIthinkourprojectwon'tbe
needingasmuchasyourlibraryhasinit..
Ourprojectisaboutalampthatcanbecontrolledbija
beacon.Thebeaconisthesenderandthebulboflight
hasreceiversinit..Allthereceiverswillbelookingat
otherdirections.ThereceiverthatpicksupaIRsignal,
turnsona1wattpowerLEDinthatdirection.
ThebeaconcanalsocontroltheintensityoftheLEDS
troughapotentiometer.Assoonasthepotentiometer
valuechanges,sodoestheHEXthatthebeaconis
sending...
That'sprettymuchit..Ihopethatyoucouldhelpus,this
isthefinalthingweneedtofix.
Thanksinadvance!
June2,2010at10:44AM

TiStylesaid...
Ken:
HeyIthinkI'vefoundasolution,butI'mnotsure...In
IRremoteHw.cppI'vechangedthe:
#defineSYSCLOCK16000000//mainArduinoclock
To:
#defineSYSCLOCK100//mainArduinoclock
Andsofaritworkswith7sensors,I'mgoingtotestit
withmoretommorow..
June3,2010at8:17AM

PaulShmakovsaid...
HiKen!Thanksalotforalibrary.
JustwantedtoinformyouitworksgreatonTeensy2.0
afteracoupleofmodifications(likemovingtotimer1).
June4,2010at5:04AM

JerryZhengsaid...
thxforthegreatwork.
recommendforabiggerRAWBUF,asmostaircondition
controllersendaIRmessage>100bitseven200bits.
June9,2010at7:03AM

Larrysaid...
Hi,
Thanksforthelibrarycheckoutyusageofithere:
http://luckylarry.co.uk/2010/06/arduinoredefiningthetv
remote/
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

48/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

madeteworkaloteasier:)
Larry.
June13,2010at2:32PM

Milessaid...
HiKen,fantasticworkdecodingandwritingupan
excellentlibrary.
I'mtryingtouseittocontrolaSkyboxintheUKbutI
thoughtI'dtakeaslightlydifferenttakeonit.
Firstofall,theSkyremoteisactuallyRC6Mode6(Not
thatIknowmuchaboutthat).
I'vetakenouttheIRreceiverandattachedittothe
arduinoandrunacoupleofwireswheretheIRC
receiverwasandpluggedthemintothe"TX"pinofthe
Arduino.
Before:
Remote>>>>SkyBox
Now:
Remove>>>>Arduino>>>SkyBox.
YourcoderecognisesoneRC6code(channelup/down)
buttherestcomethroughasunknown.
Itriedthecodeofyourswhichreadsinacodethenlets
yousenditviaTXbutunfortunatelythatdidn'twork.
Doyouhaveanyhintsastowhythismaybefailing?
June14,2010at7:12AM

KenShirriffsaid...
Thanksforallthecomments!
@Miles:YoucouldtrytheIRrecvDumpsketchandsee
what'sgettingreceived.Idon'thaveaRC6remoteso
unfortunatelytheRC6codeisn'ttestedtoowell.
@Larry:interestingprojectI'veaddedalinktoit.
@Jerry:thanksfortheinfo.Iwanttokeepthebuffer
small,though,soitdoesn'tusetoomuchmemory.
@TiStyle:Idon'tknowhowmanysensorsoneArduino
cansupportbeforerunningoutofcycles.Keepme
informed:)
@Cameron:Sorry,noideawhyyou'dbegetting
crashes.AreyouusinganArduinoduemilanoveor
somethingelse?
June14,2010at9:38PM

http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

49/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

silver.smithsaid...
HiKen,
Thanksforthelibrary.
Ihavemanagedtosendandrecievecommandswithit,
butIhaveaproblemwiththeonlycommandIreally
needtosend.Iwouldliketosendtherecord/stopcode
ofmycamcorderasarawircode.Imeasuredthethe
rawircodewithbotharduinoandusbirtoy.AfterthatI
wasalsoablelocatemyremote(canonwl80,notany
regularprotocol)commandsatthelircsite,butIcan't
figureouthowtousethesend.rawcommand.Perhaps
youwouldliketowriteanexample?
BecausemycodingisreallybeginnerslevelandIneed
onlyoneircommand,I'mnottryingtowritethewhole
protocol.
June15,2010at4:56AM

silver.smithsaid...
Forgetmylastcomment,IjustnoticedthelinktoLucky
Larryssite,whereIfoundtheinformationIneeded.Idiot
me...
June15,2010at10:58AM

Milessaid...
@Ken
Yeah,forthemostpartitcannotdecodethemessage.I
thinkthatstandstoreasonasthecontrollerisRC6Mode
6.Sadlydocumentationonthatprotocolislackingat
best.
Frommyunderstandingit'sjustRC6butaccepts32bit
packets.
Here'swhattheIRDumpreceives:
0
Couldnotdecodemessage
Raw(42):2593418003004001050300600350
50035010004009508005503005503001550
3005508009007506503006003001000250
70070055035010003506007505002502050
300
0
Couldnotdecodemessage
Raw(44):79222700900400500350500400950
400950850500350500400500400550300
550850900850500350550400900400500
850450450900400550800500350950400
500400
0
Couldnotdecodemessage
Raw(42):180462700900450500350500400950
400900850500400500350550400450400
500850950800500400500400950400500
3505008001000800500400950400500800
0
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

50/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

Couldnotdecodemessage
Raw(42):114982650900400500350550400
950350950800550400500350500350550
400450900900850550300550350950400
5004005008001000800500400950350550
800
0
Couldnotdecodemessage
Raw(44):38662650950400500400500350950
400950800550350550350550350550350
500850900850550300550400900400550
3505008009508505004005003501000400
450400
0
Couldnotdecodemessage
Raw(44):2979226001050350550350500400
950350950850500400550350500350500
400500850950800500400550350900450
450850950350550350550350500400550
800500350
0
Couldnotdecodemessage
Raw(44):259622650900450450400500350
950450900850550300550350500400500
4005008509008505503505003501000350
550800950350550350550350550300550
850500350
0
Couldnotdecodemessage
Raw(44):42522650950400500400450400950
400950850450400550350700100600350
500850900850500450450400950400500
850950350500400500400500350500850
500400
0
Couldnotdecodemessage
Raw(68):215484450450055017005001750550
1700550600500600550600500600500600
500175055017005001750550600500650500
60050060055055050017505501700500650
5001750500650450600550600500650500
600500600500175055060050017505001750
50017505001700550
0
Couldnotdecodemessage
Raw(68):72144450450055017005501700550
1700550600500600500650500600550550
500175055017005001750550550550600550
55055060050060055017005501700550600
5001700550600500600550600500600500
650500600500175055060050017005501700
55017504501750550
0
Couldnotdecodemessage
Raw(68):72144450450055017005001750550
1700500650500600550600500600550550
550170050017505501750450650500600500
60055065050055055017005501700550600
5001750500600550550550600500600500
650500600550170050065050017505001700
55017005001750550
0
Couldnotdecodemessage
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

51/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

Raw(40):1152625501000300550400550300
100035010007501450300550300650350550
750105070014503501000250650750650300
95035060025011002501000250700300
0
Couldnotdecodemessage
Raw(38):792226009502506503505503002550
600700200500400600250600300550800
95080060030055035010002506507501900
3506502509503001000350
0
Couldnotdecodemessage
Raw(6):5650200275035047002500
June16,2010at8:42AM

KenShirriffsaid...
@Miles:Thosecodeslookmightystrange.Itlookslike
thereareatleastthreedifferentcodingschemesin
there.Youhavesignalsthatstartwithonfor1800us,off
for300onesthatstartonfor2700us,offfor900usand
onesthatstartonfor4450us,offfor4500us.(Lookingat
yourdumpedvalues,startingwiththesecondnumber.)
Thethirdsetlooklike32bitNECcodes,exceptthefirst
onvalueis4450usinsteadof9000us.Trychanging
NEC_HDR_MARKto4450andseeifthoseones
decode.Thefirstcodeismystifying.Itdefinitelydoesn't
looklikethedocumentedRC6protocolsee
http://www.sbprojects.com/knowledge/ir/rc6.htmand
noticethetimingsdon'tmatch.Thefirstcodehastimings
allovertheplace,especiallythe1550usand2050us
values.ThesecondcodelookslikeRC6with24bitsof
data.However,themarks(positivenumbers)areabit
shortandthespaces(negativenumbers)areabitlong
thesensorsI'veseenarealltheotherwayaround.Try
changingMARK_EXCESSto0ormaybe80or100and
seeifthathelps.(TheRC6timingshouldbe444us,but
you'reseeingonfor350400usandofffor500550us.)
June18,2010at12:18AM

CaptainTunasaid...
Thislibraryisgreat.Thankyou!!
nowtothequestion:=):
Iwasthinkingaboutusingboththesendingandthe
receivingfunctionsinasinglesketch(projectwhich
involvesbothsendingandrecevingofIR)andiwas
askingmyself:won'ttheinterruptscalledbythereceiving
functioncorruptthecodebeingsentwithirsend?Thatis,
whenicallthefunctionirsend,dotheinterrupts(called
whentimer1overflows)getcalledalsowhilei'msending
thedata?
June18,2010at2:12AM

Milessaid...
ThanksKen,I'lltakealookatitandseewhatIcancome
upwith.

http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

52/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

What'sthebestwaytosimplyreplaythemessage?
rawSend?
Onceagain,greatwork!
June20,2010at2:24AM

Craigsaid...
IbuiltanArduinosteeringwheeltoIRcontrolcircuitthis
weekendtocontrolanxpressRCiXMsatelliteradio
receiverinmycar.Yourfabulouslibraryandmy
previousexperiencehackingJP1remotesallowedmeto
getmyprojectupandrunninginnotime.
Ididrunintooneissuewithyourlibrarythereisnoway
tosendRC5extendedcodes.Thefixwouldbeto
commentoutthetwolinesthatsay"Secondstartbit"in
IRsend::sendRC5()butdoingthatbreaksanyexisting
codesoabettersolutionistocreate
IRsend::sendRC5X().
I'dalsosuggesttweakingthecommentsto
IRsend::sendRC5():
//Note:firstbitmustbeaone(startbit)
+//Callerneedstotakecareofflippingthetogglebit
+//(whichis1stpassedbit)
voidIRsend::sendRC5(unsignedlongdata,intnbits)
BTW,thecurrentcommentiswrongthecodeclearly
sendsbothstartbits.
Somethinglikethiswouldbeappropriatefor
IRsend::sendRC5X():
+//RC5extended
+//1stpassedbitisthe2ndstartbit/fieldbit/6th
commandbit
+//2ndpassedbitisthetoggle(callerhandlesflipping)
+voidIRsend::sendRC5X(unsignedlongdata,intnbits)
Here'salinktoacontextdiffforIRremote.cpp/IRremote.
June20,2010at8:17PM

Craigsaid...
Ialmostforgothere'sthemacroIcameupwithtobuild
thedatabytesandsendaRC5Xcommmand.(Iactually
expectedtofindsomethinglikethisinIRremote.h!)
/*
*Construct13ofthe14bitsofaRC5extended
command
*
*(the1ststartbitisprovidedbyirsend::sendRC5X())
*2ndstartbit/akafieldbit/aka7thcommandbit
*togglebit
*5bitsofdevice
*6bitsofcommand(OBCformat)
*/
#defineRC5XCODE(dev,obc,toggle)\
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

53/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

((((((((obc)&0x20)>>4)|(toggle))<<5)|\
((dev)&0x1F))<<6)|((obc)&0x3F))
/*XDPR1XMSatellilteRadioremoteRC5devicecode*/
#defineMY_DEVICE27
unsignedchartoggle
/*SendaRC5extendedcommandtotheXMreceiver*/
void
sendrc5(unsignedcharobc)
{
irsend.sendRC5X(RC5XCODE(MY_DEVICE,obc,
toggle),13)
toggle=!toggle
}
June20,2010at8:34PM

CaptainTunasaid...
Sorryfortheabovecomment,ijustnoticedthatyou
havewrittenthatitdoesn'tsupportsimultaneuos
receivingandtransmitting.
Butthatmakesmewanttoaskyousomethingelse:what
doesthatexactlymean?Doesitmeanthatwheniuse
"irsend.sendSony(0xa90,12)"theinterruptwon'tbe
calledwhiletransmissionisbeingsent,ordoesthat
meanthatjustwriting"IRsendirsend"disablesreception
forthewholesketch?Iguessit'sthefirstcase
(=receptiondisabledWHILEtransmitting)evenbecause
ofyourotherprojectwhichreceivescodesfromother
remotesandduplicatesthem.
again,thankyouforthegreatwork!
June21,2010at1:27PM

TomTomsaid...
whatamIdoingwrong?Tryingtoaddmyviewsonic
remote.Iaddedthiscode
CPP/H::::::::::::::::::::::::::::
#defineVIEWSONIC_HDR_MARK9150
#defineVIEWSONIC_HDR_SPACE4400
#defineVIEWSONIC_BIT_MARK700
#defineVIEWSONIC_ONE_SPACE1550
#defineVIEWSONIC_ZERO_SPACE400
voidIRsend::sendViewSonic(unsignedlongdata,int
nbits)
{
enableIROut(40)
mark(VIEWSONIC_HDR_MARK)
space(VIEWSONIC_HDR_SPACE)
for(inti=0i<nbitsi++){
if(data&TOPBIT){
mark(VIEWSONIC_BIT_MARK)
space(VIEWSONIC_ONE_SPACE)
}
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

54/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

else{
mark(VIEWSONIC_BIT_MARK)
space(VIEWSONIC_ZERO_SPACE)
}
data<<=1
}
space(0)
}
Arduino:::::::::::::::::::::::
#include
IRsendirsend
voidsetup()
{
Serial.begin(9600)
}
voidloop(){
if(Serial.read()!=1){
for(inti=0i<3i++){
irsend.sendViewSonic(0xC18F50AF,32)//Viewsonic
TVpowercode
delay(100)
}
}
}
Problemisit'llworkonceevery10triesorso(andonly
turnsoffmytvnoton).Iputituptoaoscilloscope(solar
cellgoingtomycomputer)andIgetabout21hzfrommy
viewsonicremote,butmyarduinoprogramchanges
between10889hz.Yoursonycodestaysatabout19
20hz(sorrydon'tknowifitshz,mhz,orkhz,toolazyto
turnonmyothercomputertosee).
IchangedenableIROut()intbutstilldoesn'twork.AmI
missingsomething?
Ihavethefollowingfromthedumpprogram:
DecodedNEC:C18F50AF(32bits)
Raw(68):77289150440070015007001600700
4007004007004507004007503507501550
65015507004507004506504507001550700
1550700155070015507004007001550700
4007001550700450650450750350750400
700155070040070015507004506501600650
160070015507001550700
June22,2010at10:04PM

CaptainTunasaid...
Onelastthing:aboveitsaysthatthereceiverinterrupt
codeiscalledwhenTIMER1overflows.Ihavechecked
the.cppfileandthereisnosignoftimer1whilethere
clearlyissomethingrelatedtotimer2.Didimiss
something?
June23,2010at6:21AM
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

55/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

KenShirriffsaid...
@TomTom:IlookedattheLIRCfileforViewsonic.I
thinkthemainthingisyouneedtosenda
mark(VIEWSONIC_BIT_MARK)attheendofyourcode.
Youcouldalsotrytweakingyourtimingsabittomatch
theLIRCfile:
http://lirc.sourceforge.net/remotes/viewsonic/RC00070P
butIthinkthemissingmarkattheendistheproblem.
@CaptainTuna:yes,thecodeusesTIMER2.No
simultaneoussendingandreceiving:whenyousenda
codeitdisablesIRinput,andyouneedtocallenableIRIn
tostartreceivingagain.(IdothisbecauseIkeptrunning
intotroublewiththeboardreceivingthecodeitwas
sending,soitseemedbettertojustdoonethingata
time.)
@Craig:Ididn'tknowtherewereRC5extendedcodes
I'lllookintoaddingthemtothenextversion.
June23,2010at5:53PM

TomTomsaid...
ThanksKen!!!Addingmark(VIEWSONIC_BIT_MARK)at
theendofmycodeworked(Ialsohaditloopfrom3to
6)butnowitworkseverytime!Shouldhavenoticedit
fromthedatadump.Thanksagain!
NowIhaveeverythingIneedtocompletemyproject!
June23,2010at9:12PM

Craigsaid...
@KenShirriff:Ididn'tknowtherewereRC5extended
codesI'lllookintoaddingthemtothenextversion.
ThisisthefirstRC5deviceI'veencounteredandI
learnedabouttheRC5extendedprotocolfromthe
PhillipsRC5Protocolpageyoureferenceabove.
@edward:Ireducedyour100msto50msanditworked.
Soyoumightconsiderchangingeyoursamplesnippetto
50msdelaysbetweenpulses.
Isecondthis.Infact,yourUnderstandingSonyIR
remotecodes,LIRCfiles,andtheArduinolibrarypage
givestheminimumpacketgapas45076usandI've
foundthatwiththeSonyequipmentIhave,100msdoes
notworkbut45msdoes.
June24,2010at11:05AM

Craigsaid...
Regardingthenextversion,Ihavesomeideasabout
handingsony12/sony15.Iwantedamacrothatcould
handdeviceandcommand(OBC)values.However
thankstothe"LSBfirst"featureoftheSonyprotocol,this
isahassle.Istartedbywritingcodethatusedareverse
bitroutine:
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

56/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

unsignedlong
revb(unsignedlongv,ints)
{
unsignedlongr
unsignedlongm
inti
m=0
for(i=s1i>=0i){
m<<=1
m+=1
}
r=v
s
for(v>>=1vv>>=1){
r<<=1
r|=v&1
s
}
r<<=s
return(r&m)
}
void
sendsony12(unsignedchardev,unsignedcharobc)
{
unsignedlongcode
/*sony12:7commandbitsand5devicebits*/
code=(revb(obc&0x7F,7)<<5)|revb(dev&0x1F,5)
for(inti=0i<3++i){
irsend.sendSony(code,12)
delay(45)
}
}
void
sendsony15(unsignedchardev,unsignedcharobc)
{
unsignedlongcode
/*sony15:7commandbitsand8devicebits*/
code=(revb(obc&0x7F,7)<<8)|revb(dev&0xFF,8)
for(inti=0i<3++i){
irsend.sendSony(code,15)
delay(45)
}
}
Thisallworksbutit'snotveryoptimal.Iconsidered
writingmacro'stodothebitreversingbutcppisfairly
limitedsoyou'dhavetohaveonedefineperdev/cmd
code,e.g.:
#defineSONY8DEV_10x80
#defineSONY8DEV_20x40
[...]
#defineSONY8DEV_480x0C
#defineSONY7OBC_200x14

http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

57/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

/*sony15:7commandbitsand8devicebits*/
#defineSONY15CODE(dev,obc)\
((((obc)&0x7F)<<8)|((dev)&0xFF))
irsend.sendSony(SONY15CODE(SONY8DEV_48,
SONY7OBC_20),12)
Ithinkthat'sworkablebutitsureinvolvesalotofmonkey
motion.
Mynextideawastomakeasendsonyroutinethat
clocksthebitsoutbackwardsfromtheotherIRroutines.
Thatwaytheuserdoesn'thavetoworryaboutreversing
thebits.Hecanpassthedatain"normally"andthe
routineautomaticallyreversesthebits.Thatworksgreat:
#defineSONY_REPEAT_MS45
/*"Reverse"sendSony()*/
void
sendSonyR(unsignedlongdata,intnbits)
{
irsend.enableIROut(40)
irsend.mark(SONY_HDR_MARK)
irsend.space(SONY_HDR_SPACE)
for(inti=0i<nbits++i){
if(data&1){
irsend.mark(SONY_ONE_MARK)
irsend.space(SONY_HDR_SPACE)
}else{
irsend.mark(SONY_ZERO_MARK)
irsend.space(SONY_HDR_SPACE)
}
data>>=1
}
}
/*sony12:7commandbitsand5devicebits(reversed)
*/
#defineSONY12CODER(dev,obc)\
((((dev)&0x1F)<<7)|((obc)&0x7F))
void
sendsony12(unsignedchardev,unsignedcharobc)
{
unsignedlongcode
code=SONY12CODER(dev,obc)
PORTB=0x20
sendSonyR(code,12)
PORTB=0x00
delay(SONY_REPEAT_MS)
PORTB=0x20
sendSonyR(code,12)
PORTB=0x00
}
/*sony15:7commandbitsand8devicebits(reversed)
*/
#defineSONY15CODER(dev,obc)\
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

58/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

((((dev)&0xFF)<<7)|((obc)&0x7F))
void
sendsony15(unsignedchardev,unsignedcharobc)
{
unsignedlongcode
code=SONY15CODER(dev,obc)
PORTB=0x20
sendSonyR(code,15)
PORTB=0x00
delay(SONY_REPEAT_MS)
PORTB=0x20
sendSonyR(code,15)
PORTB=0x00
}
/*A/Vmute*/
sendsony15(48,20)
sendSonyR()issmallerthansendSony()andit'sstraight
forwardtoassemblecodes.
(Note:Itestedthe"sendthrice"butnotthe"sendtwice"
versionofthecodeyetmyfirst/onlydevboardis
currentlyinthecar!Butmorepartsarrivetoday...)
June24,2010at11:07AM

KenShirriffsaid...
@Craig:Ihavesomebitreversinglogicandlogicto
breakapartSonycodesinthedevversion:see
http://github.com/shirriff/ArduinoIRremote.Butthat's
theoppositedirectionfromwhatyou'redoing
assemblingtheSonycodesfromthecomponentparts.
I'llmergeyourcodeinwhenIhavetime.
Also,foranyoneinterestedinSonycodes,seemyblog
postUnderstandingSonyIRremotecodes.
June24,2010at8:59PM

Anonymoussaid...
I'mtryingthisonmyphotoframe,
andit'sworkingpartialy..TheIRrecordsketchworks,
anditrecognizesitasNEC.
RecievedNEC:1FE7887.
Whenipushthebuttonitsendsitout,perfect..
Butwhatdoidowiththisrecievedcode..itriedtopaste
itinIRsendDemo,igetanerrorinvalidsuffix.
Otherthanmymistakes,itsperfectforwhatiwant,
thanks
June26,2010at8:46AM

KenShirriffsaid...
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

59/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

@anonymous:youneedtoput0xbeforeahexvaluein
C++.I.e.0x1FE7887
June26,2010at5:26PM

Anonymoussaid...
thanksken,
forallyourworkandyourfeedback..
Nowit'sworkinggreat.
I'vegotaPhotoframe,withouttheoriginalremote,but
foundout,byaccident,thatallthosecheapremote's
(fotoframe,usbdbvt,andthe3$remotenuelectronics
sells,etc)haveafewbuttonsincommon..Sowiththe
helpofyourprogram,andalotofdifferentremote'si
testet,imadethecontrolmyphotoframe..Digitaldigital
controlled..
thanks
mies,
thenetherlands
June27,2010at2:16AM

wingstersaid...
hi!
thelibraryworksreallyfinewithsomeofmyremotes,
thankyouverymuch!unfortunatly,mostofmystuffis
controlledwiththepanasonicprotocol...andmyskill
seemsnotgoodenoughtobringthecodepieces
together.
istherea"full"versionofthelibraryavailableincluding
thepanasonicprotocoll?
ifnot,iwilldivedeeperinthecodeandwillfigureout
whyit'ssaying
/Applications/Arduino.app/Contents/Resources/Java/libra
ries/IRremote/IRremote.cpp:625:error:'class
decode_results'hasnomembernamed'address'
atthemoment.
thankyou!
bye
wingster
June28,2010at12:43PM

CaptainTunasaid...
ThanksfortheanswersKen.Igotsomemorethough
(hopei'mnotbotheringyoumuchwiththese):

http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

60/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

1)there'saconstantinyourlibrarycalledGAP_TICKS.If
iwellunderstooditisthemintimebeforetwo
consecutivetransmissions.Whydidyouintroduceit?
Whydoyouwanttohaveaminimumtimebetween2
transmissionsandnotmakethereceiverpick
consecutiveones?
2)whyareyouusingatimeinterrupt?IseethattheISR
routinegetscalledwhentheTIMER2overflows(setat
50us).WhynotusetheattachInterruptofferedbythe
arduinosothatinterruptroutineiscalledonlywhenthe
arduinodetectsachangeinthestateoftheinputpin
connectedtotheIRreceiver(goesLOWfrom
HIGH(idle)),andthenmaybeusepulseintomeasurethe
lenghtsofmarksandspaces?Itsoundsmucheasierto
me,buti'mnotanexpertlikeyousoiamsurelymissing
someCONsaboutthismethod.
June29,2010at3:20AM

Anonymoussaid...
I'vecreatedsometvremotepranksusingyourlibrary
andanIRLEDtosendoutdata.Forexample:iftheyhit
channelup,thearduinowillsendoutchanneldown,and
viceversa.Also,iftheytrytoturntheTVoffthearduino
willturnitbackon.
It'spostedatthearduinowebsite:
http://www.arduino.cc/cgibin/yabb2/YaBB.pl?
num=1277840151
June29,2010at1:10PM

AndrewRosenblumsaid...
I'mnotabletoget2receiverstowork.Itriedcodesimlar
toTiStyles.IfthepinsassignedtoRECV_PINand
RECV_PIN2arereversed,onlythereceiverattachedto
RECV_PINworks.Pleasetakealookatthebelowcode.
Isthereasamplemultiplereceivercode?
/*
*IRremote:IRrecvDemodemonstratesreceivingIR
codeswithIRrecv
*AnIRdetector/demodulatormustbeconnectedtothe
inputRECV_PIN.
*Version0.1July,2009
*Copyright2009KenShirriff
*http://arcfn.com
*/
#include
intRECV_PIN=4
intRECV_PIN2=8
intledPin=13
IRrecvirrecv(RECV_PIN)
IRrecvirrecv2(RECV_PIN2)
decode_resultsresults
voidblinkOnce(){
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

61/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

digitalWrite(ledPin,HIGH)
delay(400)
digitalWrite(ledPin,LOW)
}
voidblinkTwice(){
digitalWrite(ledPin,HIGH)
delay(100)
digitalWrite(ledPin,LOW)
delay(300)
digitalWrite(ledPin,HIGH)
delay(100)
digitalWrite(ledPin,LOW)
}
voidsetup()
{
Serial.begin(9600)
irrecv.enableIRIn()//Startthereceiver
irrecv2.enableIRIn()//Startthereceiver
pinMode(ledPin,OUTPUT)
}
intsuccessCount
interrorCount
voidloop(){
booleangotOne=false
if(irrecv.decode(&results)){
Serial.println("ir0")
gotOne=true
}elseif(irrecv2.decode(&results)){
Serial.println("ir1")
gotOne=true
}
if(gotOne){
Serial.print("type=")
Serial.println(results.decode_type)
if(results.decode_type!=1){
Serial.print("value=")
Serial.println(results.value,HEX)
Serial.print("numberofbits=")
Serial.println(results.bits)
}
if(results.decode_type==1){
blinkTwice()
errorCount++
}else{
blinkOnce()
successCount++
}
Serial.print("successcount=")
Serial.print(successCount)Serial.println("")
Serial.print("errorcount=")Serial.print(errorCount)
Serial.println("")
irrecv.resume()//Receivethenextvalue
irrecv2.resume()//Receivethenextvalue
}
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

62/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

}
June30,2010at8:47PM

AndrewRosenblumsaid...
Ignorelastpost.Theproblemwashardware.The
secondIRreceiverwasmissingits5Vwire.(Yeah,I
knowitisaprettysimplecircuit.)
Thanksforthegreatlibrary.Itmakesmyprojectmuch
easier.
Myprojectistankwar:2remotecontrolbotsthatmove
aroundandcan'shoot'ateachother.Therewouldbe2
4receiverstodetectshotsfromanydirection.Thebots
themselveswouldberemotecontrolled.Thehuman
commandercandrivethetankandshoot.
Technologically,thisisprettysimilartoPolulo'sbeacon,
http://www.pololu.com/catalog/product/701,butIgotthe
ideafromlasertag:
http://www.ibm.com/developerworks/edu/osdwos
arduino1.html
Thelasertaggamesoundslikefuntoo.
Whatareotherpeopleworkingon?
July1,2010at6:58PM

CaptainTunasaid...
Cool!Iamalsoworkingonalasertaggame
(http://www.laserforums.com/forum/showthread.php/466
9ArduinoLasertag).Wecouldjoinforces:=)
..andcurrentlytryingtogetthetransmissionupto56KHz
July2,2010at12:05PM

AndrewRosenblumsaid...
Itried5different38kHzreceivers.Ipicked38kHzfor
compatibilitywithcommonremotes.Theyallworkpretty
well.Themoreexpensiveoneshavebetternoise
suppression,awiderreceptionangleandcanpickup
somereflections.
The56kHzwithashortsignalmightbebetterforlaser
tagtominimizethedeadtimeduringtransmission.I'm
notsureifitmatters.Ihavenotputitalltogethertotest
usability.
I'mnotsurewhich38kHzreceiverisbestforlasertag.
Noisesuppressionseemsgood,butdon'tactuallywant
topickupreflections.
Currenttestcircuitsarejustbreadboardswithexposed
receiverandled.Nextstepwouldbetoorestricthitsto
wellaimedshots.
Iwilladdatubearoundtheled.Alenswouldbebetter.
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

63/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

IntheIBMlinkafewpostsback,alenswasaddedthe
doubledtherange.
Thereceiverhas2Vishayreceivers.I'mnotsurehow
manytouseandofwhatqualityforbestresults.One
suggestiononarduinofourmswastouseasingle
receiverwithanacryliclens.Thelenswouldbeapiece
ofanacrylictubewiththereceiverinthehole.Notreally
surehowthisworks.
Anythoughtsoneitheroftheseopticalfactors:
theledtubeandlens
thereceiverlens
July2,2010at4:30PM

arduEvesaid...
@AndrewRosenblum
Wouldyouhavethepartnumberstothe5different38
kHzreceiversyoutried&couldyoucommentonwhich
turnedoutbetter?
Perhapspostonhttp://www.arduino.cc/cgi
bin/yabb2/YaBB.pl?num=1251570417.
AlsoifanyonewantsmoreroomtodiscussKen'sIR
Libraryheadonovertheretoo.
@Kenmightbegoodtoaddaprominenttotheforumso
thatsomeofthesecommentsmightlandthereinstead.
July2,2010at6:08PM

arduEvesaid...
@Kenmightbegoodtoaddaprominentlinktothe
forumsothatsomeofthesecommentsmightlandthere
instead.
(&Ithoughtiproofread)
July2,2010at6:11PM

JerryZhengsaid...
#defineRAWBUF237//abiggerbufferwasmodified
getarawcodeas:
Raw(194):7300650160060016006001550650
15507001500700150065015507001500700
450600500650500600500650500600500
650500600550600160060016006001550550
16506501550650155055016507001500700
450600500650500600500650500550600
500600550600600160065015506501550650
15007001500700150070015505001650700
450600500600550550550650500650500
600500650500650150070015507001500650
4506501550650155055016507001500700
4506504506505006501550650450650500
6504506505006005005506005501650700
450600160065045065015507001500550
165070015006504506501600650450650
15505006006005506505006001550550600
55016507004505501650650450650500600
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

64/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

160070040065015507004506001550700500
55016007001500650

thenaarraywasclaredas
unsignedintpowerOn[194]=
{650,1600,600,1600,600,1550,650,1550,700,1500,700,
1500,650,1550,700,1500,700,450,600,500,650,500,600,
500,650,500,600,500,650,500,600,550,600,1600,600,16
00,600,1550,550,1650,650,1550,650,1550,550,1650,70
0,1500,700,450,600,500,650,500,600,500,650,500,550,
600,500,600,550,600,600,1600,650,1550,650,1550,650,
1500,700,1500,700,1500,700,1550,500,1650,700,450,6
00,500,600,550,550,550,650,500,650,500,600,500,650,
500,650,1500,700,1550,700,1500,650,450,650,1550,65
0,1550,550,1650,700,1500,700,450,650,450,650,500,65
0,1550,650,450,650,500,650,450,650,500,600,500,550,
600,550,1650,700,450,600,1600,650,450,650,1550,700,
1500,550,1650,700,1500,650,450,650,1600,650,450,65
0,1550,500,600,600,550,650,500,600,1550,550,600,550
,1650,700,450,550,1650,650,450,650,500,600,1600,700
,400,650,1550,700,450,600,1550,700,500,550,1600,700
,1500,65}
so,thefollowingcodeswereuploadedtoarduino
#############################################
######
#include
IRsendirsend
//justaddedmyownarrayfortherawsignal
unsignedintpowerOn[194]=
{650,1600,600,1600,600,1550,650,1550,700,1500,700,
1500,650,1550,700,1500,700,450,600,500,650,500,600,
500,650,500,600,500,650,500,600,550,600,1600,600,16
00,600,1550,550,1650,650,1550,650,1550,550,1650,70
0,1500,700,450,600,500,650,500,600,500,650,500,550,
600,500,600,550,600,600,1600,650,1550,650,1550,650,
1500,700,1500,700,1500,700,1550,500,1650,700,450,6
00,500,600,550,550,550,650,500,650,500,600,500,650,
500,650,1500,700,1550,700,1500,650,450,650,1550,65
0,1550,550,1650,700,1500,700,450,650,450,650,500,65
0,1550,650,450,650,500,650,450,650,500,600,500,550,
600,550,1650,700,450,600,1600,650,450,650,1550,700,
1500,550,1650,700,1500,650,450,650,1600,650,450,65
0,1550,500,600,600,550,650,500,600,1550,550,600,550
,1650,700,450,550,1650,650,450,650,500,600,1600,700
,400,650,1550,700,450,600,1550,700,500,550,1600,700
,1500,65}

voidsetup()
{
Serial.begin(9600)
}
voidloop(){
//alteredthecodejusttosend/testmyrawcode
irsend.sendRaw(powerOn,194,38)
}
#############################################
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

65/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

#########
butitdosen'twork.neither"staticunsignedint
powerOn[194]"
thenaledwasusedtoinsteadoftheIRled,itdosen't
blink.
however,whileuseasmallerarraysuchas"unsignedint
powerOn[10]=
{650,1600,600,1600,600,1550,650,1550}",theled
blinked.
soiguessthatthearraypowerOn[194]wastoobig.
thequestion:howtotackletheproblemrisedbythose
bigrawcodes?
jerry
greatthx
July3,2010at10:58AM

Anonymoussaid...
thankyouverymuch!
thatsagreatlibrary:)
ButIdon'tseeanyinformationaboutthelicenseofthe
sourcecode.Canichangethelibrary,useitinanother
opensourceprojectetc.?!
July3,2010at1:00PM

AndrewRosenblumsaid...
Choiceofreceiverdependsontheapplication.
Myapplicationisatankbotwithanirgun.I'dlikerange
of1020',buttheyshootermustbefairlyaccurate.The
receivershouldwork360degrees.
I'mfairlyenamoredwiththetsop2438and1138.Both
arewonderfulreceiversintermsofrobustnessand
angleofacceptance.Theyseemtoacceptechos.The
2438couldreadasignalfrom31'away,thelengthofmy
livingroom.Itwouldbeagoodchoiceforaremote
controltv.
Today,Iworkedonrestrictingtheshootingangle.The
LEDwillbemountedinacardboardtube.I'mnotsure
howmuchcardboardshieldsIR,butitseemstowork.
Thereaseveralgreatpostsaboutlasertag.Herethey
arelookingfor100300'range.Iactuallyboughta
magnifyingglasstotrythis.ButIcouldnotgetthisto
work.
Lasertagisabitofadistraction,butthetechnologyisso
similarIfeltliketryingit.Besidesusing56kHzsignals,
theymount3setsof3sensorsonahelmet.Iimagine
theyjusttiethesignalpintogetherineachsettosimplify
thewiring.Itriedbothways(connectingthesignalpins
toseparatearduinoinputsandconnectingthemtothe
sameinput),butdidnotreachanyconclusions.IthinkI
willusetheirdesignasitseemsmature.
July3,2010at6:11PM
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

66/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

CaptainTunasaid...
Youareright.Everylasertagsystemi'veseenoutthere
hasthereceiversconnectedinparallel.Iamcurious
abouthavingdifferentpinsforreceptionthough,asit
wouldbequitecool.Itsurelyneedssomemodificationof
thelibrarythough.
July4,2010at1:44AM

CaptainTunasaid...
Heyguys.Imodifiedthelibraryalittle,sothatitcan
sendIRinthebackground.Stillhavetotestitout.Here
iswhati'vedonesofar:

voidIRsend::sendSony(unsignedlongdata,intnbits){
if(irparams.bitstx==0){//ifIDLEthentransmit
enableIROut(40)
irparams.timertx=0//resettimer
irparams.resettx=48//initialheaderpulseis2400us
long.2400/50usticks=
48
irparams.bitstx=nbits+1//bitslefttotransmit,including
header
irparams.datatx=data<<(32bitstx)//unsignedlongis
32bits.datagets
shiftedsothattheleftmost(MSB)willbethefirstofthe
32.
irparams.spacetx=false
TCCR2A|=_BV(COM2B1)//Enablepin3PWMoutput
fortransmissionofheader
}
}

ISR(TIMER2_OVF_vect)
{
RESET_TIMER2
//TRANSMISSION
if(irparams.bitstx!=0){//ifwehavegotsomethingto
transmit
irparams.timertx++
if(irparams.timertx==irparams.resettx){//ifresetvalue
isreached
if(irparams.spacetx){//itwasaspacethathasjustbeen
sentthusa
total"set"(bit+space)so..
irparams.spacetx=false//wearenotgoingtosenda
spacenow
irparams.bitstx=irparams.bitstx1//wegot1lessbitto
send
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

67/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

irparams.datatx<<=1//shiftitsoMSBbecomes1stdigit
if(irparams.datatx&TOPBIT){
irparams.resettx=24
TCCR2A|=_BV(COM2B1)//activatepin3PWM
(MARK)
}
else{
irparams.resettx=12
TCCR2A&=~(_BV(COM2B1))//disablepin3PWM
(SPACE)
}
}
else{//wesentthebit,nowwehaveto"send"thespace
irparams.spacetx=true//wearesendingaspace
irparams.resettx=12//600us/50us=12
TCCR2A&=~(_BV(COM2B1))
}
}
}
....continueswiththerestoftheISRroutine.

thisgoesintheIRremoteInt.h
//informationfortheinterrupthandler
typedefstruct{
uint8_trecvpin//pinforIRdatafromdetector
uint8_trcvstate//statemachine
uint8_tblinkflag//TRUEtoenableblinkingofpin13on
IRprocessing
unsignedinttimer//statetimer,counts50uSticks.
unsignedinttimertx//timerforcounting50usticks
(Tx)
unsignedintresettx//resetvalueforabovetimer
(Tx)
unsignedintbitstx//numberofbitslefttosend
(Tx)
unsignedlongdatatx//datatobetransmitted(Tx)
booleanspacetx//trueifspacehasbeensent(Tx)
unsignedintrawbuf[RAWBUF]//rawdata
uint8_trawlen//counterofentriesinrawbuf
}
irparams_t

Whatdoyouthinkaboutit?Coulditwork.I'lltestitout
tomorrowtoletyouknow.
July5,2010at10:18AM

CaptainTunasaid...
Thiscommenthasbeenremovedbyablog
administrator.
July5,2010at10:19AM

CaptainTunasaid...
Thiscommenthasbeenremovedbyablog
administrator.
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

68/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

July5,2010at10:20AM

andruchasaid...
Woww,IthinkthisisjustwhatIwaslookingfor.
However,Imtryingtosendandreceiveirsignalsinthe
sameapplicattion,andwhenIusetheirsend.sendSony,
itblockstheirrecv.decode(&results),andthenitdoesnt
workanymore...
Doyouhaveanyideawhichismymistake?

#include
intRECV_PIN=11
IRrecvirrecv(RECV_PIN)
decode_resultsresults
IRsendirsend
constintbuttonPin=4//thenumberofthepushbutton
pin
intbuttonState//currentstateofthebutton
voidsetup()
{
Serial.begin(9600)
irrecv.enableIRIn()//Startthereceiver
}
voidloop(){
buttonState=digitalRead(buttonPin)
if(buttonState==HIGH){
for(inti=0i<3i++){
irsend.sendSony(0xa50,9)//SonyTVpowercode
Serial.println("a90")
delay(100)
}
}
if(irrecv.decode(&results)){
Serial.println(results.value,HEX)
irrecv.resume()//Receivethenextvalue
tag=true
}
}
July19,2010at2:20PM

Rabiulsaid...
ThankyoufortheIRlibrary.Ihavedownloadedand
triedit.Iamgettingthe"Couldnotdecodemessage"
error.Ireadthemessagesbysomeotheruserswhoare
alsogettingthisanditisadvisedtouseaninvertertofix
this.
Cananyonepleasetellmehowtouseaninverter?Or
anylinkhavingtutorialonusinginverterwithIRreceiver
modulewouldbenice.
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

69/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

Thankyouinadvance.
July21,2010at2:55PM

Rabiulsaid...
Referringtomyabovemessagethefollowingmessages
wasreceivedbypressing1and2onSonyTVremote:
0
Couldnotdecodemessage
Raw(76):1982030010050100501005010050
100501005010050100150501005010050
10050100345030050100100501005010050
100501005010050100150501005010050
10050100345030050100501005010050100
50100501005010050200501005010050
100
0
Couldnotdecodemessage
Raw(76):3050300100150501005010050100
50100501005010050200501005010050
100501003350300100150501005010050
100501005010050100501501005010050
1005010010033503001001505010050100
501005010050100501005015010050100
5010050
July21,2010at3:09PM

RibeiroSantossaid...
IhaveaSamsungremote,andasthisExcellentlibrary
IRemotehasnt(yet!)adecode/sendsamsung.Using
thatalsoExcellentposthttp://www.maartendamen.com/?
p=257,issimpletoaddthatfuncionallity.Thesend
methodisbasicallythesameasNEC.
Afterfollowtheinstructionsinmaartendamen(wich
decodesthesamsungir),
addinIRemote.cpp:
voidIRsend::sendSamsung(unsignedlongdata,int
nbits)
{
enableIROut(38)
mark(SAMSUNG_HDR_MARK)
space(SAMSUNG_HDR_SPACE)
for(inti=0i<nbitsi++){
if(data&TOPBIT){
mark(SAMSUNG_BIT_MARK)
space(SAMSUNG_ONE_SPACE)
}
else{
mark(SAMSUNG_BIT_MARK)
space(SAMSUNG_ZERO_SPACE)
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

70/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

}
data<<=1
}
mark(SAMSUNG_BIT_MARK)
space(0)
}

AddinIRemote.h

classIRsend
{
public:
IRsend(){}
voidsendNEC(unsignedlongdata,intnbits)
//addthisline
voidsendSamsung(unsignedlongdata,intnbits)

Afterthat,justuse,inyoursketch
irsend.sendSamsung(,32)
byexample,nextprogram
irsend.sendSamsung(0xE0E048B7,32)
July23,2010at12:53PM

weihangsaid...
ThanksKenforthegreatlibraryandWolfgangforthe
PanasonicIRprotocol.Imanagedtocapturethesignal
frommyremotecontrolaftertweakingthemark&space
andmovingtheinlineoffset++outtoalineonitsown,
i.e.
for(inti=0i<32i++){
if(!MATCH_MARK(results>rawbuf[offset++],
PANASONIC_BIT_MARK)){
returnERR
}
becomes
for(inti=0i<32i++){
if(!MATCH_MARK(results>rawbuf[offset],
PANASONIC_BIT_MARK)){
returnERR
}
offset++
Beforemodification,theinlineoffset++adds2tooffset.
Whenoffset++isonitsown,offsetisincrementedby1.
Cananyoneexplainwhytheunaryincrementoperator
behavesthisway?
August3,2010at8:11PM

KenShirriffsaid...
@weihang:you'regettingthedoubleincrementbecause
whentheMATCH_MARKmacroexpandsout,it
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

71/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

evaluatestheexpressionwiththeincrementtwice.You
don'twanttodoanythingwithasideeffect(e.g.++)ina
C++macro.Fordetails,see
http://gcc.gnu.org/onlinedocs/cpp/DuplicationofSide
Effects.html
August5,2010at10:54PM

Jessarelsaid...
hiKen,imtryingtochangethepwmfrompin3topin11
withthismods:
//TCCR2A|=_BV(COM2B1)
TCCR2A|=_BV(COM2A1)
//TCCR2A&=~(_BV(COM2B1))
TCCR2A&=~(_BV(COM2A1))
//pinMode(3,OUTPUT)
//digitalWrite(3,LOW)
pinMode(11,OUTPUT)
digitalWrite(11,LOW)
Butdoesn'tseemstobeworking,
Canyouhelpme
August16,2010at3:09PM

Jessarelsaid...
Solved

TCCR2B=_BV(CS20)
thanks:)
August16,2010at4:37PM

KenShirriffsaid...
@Jessarel:I'mgladyoufiguredouthowtousetheother
timer.Ifyou'relookingformoreinformationonhowto
useotherboardsortimerssee
http://www.pjrc.com/teensy/td_libs_IRremote.htmlwhere
PaulStoffregenhasportedIRremotetomultiple
platforms.WhenIhavetime,I'llmergethisinwithmy
code,butfornow,youcanpickupthemodifiedlibrary
there.
August21,2010at3:45PM

afauchersaid...
Iusedyourlibrarytomakealasertagguncompatible
withthePhoenixLTXseries(Nerf&Tiger).Itdid
howeverrequiredbumpingtheminimumgapfrom5000
to7000
http://executedata.blogspot.com/2010/08/phoenix
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

72/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

ltx.html
August23,2010at10:14PM

bensaid...
Awesomecode,Ken.Thanks!
IthoughtIwouldaddmytwist:IneedtosendIRto2
differentapplicances(TVandcablesettopbox).SoI
needtosendIRoutonpin3(asyoudo)andanother
pin.Thismeansofcourseusinganothertimer(Timer1
forme).
Myresultisbelowforpin9.Itworks,butit'shacked
togetherandIwouldappreciateanyoneimprovingit!
Ben
voidIRsend::enableIROutNine(intkhz){
TIMSK1&=~_BV(TOIE1)//clearsthetimer(Timer1)
overflowinterruptenablebit
pinMode(9,OUTPUT)//Newoutputpinnine
digitalWrite(9,LOW)//WhennotsendingPWM,we
wantitlow
//Alternative,hackedtogetherfromthearduinoeg
(http://www.arduino.cc/cgibin/yabb2/YaBB.pl?
num=1199535681)
TCCR1A=_BV(WGM13)|_BV(WGM11)|
_BV(WGM10)
TCCR1A=_BV(COM1A0)//startthetimer
TCCR1A&=~(_BV(COM1A0))//Disablepin9PWM
output
TCCR1B=(_BV(WGM12)|1)//setthepredivide,inthis
case1=001meansnoprescaling
OCR1A=SYSCLOCK/2/khz/1000
OCR1B=OCR1A/3//33%dutycycle
}

voidIRsend::markNine(inttime){
//SendsanIRmarkforthespecifiednumberof
microseconds.
//ThemarkoutputismodulatedatthePWMfrequency.
//TCCR2A|=_BV(COM2B1)//Enablepin3PWMoutput
TCCR1A|=_BV(COM1A0)//Enablepin9PWMoutput
delayMicroseconds(time)
}
/*Leavepinofffortime(giveninmicroseconds)*/
voidIRsend::spaceNine(inttime){
//SendsanIRspaceforthespecifiednumberof
microseconds.
//Aspaceisnooutput,sothePWMoutputisdisabled.
//TCCR2A&=~(_BV(COM2B1))//Disablepin3PWM
output
TCCR1A&=~(_BV(COM1A0))//Disablepin9PWM
output
delayMicroseconds(time)
}
August29,2010at3:20AM

http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

73/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

Vladsaid...
Wouldanybodybekindtowriteanexamplelineofcode
forsendingakeyforthisremote:
http://lirc.sourceforge.net/remotes/dell/MR425
IhavetriedRC6andraw(withthe"IRrecvDump"
receivedarray),andnoluck.IcanseetheIRled
sendingwithaphotocamera,butIgetnoreactionfrom
thereceiver.
September2,2010at12:27PM

KenShirriffsaid...
@ben:Formoreinfoonusingdifferenttimers,see
Paul'sextensions.
@Vlad:ItlooksliketheDellMR425remoteuses37bits,
whilemycodeonlysupports32bits.Youcouldprobably
changethelibrarytouse"longlong"integers.Areyou
tryingtoreceivecodesfromthisremote,orusethe
Arduinotosendcodes?Toreceive,seemyarticleUsing
arbitraryremoteswiththeArduinoIRremotelibrary.If
you'retryingtosendusingtherawcodes,notethatthe
RC6protocolalternatesbetweentwodifferentcodesfor
eachbutton,soyou'llneedtodothattoo.
September4,2010at11:58AM

Vladsaid...
ThanksforthereplyKen.Iamtryingtosendcodes.
Receivingseemstoworkjustfine.FromalltheremotesI
havearoundinmyplace,Ionlymanagedtosendkeys
toacheapDVDplayerthatusesNECprotocol.Four
otherremotesarenotrecognized.I'vetriedsendingraw
codesfromall,butfailed.
I'venoticedthattherawcodesrecordedfromallofthe
remotesbeginwithtworandomcodes.Forexample,
here'sthesamekeyofthesameremotepressedafew
times(onceeverytwoseconds):
Couldnotdecodemessage
Raw(76):1182634001650500350.....
Couldnotdecodemessage
Raw(76):2000434001600500350.....
Couldnotdecodemessage
Raw(76):568634001600500350......
Couldnotdecodemessage
Raw(76):311234001650450350......
Theyalwaysstartdifferentlyandsometimes,thethird
andforthnumberis(+)or()50.Isthisnormal?
September7,2010at3:58AM

Sethsaid...
cananybodyhelpmesendRawcodes?
IveusedIRrecvDumptogetthefollowingcode:
Couldnotdecodemessage
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

74/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

Raw(76):9200445065050065016006501600
650160065045065016506501600650500700
4506505006504507005006505006501600
6505006504506505506501600600550650
4506501600650160065016506001650650
16006501600650450650500650450700500
6505006504506505007005006501600700
15506501600
HowdoIsendthiscodeusingirsend.sendRAW?
Also,thisremoteislistingintheLIRCdatabase,butitis
obviouslynotrecognizedbythislibrary.CanIusethe
LIRCinformationtoproduceaprotocolforthelibrary?
September18,2010at8:55AM

arunreddysaid...
Firstofalliwouldliketothankyouforsuchawonderful
library.
Amastudenttryingtobuildaarduinoclockwith7
segmentdisplaysdrivenby74hc595.Tryingtosettime
withIRRemote.Theexistingcodeusesaclocktoset
display.IRRemoteisnotgettingdetectedorrathercan
saynotworkingwhilesendingtheserialdata.
Ihavekeptthecodehere.http://pastebin.com/c8BYpeUr
...
Isitbecauseofserialdatapush/ShiftOutcausingthe
issue?Ifyes,anyhelponhowtorectifyit.?
Thanks.
September18,2010at11:56AM

arunreddysaid...
WhenshiftOut()functionisbeingusedinthecodealong
withIRRemotelibrary.TheRecieverdoesntdetectthe
keypressactions.
ShiftOut:http://arduino.cc/en/Reference/ShiftOut
September18,2010at12:05PM

lafssaid...
PleasecanyoushowmeaIRLEDtobuyinorderthe
IRRecordexamplefromIRarduinolibrarytowork.
IalsohavethePANASONICIRReceiveranditworksbut
IneedalsoaIRLEDtosendthesignal.
IHaveArduinoDueminalove328.PleaseshowmeaIR
LEDforthispurpose.
Also,IwanttheIRLEDtoworkwithNEC,RC5/6,SONY,
etc..
Thanks!
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

75/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

September23,2010at4:53AM

GusGrubbasaid...
ThisismyveryfirstArduinoprogram/sketch.My
intentionistocontrolmyAVsystem.I'vetriedthe
Logitechremotes,andlatelyaPhlipsPronto.Intheend,
noneofthemwork.Atleastnotinawaymywifeorthe
childrencanuse.IlookedaroundandfoundtheArduino!
Great.NowIcanwritemyownandaddcontrols/sensors
toseeifthethingsareactuallyworkingthewaytheyare
supposedtoandreportbacksocorrectiveactionscan
betaken.Theidea(likemanyothershere)istoprovide
awebinterfacetoallthissoIcanaccessitallthrough
aniPad.
ThiscodewillparseaProntoHexcodesetandsendit
throughKen'slibrary.
Ken,thanksalot!Yousavedmealotofwork.Feelfree
todoasyoupleasewiththiscode.AsIsaid,it'smyvery
firstsoitmaynotbeallthat.Thefamous:itworksfor
me...
Itriedappendingthecodetothecommentbutitwas
rejectedforbeingtoolarge(beyondthe4klimit).
Instead,I'veuploadedtomyserver.Youcandownloadit
here:IRProntoSend.tgz.
Thanks!
g
September24,2010at11:48AM

GusGrubbasaid...
Oops...thelinkgotmessedup.Trythis(notagsthis
time):http://www.xcreet.com/IRProntoSend.tgz
Thanks!
g
September24,2010at11:53AM

WhiteHexagonsaid...
Wow!afterwastinghalfadaytryingtodecodesomeIR
signalswithmyownArduinocode,I'msogladIcame
acrossyourblog!!I'musingSEN08554fromsparkfun,
andyourlibraryseemstoworkperfectly:)
ThewholereasonformyprojectisIhaveanobscure
remoteformyA/CunitwhichI'mtryingto'record'a
controlfor'playback'atalaterdateviaan950IRled
(COM09349).
IRRecvDumpproduces:Raw(76):434835501650
50012005501200550300550[etc]
Somyfirstquestioniswhatthebestwaytoplayback
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

76/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

thisrawdata.CanIjustputitbackintoanarrayandcall
SendRaw?orwilltheMARK_EXCESSerrorscauseme
trouble.
Q2.Iwouldhavejusttriedtheabove,butIonlyhavea
singleArduino.SoItriedapushbuttononaninterruptto
triggerasendsonycontrol(codefromIRSendDemo).
Howeverthisseemstoblockandstopthereceive
functionalityworking.I'mknowthisisn'tthemulti
threadedworldI'musedtowithJava:)butisthereany
waytomakethesendandreceivecoexist?Iwantto
seeifwhatIsendissimilartowhattheoriginalremote
sent.
September25,2010at6:41AM

Anonymoussaid...
HeyGuys,
WhereshouldiunpackthisonaMAC?Idon'tseeany
filestructureforthearduino/hardware/librariesIam
usinganArduinoMegaandIcanuploadandrun
sketchesonitfinebutwhenItrytorunanexamplefrom
thisproject,itobviouslydoesn'tknowwheretheincludes
shouldbepointingto.IamnewtothissoIapologizein
advancedforbeingstupid.
September28,2010at9:09PM

Carlsaid...
Thisisareallygreatproject!
HasanyonemanagedtogetanXbox360topoweron?I
knowthecodeisRC6:800F740C(36bits),butthat
doesn'tworkusingthecommand
"irsend.sendRC6(0x800F740C,36)".Allmyother
remotesworkperfectlyusingthis.
ThanksalotforyourhardworkKen.
October11,2010at9:10AM

KenShirriffsaid...
Carl:there'ssomediscussionoftheXbox360remote
earlierinthecommentslookfor"Vishal".UnfortunatelyI
don'tthinkVishalgotitworking.Ifanyonewas
successfulwiththeXbox360,pleaseletmeknow.
October12,2010at8:33PM

Carlsaid...
HiagainKen,
Istillhaven'tgotitworking,butIdidmanagetogeta
lookatitunderanoscilloscopetoday.Bearinmind,I
haveabsolutelynoideahowtoworkanoscilloscope,
thiswasthefirsttimeItouchedone,butIdidgetsome
sortofoutput(excusethefactthatthismachinelooks
likeitwasbuiltinthestoneage).
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

77/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

WhatItriedtodowasgettheentirepacketintothe
screenatonce,soit'sreallytiny,butmaybeyou'llbe
abletospotsomething.Ishortenedthecodetojustloop
theXboxcodewithadelay(30),thatseemedtomatch
theoutput.
ThefollowingimagesarethebestIcouldcapture(how
doyoucapturedataontheseoldthings?).
http://imgur.com/a0EF6.jpgARDUINO
http://imgur.com/hhAD5.jpgXBOXREMOTE
Whenyoulookatthese,theylookprettysimilar,but
blurryandsmallashell.I'lltrytogetsomethingbetterto
yousoon.Wehavesomedigitalscopes,buttheywere
beingusedtoday,soI'llhavealookagaintomorrowifI
can.
ThanksKen.
October14,2010at9:37AM

KenShirriffsaid...
Carl:Theoscilloscopetracesareextremelyhelpful.It
lookslikethecodeyouwantis37bitsandyourcodeis
36bits.(Idon'tknowhowyougot36bitssincemycode
onlysupports32bits,soyoumustbedoingsomething
sneaky.)TheotherproblemistheXBOXremote'scode
is0x1001fe8180(ifImanuallydecodedtheoscilloscope
tracecorrectly),whichisentirelydifferentfromthecode
you'resending.Thetimingalllooksgood,soIthink
you'reclose.
October14,2010at11:39PM

Carlsaid...
Helloagain,
Ididn'tgettouseanoscilloscopetoday,butIhavegota
solution(sortof).IgaveuponRC6andwentwithRaw.
So,ifyoudecodetherawfile,assignthevaluestoa
string,andcallthatinirsend.sendRaw(),itwillwork.
Now,theXbox360sends2differentcodesforon/off,so
thiswillonlydooneortheother.I'lldecodetheother
onetomorrow,maybe.
Assignthisoutsideofyourloop:
unsignedintXboxOn[66]=
{2700,850,500,400,450,400,500,850,450,850,1400,850,
450,400,500,400,500,400,500,350,500,400,500,400,450
,450,450,400,500,400,500,400,900,450,450,400,500,40
0,450,850,950,400,500,400,450,850,950,800,500,400,5
00,400,500,400,500,400,450,400,950,400,450,850,500,
400,500}

Thencallitwiththiscommand:
irsend.sendRaw(XboxOn,66,36)
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

78/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

Thatshouldeitherswitchyourxboxon,orswitchitoff,
soyou'llneedaremotetosendtheothercode.
Ken,whatdoyouthinkwouldbethebestwayof
implementingthissowhenthecommandiscalled,this
codeandtheothercorrespondingrawcodeissent?Just
sendthembothfairlyquicklyandhopetheXboxdoesn't
justswitchonandoffagain?
Thanks,
Carl
October15,2010at12:22PM

Anonymoussaid...
HithereKen,I'mhavingafewproblemsgettingthisto
workwithmyTV+DTVbox.Ithinkit'sbecauseofa
weirdprotocolusedbyboth.They'rebothmanufactured
byThomson.
Here'sadumpoftheTVsVol+button:
0
Couldnotdecodemessage
Raw(26):26298700180070018006504350700
43506501850650185065044006001900600
4400650185065018506504400600
Asyoucansee,itappearsthemarksandspacesare
inverted.Wonderingifitwassometingwrongwithmy
wiring,Icheckedasonyremote,anditdecodedfine.
So,isthereawaytoinverttheoutput/IRsendmarksand
spacesincode.
IwanttodoitincodebecausethedongleI'mlookingat
makingwillsendoutthesenonstandardcodes
alongsidesonycodes,sodon'twanttoinverttheoutput
wholesale.
Cheers,
TheCageybee
October16,2010at3:36AM

Anonymoussaid...
HiagainKen.Forgetmypreviouscomment.
SendingthecommandasRAWisworking.Justturnsout
I'mnotgettingmuchpowerfrommyIRLED.
Regards,
TheCageybee
October16,2010at7:51PM

bleiksaid...
Hey
IhaveamacandIdownloadedyourlibraryanddumped
thefileunderarduino/librariesnexttothefilearduino.jar
ThenItriedtoopentheIrRecivdumpandcompilethe
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

79/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

programbutittellsmeVariableorfield'Dump'declared
voidandthefirsterrorlinemessageis
IRrecvDump.cpp:9:22:error:IRremote.h:Nosuchfileor
directory
didiputthezipfileinthewrongplace?andifitiscan
someonecanpleasetellmewheretoputitinamac
thx!!!
October19,2010at10:48AM

AndrewRosenblumsaid...
HeyBleik,
Thefoldertreeis:Documents,Arduino,libraries,
IRremote.Ifhefolderlibrariesdoesnotexist,createit.
ThebitabouttheArduino.jarsoundsfishy,butitcould
justbeajarthatisnotused.
YouhavetobouncetheArduinoIDEtopickupthis
library.
Goodluck!
October20,2010at4:55PM

Saurabhsaid...
IamusingthelibraryforSAMSUNGRemote
(http://www.maartendamen.com/?p=257)anditgivesme
outputasOFFSET3usingtheIRRecvDump:(
October20,2010at6:30PM

Saurabhsaid...
IamusingthelibraryforSAMSUNGRemote
(http://www.maartendamen.com/?p=257)anditgivesme
outputasOFFSET3usingtheIRRecvDump:(
October20,2010at6:30PM

bleiksaid...
HeyAndrew,
Thankssomuchitworked!woop!
October21,2010at8:46AM

NickE.said...
HeyKen,
JustwantedyoutoknowthatI'musingyourlibraryfora
robotthatplayslasertag!
IttakescommandsfrommySONYTVremoteandfires
anIRLED"Cannon"attheotherguy.
It'sworkinggreat!
Yourlibraryisveryeasytouse,savedmenodoubt
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

80/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

countlesshours,andhasn'tcausedmeanytroubleall
quarterlong!
Thankyousomuchforputtingyourworkouttherefor
everyone,andevenmoreforpubliclyhelpingallthese
peopletroubleshoot!
November3,2010at7:52PM

KenShirriffsaid...
HiNickE!Thanksforyourcommentonyourlasertag
robot.Itsoundslikeareallycoolprojectdoyouhavea
linktoit?
Foranyofyouwhohavedoneinterestingthingswiththe
library,pleasesendmealinktoyourprojectandI'll
makealistofprojects.
November3,2010at11:49PM

Rotceh_dnihsaid...
Hayken,
imverynewtoarduinobuthavepickedupyourcode
andhavemanegedtodumpallmyremotecode'sand
playthembackwiththeIRSendDemowithapushbutton
oneatatimebutiwishtohave5pushbutton'seach
sendingadifferntcode,,,ihavetryedtowrightonescript
with2button's(oneforpoweroneforchanup)butwhen
iuploaditonlythefirstonework's
[code]
*/
#include
IRsendirsend
//constantswon'tchange.They'reusedhereto
//setpinnumbers:
constintbuttonPin=2//thenumberofthepushbutton
pin
constintbuttonPin1=4//thenumberofthepushbutton
pin
//thenumberoftheLEDpin
//variableswillchange:
intbuttonState=0//variableforreadingthepushbutton
status
voidsetup(){
//initializetheLEDpinasanoutput:
Serial.begin(9600)
//initializethepushbuttonpinasaninput:
pinMode(buttonPin,INPUT)
pinMode(buttonPin1,INPUT)
}
voidloop(){
//readthestateofthepushbuttonvalue:
buttonState=digitalRead(buttonPin)
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

81/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

//checkifthepushbuttonispressed.
//ifitis,thebuttonStateisHIGH:
if(buttonState==HIGH){
//turnLEDon:
(Serial.read()!=1){
for(inti=0i<3i++){
irsend.sendNEC(0x2FD48B7,32)//MYTVpowercode

//readthestateofthepushbuttonvalue:
buttonState=digitalRead(buttonPin1)
//checkifthepushbuttonispressed.
//ifitis,thebuttonStateisHIGH:
if(buttonState==HIGH){
//turnLEDon:
(Serial.read()!=1){
for(inti=0i<3i++){
irsend.sendNEC(0x2FDF807,32)//MYtvChanup
}
}
}
}
}
}
}
[/code]
thnxinadvance:)
November5,2010at7:49AM

KenShirriffsaid...
@Rotceh_dnih:itlookslikeyouareclosingtheforloop
andtheifstatementinthewrongplace,sothesecond
signalwillonlybesentifbothbuttonsarepressed.You
needtomoveacoupleoftheclosingbracesup.Goto
Tools>AutoFormat,andthecodestructurewillbe
clearer.Letmeknowifamoredetailedexplanation
wouldhelp.
November6,2010at12:32PM

NickEsaid...
Here'salinktoaYouTubevideodemoingmyproject
therobotthatplayedlasertagrelyingheavilyonyour
library:
November9,2010at8:07PM

NickEsaid...
Sorry,thislink:
http://www.youtube.com/watch?v=F8QwoZgwDbw
November9,2010at8:07PM

http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

82/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

Ricksaid...
Ken,isitpossibletoputanIRLEDoneachofthe6
PWMpinsonanArduinoProMini?I'mlookingto
addresseachIRoutputindividually.Theideaistosay
somethinglike:"3,stb,power_on"where3=IRLED#3,
stb=theremote,power_on=thepoweroncommand.
BTWGreatwork!Thanksfortheeffort.
November18,2010at7:52AM

ToddTreecesaid...
Hereisalinktoapagedescribingmyuseofthelibrary
withaniPhoneforanyonewhoisinterested.
http://unionbridge.org/design/ircommand
ThanksforthegreatlibraryKen!
November18,2010at7:56AM

evansaid...
imtryingtodecodearoomlocaterthatsendsIR
signals...
icanttellifitisNECorsonyorwhatexactly..
cansomeonehelp!
thisismydumpvalues
Couldnotdecodemessage
Raw(76):14654950300350250350550400200
3502504003002503004
00200300300350400550250300400250600
300550450300250250
350250300650300250350300300250400
250400200350450100350
5505001503003506003007505050700300
250300350500450350
200350350200350250400
0
Couldnotdecodemessage
Raw(76):15654850300200400300550350250
3003502502504003502
50300300400200400400400400200400550
300600850500250250
300600350300300250350450100350350
300300200350125035025
0350700150600350900350200400650200
2504503002004502003
50250250450850600400250
0
Couldnotdecodemessage
Raw(76):156541000450100400300550350300
300300300300300350
25025040020040020035050200400400
1100400550600650300300
250650300300350250300400200300350
25035025035025065010
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

83/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

00250600350750750250300350250650300
300300450100350350
350200300350300300400450
0
Couldnotdecodemessage
Raw(76):15254950250350300300550350300
3009002504002503004
00200400300300600300300300600300550
850450250300350550
400300300250350850400200300350300
120035035025060030060
02504003002004003003001200300950300
350300250350400504
50550350250350350550350
0
Couldnotdecodemessage
Raw(76):15504950200400250350600300250
4003502503003003003
50300200400250250650350300300300550
350600900300400250
250600400300300250350300300250350
900300250700300300250
4001450950350250350250650200300400
2503502503509003503
00300300550350300350250
0
Couldnotdecodemessage
Raw(76):15404950250400250300600350350
2502504002003502503
50350250250400300550300350200450
1500900300300300350650
200350300250300350300400100400300
35030025065025035035
0250600350650900250300300300650350
2003502503502504003
00300350150450250300600
0
Couldnotdecodemessage
Raw(76):15454900200350250400650250250
4502003002503004003
00300250950650200400300200650400650
850200400250300600
350450150300300350300200400300300
250350300650400150350
3001450950900350600350250350250350
2503503501005003003
00250350550450150300350
0
Couldnotdecodemessage
Raw(76):1465410002503502503501200350
200400250400250300300
3509006002504501050400600900300300
3503006502502503503
00300450150300350300300400200250700
3003001150350600950
2004001150350300350250300350300250
35090035025060035010
0550250145010001000150600350
0
Couldnotdecodemessage
Raw(76):146541000200400300250600350250
400250350200400350
150400300250350250650350300200400
http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

84/85

6/3/2015

AMultiProtocolInfraredRemoteLibraryfortheArduino

60035055090045050400
350550350300300350300300250400200
300350250350300400500
3501200350500600650350400150600400
2004002503503502502
50350300350300250300600
0
Couldnotdecodemessage
Raw(76):156041000200450400200600300250
400250300250400300
250300350250350200750800350600350
650850900350550300300
350350300200300350300300350250400
35035040040040015060
0350550650650250300350600300300300
2504004001003503503
00300300300350600250300
0
November18,2010at3:21PM
1200of804NewerNewest

PostaComment

Linkstothispost
CreateaLink

Service Desk
Software
Simple, Efficient & ITIL-ready.
Setup in 2 mins at $0. Sign up
now!

NewerPost

Home

OlderPost

Subscribeto:PostComments(Atom)

http://www.righto.com/2009/08/multiprotocolinfraredremotelibrary.html

85/85

You might also like