Z-Wave Ceiling Fan

Goal: adapt a ceiling fan for Z-wave control.

I have a z-wave curtain relay module that needs used. It has a stop signal, open signal, and close signal. The stop is always send before the open or close signal. Each has an associated timer with a default value of 1 s and a range of 1-255 s. After the stop there is a 1 s pause then the open or close signal.

So basically I have an on and an off control, and I need to control the off and three fan speeds. Ideally I'll also retain manual control via the pull chain. My plan is to interface the relay module to a small Arduino and have the Arduino control three power relays for the three fan control wires. Each "on" command will increase the speed, circling back to "off" just like the manual switch. The z-wave off command will turn it off directly. I'll also interface the manual pull chain switch to the Arduino so I'll retain manual control.

Requirements

  1. Manual control for light and fan still works. (achieved)
  2. Power-on state is based on manual switch positions. (achieved)
  3. LED indicators for (LED feedback was unnecessary)
    1. Green when z-wave light toggle ("open") command is HIGH on curtain relay.
    2. Red when z-wave fan increment ("close") command is HIGH on curtain relay.
    3. green and red flash light while curtain "stop" command is HIGH on curtain relay.
    4. Green and red flash when first powered on
    5. Relay board LEDs are visible (objective)
    6. Arduino board LED is visible (objective)
    7. one red flash when fan set to low manually, two flashed for medium, three for high
    8. one green flash when light turned on or off manually
  4. each z-wave curtain "close" command increments fan speed (a better protocol was found)
  5. each z-wave curtain "open" command toggles light (a better protocol was found)

