Tuesday, May 10, 2016

Using a Particle Photon as a small WiFi controlled IR blaster

I have written about using a Raspberry Pi as a Wi-Fi controlled IR blaster. Eventually I was left with just using my LogitechHarmony Hub to control IR devices in my living room. Recently I moved some things around and put my Winix Air Purifier in my bedroom. I no longer had the Raspberry Pi set up and purchasing another Harmony Hub for my bedroom is just too costly.

I purchased two Particle Photon devices that I was going to use for another project which ended up failing. Since they were just laying around, I decided to try and see if I can set them up to be little Wi-Fi controlled IR blasters. And luckily, after a bit of head scratching and cursing, I got it to work!

Quick Introduction to the Particle Photon

The Particle Photon is a small microcontroller that includes built-in Wi-Fi. It is relatively cheap at only $20. Development is pretty simple using their online IDE. From a web page you can code, compile and send it to the Photon. Particle advertises it as a prototyping device for Internet of Things (IoT) products. I think it is a great little device for home automation use.  

Grabbing the hardware

There is not much in terms of hardware that is needed. I got my Particle Photon, a micro USB cable and power supply along with my old SparkFun IR Kit which should still be working with my hacked IR extension cable. I am not sure why SparkFun no longer sells that IR kit, so you may have to look elsewhere if you need something similar.

Set up the Photon

If you have already set up your Particle Photon before, you can skip this section. I used my phone with the Particle app in order to set up the Wi-Fi on the device as I felt it was the easier method. All I needed to do was power on my Photon, install the app on my iPhone and follow the directions. You will just connect the Wi-Fi being broadcast by the Photon and then configure its settings to connect to your Wi-Fi hub. Getting Started.

Programming time on Particle Build!

Now that we have our simple hardware set up, we just need to do a bit of coding.

Head on over to https://build.particle.io and make sure your device is properly set up and registered with your account.

In the Code tab, I created a new app called IRTOGGLE. Then I went to the Libraries tab and searched for the library called IRTRANSMITTER found in the Community Libraries and selected Include in App. I then used the example in the included library to modify my IRTOGGLE.INO file.

// This #include statement was automatically added by the Particle IDE.
#include "IRTransmitter/IRTransmitter.h"

#define IR_PIN D6
#define LED_PIN D7

IRTransmitter transmitter(IR_PIN, LED_PIN);
// Raw data can be sniffed using an IR-receiver and e.g. https://github.com/z3t0/Arduino-IRremote/blob/master/examples/IRrecvDumpV2/IRrecvDumpV2.ino
unsigned int data[71] = {9050,4400,600,500,600,1650,600,500,600,500,600,1650,600,500,600,500,600,550,600,1600,600,500,600,1650,600,1650,600,500,600,1600,600,1650,600,1650,550,1650,600,1650,600,500,600,500,600,1650,600,500,600,500,600,550,550,550,600,500,600,1650,550,1650,600,550,550,1650,600,1650,550,1650,600,40212,9000,2200,550};

void toggleFun(const char *event, const char *data2) {
    Particle.publish("Toggle function triggered!");
    transmitter.Transmit(data, sizeof(data) / sizeof(data[0]));

void setup() {
    if(Particle.subscribe("toggleAirPurifier", toggleFun)) {
        Particle.publish("Successfully subscribed to toggleAirPurifier");

The main focus found here is the data array that contains the IR code for powering my Winix Air Purifier, and the Particle.subscribe command that is used to interact with IFTTT.

Getting the right IR codes

While the programming aspects seemed relatively easy since I was using a library for IR transmission, finding the right IR code for my Winix purifier took some work. I have an old HP USB MCE IR Transceiver which were originally used for Windows Media Center.

Afterwards, I used WinLIRC in order to capture the IR codes from my remote. I first launched winlirc.exe in administrator mode and in Setup set the Input Plugin to be MCEVista64.dll. After configuration, I quit the app and launched Command Prompt in administrator mode. I navigated over to and ran RawCodes.exe. This tool spits out the raw IR codes that the receiver gets. Pointing my Winix purifier remote to the receiver and pressing the power button multiple times, I noticed a pattern where it would repeat.

Based on the original sample code and the codes from RawCodes.exe, it seems to me that every IR code starts with 9000 4400. I right-clicked, selected mark and highlighted the codes to paste into my data array. I realized every device will have a different array size. They will not all be the same. So copy from 9000 4400 until the very last code and set the appriorate array size in your code.

Working with IFTTT and SmartThings

I decided that the easiest way to do Home Automation with the Particle Photon would be through IFTTT. Particle includes a IFTTT channel that provides an ability to monitor changes from the Photon and also push (“publish”) events that the Photon can pick up and act upon.

Because I wanted to be able to control my Winix air purifier through voice with my Amazon Echo, I decided to use my SmartThings hub. On SmartThings Developer I created a virtual switch under My Devices and then set the Amazon Echo to see this switch through the Echo Smart App.

Now on IFTTT I set that virtual switch to push an event called toggleAirPurifier. This may look familiar as it was in my Photon code above with the Particle.subscribe command.

With the setup now complete, I have my Winix air purifier automatically turn on and off based on my SmartThings scheduled routines. It can also be controlled through my Amazon Echo. I could additionally record more IR codes so that I can create a new virtual switch for changing the speeds, but I am statisfied with my current setup.

I hope this article helps those that are looking for a cheap and simple solution for controlling IR devices with home automation!


  1. Fantastic write up! I going to try this myself, do you have any schematics on wiring up the components. I have not much experience of these development boards, so any tip would be welcome. Thanks.

  2. An Excellent article which needs to be highlighted.thanks for sharing an inspiring article. it is very interesting. air purifier

  3. cold storage fort worth FrigiServe is a commercial cold storage warehouse that provides quick freezing, handling, and storage for the food industry. Contact Us.