Introduction: Voice Control of a Ceiling Fan With Alexa

Picture of Voice Control of a Ceiling Fan With Alexa

In this Instructables, we will use a Particle Photon (Arduino compatible) microcontroller coupled with a 315MHz RF Transmitter to send commands to a Harbor Breeze ceiling fan. We will then learn how to use an Amazon Echo and Alexa to activate our fan using voice commands. The ultimate goal is to be able to turn on the fan by saying: "Alexa, trigger fan on".

Acknowledgments:

Reverse Engineer RF Remote Controller for IoT! by veggiebenz

RF 315/433 MHz Transmitter-receiver Module and Arduino by Mohannad Rawashdeh

Home Automation using Particle and Amazon Echo by Krishnaraj Varma

Step 1: You Will Need...

Picture of You Will Need...

Step 2: Connecting the Photon to the RF Transmitter

Picture of Connecting the Photon to the RF Transmitter

The MX-FS-03V RF Transmitter module can be found in 2 frequencies, 315MHz and 433 MHz. I used the 315 MHz to match our ceiling fan frequency.

The RF module requires only 3 wires: GND, VCC and DATA. We will connect the GND pin to pin GND and VCC to VIN of the Photon. The signal pin DATA will be connected to D0 of the Photon.

Additionally, you will want to attach an antenna to the module to get better range. A 13cm (5") straight wire soldered to the ANT hole should do the trick.

Thanks to veggiebenz's Instructable, we are able to transmit RF commands to the fan by sending a pattern of 0s and 1s to the D0 pin configured as a digital output; no library is required.

Step 3: Software

Picture of Software

We will assume that you have already gone through the steps to create your particle account and activate your photon device. In the rest of this Instructable, we will also assume that you named your Photon device "fantastic" (lame, I know). See the getting started link on the particle web site for more information on how to do this.

Open the Particle Build web site and login to you account. Create a new project by entering a title ("fantastic" in this example). Download the software and add the 3 files to your project (Hint: to create the fantypes.h and fantypes.cpp files, use the small + icon at the top right of the toolbar). I used the fantypes.h file to store the signal patterns and other constants.

Step 4: Verify the Hardware

Picture of Verify the Hardware

To verify that the Photon can now control your fan, let's create a new DO button using IFTTT's DO app (downloadable from your phone's app store). To create the recipe, click the "Recipe" icon at the bottom right of the screen, click the + sign, click the Channels tab, click the Particle icon, click Create a New Recipe, click Publish an event, call it FAN ON, select FanControl on "fantastic" for "Then Call" (Function Name) and enter "2" (or any preferred speed) for "With input (Function Input)".

Click the DO button to turn the fan on. The fan should turn on. Make sure you have attached or soldered a 13cm wire antenna to the RF module or you may have to bring the module in close proximity of the fan for this test.

Step 5: Alexa Voice Commands Via IFTTT

Picture of Alexa Voice Commands Via IFTTT

The simplest way to enable Alexa to control our particle device is to create an applet in IFTTT (If This Then That). IFTTT provides an Alexa Channel. Start the IFTTT app on your phone, click the "My Applets (used to be called recipes) and click the + icon at the top right of the screen to create a new applet. Select the Alexa channel (you will need to provide your Amazon credentials to allow IFTTT to communicate with Amazon) and choose the trigger "Say a specific phrase". Select a phrase such as "fan on" (use all lower case). The rest of the setup is similar to the DO button setup, where you select the Particle Channel for the THAT part of the applet.

That's all that is required. Try "Alexa, trigger fan on" to turn the fan on. Add other commands such as "fan off" or "light on" for additional functionality.

This is pretty much the easiest way to achieve voice control. In another Instructables, "Controlling your Photon device with SmartThings and Alexa", we will take a look at another method that involves SmartThings and that allows you to say "Alexa, turn on the fan" instead of the more awkward "Trigger fan on".

Comments

jonfitt (author)2017-08-08

The remote has a 0/1 switch and a Learn button that pairs the remote.

How are you dealing with that?

macgeek made it! (author)2017-02-17

I hacked the remote, using relays to 'activate the buttons' more brute force, but same results :)

Great job!

WilliamF163 (author)2017-02-10

After compiling a few times it works. Works well thank you. Do you know how to shut light off?

tareker (author)WilliamF1632017-02-11

Congrats! For the light, it is just a matter of sending "light" instead of "2" when creating the DO button. Take a look at the fantControl function in the fantastic.ino file for the complete list:

"light"
"off"
"0"
"1"
"2"
"3"
"4"
"5"
"6"
"random_fan"
"random_light"
"delay"
"2H"
"4H"
"8H"
"summer"
"winter"

WilliamF163 (author)tareker2017-02-11

Yes when light is sent it does turn on at lowest brightness, every time light is sent the light gets brighter. But no way to turn light off. If you send off it just stops the fan. So I am guessing the light signal you have is for the light to turn on and then add 1 to the brightness.

WilliamF163 (author)2017-02-09

I have started this project and get the following code errors:

In file included from fantastic.cpp:3:0:

fantypes.h:4:5: error: 'boolean' does not name a type
boolean power;
^

fantypes.h:10:35: error: too many initializers for 'const signal'
const signal SHORT_ON { true, 400 };
^

fantypes.h:11:37: error: too many initializers for 'const signal'
const signal SHORT_OFF { false, 500 };
^

fantypes.h:12:34: error: too many initializers for 'const signal'
const signal LONG_ON { true, 850 };
^

fantypes.h:13:36: error: too many initializers for 'const signal'
const signal LONG_OFF { false, 950 };
^
fantastic.cpp: In function 'void transmit(signal*)':
fantastic.cpp:17:52: error: 'struct signal' has no member named 'power'

^

fantastic.cpp:21:45: error: 'struct signal' has no member named 'power'
void transmit(signal array[16] = sig_preamble) {
^

fantastic.cpp:24:39: error: 'const struct signal' has no member named 'power'
for (int pre = 0; pre < 32; ++pre) { // Preamble
^

fantastic.cpp:26:40: error: 'const struct signal' has no member named 'power'
delayMicroseconds (sig_preamble[pre].duration);
^
LeoZ12 (author)2017-02-01

is there an easy way to clone the RF signal from the remote?

coolcash (author)2016-12-15

Do you know if any other resources for fan frequencies and data for the fans? I tried "decoding" my signals, but it seems too difficult for my brain/time schedule.

tareker (author)coolcash2016-12-16

Beyond veggiebenz's Instructable, I do not. But you still have the option of controlling your remote using the microcontroller and sending the signals that way. Good luck!

kylegilbert (author)2016-11-29

This is very cool!