Progress

  1. Took down the fan. Discovered that the electrical box the fan is mounted to needs secured better. It's probably the cause of the noise in the fan.
  2. Hook up temporary light fixture. I was going to temporarily connect just the light fixture part of the fan, but it has special disconnect terminals which I'd have to cut. I'm going to have to hit up a thrift store and grab a cheap fixture.
  3. Map the pinout of the pull chain switch. I used an ohmmeter to measure the relationship between the L switch terminal and the 1, 2, and 3 terminals as the switch is cycled. Turned out to be very straightforward
    1. position 1 - all disconnected
    2. position 2 - L and 1 shorted
    3. position 3 - L and 2 shorted
    4. position 4 - L and 3 shorted
  4. Count the number of digital inputs needed to interface the switch to the Arduino
    1. Need three inputs for the 1, 2, and 3 positions of the fan pull switch (which I'm going to refer to as S1-1, S1-2 and S1-3, respectively).
    2. Need one input for the light pull switch (which I'm going to refer to as S2).
    3. Need three inputs for the z-wave curtain relay module (rwhich I'll refer to as RY1-W, RY1-G, RY1-B).
    4. Need three outputs for the relays to switch the orange, purple and yellow fan control wires (RY2, RY3, RY4).
    5. Need one output for the relay to control the light (RY5).
    6. It would be nice, mostly for diagnostics, to have LEDs to indicate the state of the controller. I can use one LED with a blink pattern to give the light state, and another for the fan state. I thought about providing power state as well, but I don't want it always on, and the other two LEDs will tell me the unit is powered. So that's two more outputs.
    7. I summary, need seven digital inputs and six digital outputs.
  5. Measure the current draw of each of the three power lines. The fan is rated at 0.5 A, so I'm going to assume I need relays capable of at least 5 A.
  6. Select relays and Arduino board and flesh out BOM and order parts. Roboshop had the perfect relay board, so I got everything I needed from them. The curtain module uses 12 V, the Arduino uses from 5 to 12 V, and the relay board needs 5 V. I found a dual output power supply, but it's bulkier than I wanted. I'll probably try to remove the housing. I'll need pull up resistors for SW1 and SW2, and pull down resistors for RY1, but I already have those. I'll need a couple LEDs, but I should be able to scrounge those.
    1. 4-Channel 5V Relay Module Product Code: RB-Ite-04 1 USD$5.78 In Stock USD$5.78
    2. Arduino Pro Mini 328 - 5V/16MHz Product Code: RB-Spa-712 1 USD$9.95 In Stock USD$9.95
    3. Serial Basic Breakout Board - CH340G Product Code: RB-Spa-1408 1 USD$7.95 In Stock USD$7.95
    4. 12V/5V, 2A Power Supply Product Code: RB-Spa-1179 1 USD$9.95
  7. Determine how to fit everything in the fan. I can't install the curtain relay inside the metal fan housing or the z-wave radio won't receive anything. I thought about mounting it on the outside, but I couldn't find a place that didn't interfere with either the fan blades or the light fixture. I decided to add an extension to the fan control housing. I'll use PVC if I can find the right diameter. I'll consider 3D printing it, which would have the benefit of letting me design in the mounts for the electronics.
  8. Draw circuit. Done until I test. Schematic in Fritzing format. Looks like 10k Ohm is typical for the Arduino Pro Mini, so that's what I'm going to use until that proves not to work.
ceiling%20fan_schem.png
  1. Wrote code to control the relays, and tested it successfully.
  2. Interfaced relays to fan, just as in schematic. Works as expected.
  3. Interfaced Arduino to relays, just as in schematic, except for pull-down resistors. Works as expected.
  4. Wrote and tested code to read curtain relay. Worked perfectly.
  5. Interfaced curtain relay to Arduino. Worked perfectly. Discovered that there are three sequences from the three relays: stop/close, stop/open, and just plain stop. So I used this sequence to define a total of 7 functions using a maximum of three relay commands in sequence. The longest sequence is for fan high speed, which is stop/close, stop/close, stop. I tested generating this series on my Homeseer Zee S2 running HS3. Worked great. I put a 1 s delay between the first two commands, and had to put a 2 s delay between the 2nd and 3rd commands.
  6. In Fritzing I fit everything on a surprisingly small perfboard.
  7. Wrote code to read fan and light switches, and to trigger the appropriate action based on those switches. Tested ok.
  8. Tested switch-based control
  9. Interfaced switch to Arduino by soldering a header on the perfboard and replacing the switch wires with leader feeding into that header.
  10. Assembled and soldered on perf board
  11. Added a 200 mA fuse between the RAW input and the 5.16 V power supply. Measured the Vcc as 5.02 V with this setup.
  12. Completed all-up wiring and fully tested it.

Plan

  1. Since I don't need the blue light power wire, I might be able to run the DC power wires in it's place. This would let me mount the power supply up out of the way. My electrical engineer co-worker convinced me to look harder at fitting everything in the existing housing. Looks like I can fit the power supply in the fan housing and run a small gauge wire through to the control housing. If I mount just the zwave relay outside the control housing, I can cram everything else inside, and won't have to fabricate a new housing. But it would be so much more fun to fabricate a new housing now that I have access to a 3D printer.
  2. Measure for and design and print and test fit housing
    1. Draw in Solidworks
    2. test Print critical dimensions with 3D printer
    3. final print
  3. Test
  4. Mount
  5. Install

Lessons Learned

  1. The Arduino Pro Mini 328 might have internal pull-up resistors which could replace the four pull-up resistors.

Bill of Materials

Quantity Part Number(s) Description Cost Each Note
1 ceiling fan with light
7 each SparkFun PRT-14491 (20 pack) 10k Ohm resistor ~0.20 USD
1 SparkFun DEV-11113 Arduino Pro Mini 328 - 5V/16 Mhz ~10 USD
1 SparkFun DEV-14050 SparkFun Serial Basic Breakout - CH340G not part of final assembly
SparkFun PRT-00116 Break Away Headers - Straight
SparkFun PRT-00553 Break Away Male Headers - Right Angle 5 contacts
1 Monoprice Curtain Relay module (discontinued) could be adapted to nearly any z-wave relay module
1 Four power relay breakout board
1 200 mA fuse
1 perf board
18-22 AWG wire
1 custom housing
1 Arduino sketch CeilingFan_1.0.ino
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License