Photon: Sending Infrared remote control signals

We recently published a post on our blog, showing how to send IR signals on Arduino using simple PWM.

As we recently received our Photon, we decided to update it to cover the photon as well. The photon looks like an interesting platform for IR projects.

The blog is part 2 of a 3 part series covering this method and can be found here:

(Part 1 is also available & Part 3 which shows how to send IR signals from Binary/Hex values will be published soon for both Arduino & Photon)

We have checked the carrier frequencies & duty cycles generated by the Photon using this approach on the scope & the accuracy is fine for 95%+ of projects. (i.e. 30, 33, 36, 38, 40, 56 kHz)

D6 is used for the IR out pin, but you can change it to any other IO pin in the definitions.

You will find a link to the Photon sketch near the end of the post.

Here are some images of the generated signals:

NEC 32 bit IR Signal (With partial repeat visible)

Mitsubishi 88 bit Air Conditioner Signal

The signals were captured with AnalysIR, automatically cleaned & the buffer contents in the sketch automatically generated in ‘C’ format for inclusion in the sketch.

Feel free to ammend the code to suit your own needs.

Spark Core version: Unfortunately as we do not have a Core, we are unable to make a version available.


@AnalysIR, that looks great. I have not been using IR, but am interested.
One think I did not understand, if the Photon sends the infrared PWM, what device(s) will be expected to receive it.
And what distance are we talking (outdoors and indoors).

Thanks, Jack

The simple answer is that it is the same as for any other IR system.

Forget outdoors, due to the sun (unless you really know what you are doing)

Typically, ranges from 5->30m+ at the high end are possible. I havent covered the sending circuitry in this post, but there are lots of relevant posts on our blog and on the Arduino forum.

It is possible to get 100m+ outdoors as in Laser Tag, but again need to do a bit of researching first.

Receiving devices range from TV/STBs/media devices, Air Conditioners, serial comms and other MCUs - no limit really, using an IR Receiver.

In future, we hope to leverage the inbuilt PWM of the Photon MCU - but haven’t researched that yet & not sure if there is a library available for these frequencies yet.

1 Like

Just for an example, I’ve been working on building a one-button television mute control for our son, who has special needs:

I’m not using a Particle for this – it would be overkill. My initial working prototype was done with an Adafruit Pro Trinket, but I eventually hope to get it working with a Digispark, or perhaps even just a raw ATTiny85.

But more generally, this sort of thing is useful to give you programmable control over any items normally controlled by an infrared remote, but that you might not want to hack into directly, for whatever reason (maybe you really don’t want to void the warrantee on your brand new TV?).

One fun use-case might be to have a Photon or Core watch for when your phone connects to the your home WiFi as you arrive home from work, automatically turn on your stereo, and have it start playing your favorite CD. Or turn on the television and switch to the evening news.

1 Like

Sounds great.
Doesn’t each device (TV etc) have its own format coding. How do you handle that?
Do you use the original remote, to train your device?

Nice project. If you need any help let me know or if you would like a free copy of AnalysIR for your project, just contact me via or PM

Some times it might be easier to use bluetooth to detect if a phone enters the home. It is quite easy to detect using cheap BT devices from eBay.(.HC-xx).

You might be interested in the ‘specail’ IR remote control we made for a friend, described here…

and here

Finally, rather than using ATTinys just get a few Nanos for less than $3 incl shipping off eBay & Aliexpress. That means you don’t have to cut corners with limited SRAM/Flash/library support.

1 Like

read up on IRremote & IRLib for Arduino.

follow the navigation at the top for more info

1 Like

Thanks for the great write up! I just got a Core Maker Kit (and am waiting for a Photon) and am working on a project to automate the four window AC units I have scattered around my house. I’m going to be borrowing an arduinio board from a friend tonight and will see if I can get that setup to capture the IR codes from the remotes. I’ve found a few examples of sending IR code from a Core which I’ll then use to try and control the units. I’m planning on sharing the code once I get it all figured out. Your blog should help quite a bit in getting this all working.

Cool :smile:
If you are using an Arduino to capture AC signals, we have a post which has a much better sketch for capturing long AC signals.


It is much more accurate than any of the libraries.

The output can be used with the Photon sketch in this post or any of the Arduino libraries. (However, there are a few limitations with the Arduino libraries for some AC signals)

1 Like


I may have missed it but is the code for sending IR from the Spark Photon that you built available anywhere? I have found other examples for the Core that I was planning on building off of but I’d be interested to see what you came up with.

My current ref material:

I also found this gist which claims direct access to the PWM:

yes, it is linked in the first post of this thread…

…towards the end of the blog post on our website.

I will look at your links later…direct PWM sounds interesting…but it seems it is for the core only…it should be easy for anyone to incorporate that into the sketch we posted and adjust it for the core(unfortunately, we dont have a core to play with)

I’ll start a new project thread when I have something more interesting but I can verify your IR sending code works on a Spark Core without any modifications.

Here is the start of my project:

The IR recorder code is directly from your blog.
The IR sending code is slightly modified with some extra debugging and a safety check for bad IR code data.

With those I managed to capture the on/off button from the remote with an Arduino Uno and then replay that signal to control the AC unit with a Spark Core.

One question I have with the recorded signal, can any sort of rounding be applied? My current approach is to capture the same signal a bunch of times and then average each value.

Good to hear, it also works on the core - thanks for the update. However, I suspect that the carrier frequency will be off a wee bit more (on the core), but as you said quite usable. It should be easy to tweak for anyone with an oscilloscope.

Averaging the signal timings is OK, but in reality what you end up with is an ‘average of the errors’, which can be better than just one sample.

IR receivers introduce distortion/lag. We have a blog post explaining it here:

With AnalysIR and our soon to be released IR Learner device, we have a pretty cool ‘auto-clean’ feature which automatically cleans/corrects a large range of signals to 100% accuracy.

BTW: That sketch for recording long IR signals ‘should’ also run on Photon & Core, by adjusting the definition for the LED pin & amending the attachInterrupt statements, appropriately.

You’re right the IR recording sketch works with a few minor tweaks on the Core. I updated my git repo with the Core version of the code.

The blog you linked got me reading more about the NEC protocol (which my AC units use) and summing each mark+space pair does make it much easier to determine the bit string. It looks like the Frigidaire controller is sending 32bit NEC codes with a repeat code, though some basic testing has shown that repeat code isn’t required by the AC units.

All of that will make capturing and programming the codes MUCH easier.

@AnalysIR Thanks heaps for your great work! I’m looking to implement this into a new project that I’m working on. Just wondering though - when do we expect to see part 3? Cheers!

Hopefully in the next few weeks - time permitting.

In the meantime, using the mark space functions (in the part 2 sketch) it should be relatively easy to build your own signals from binary/hex values.

1 Like


We have just published part 3 in the Series, which shows how to send IR signals at carrier frequencies of 30, 33, 36, 38, 40 or 56 kHz at a duty cycle of circa 33%, using an updated softPWM approach.

The code has examples for sending RAW NEC & Mitsubishi 88 bit AC signals and also the same signals generated from their Hex representations and can use any IO pin for sending IR.

The code is explained in the posting and we have include a slightly different source code for the Photon along with the original Arduino code.

The carrier frequencies above were calibrated for Photon using an oscilloscope, by adjusting the trim values (in initSoftPWM).

Any one wishing to port for the Core (or any other platform for that matter) only has to adjust the periodHigh & periodLow trim values in the initSoftPWM function. If you dont have a scope, you can just use any IR receiver and adjust until it works.


Great! Thanks for the update! Sorry, I haven’t been on for a while. I’ll be sure to have a play around! :slight_smile:

also check out our updated post, for better IR performance on photon etc

Hi, so I’ve finally got time to get back into this again (holidays!) and have hit a bit of a wall. I’ve successfully captured my IR signals from my remote with AnalysIR and got codes like the following:

irsend.sendNEC(0x00FFA15E, 32); //AnalysIR Batch Export (IRremote) // AnalysIR IR Protocol: NEC, Key:  Input

Using the basic code below in an Arduino with IRLib I can get my audio system to change input every second (just for testing purposes):

    #include <IRLib.h>
    IRsend My_Sender;
    void setup() {
    void loop() {
    My_Sender.send(NEC,0x00FFA15E, 32);
    delay (1000);

The thing that has me completely stuck is now moving away from Arduino to the Photon. The Photon doesn’t accept this code (even with relevant .h files included) which is the behaviour I expected.

I’ve been trying to find ‘getting started’ tutorials etc and been reading up on the three tutorials above but to be honest I don’t actually know what I’m doing! Are you able to point me in the right direction?

Thanks! :smile: