April 10, 2019

WiFi controlled fan - build

Warning: Home appliances have high voltages inside. Danger. Don't attempt a project like this unless you know what you're doing, and take appropriate safety precautions.

See also:
Inside of fan
In the picture above you can see the inside of the fan. Important components:
  • Rotary switch that used to control power to the motor windings (top left)
  • Capacitor to help motor start (black rectangle in top left)
  • Fan motor (behind the fan in the centre - the wires for the motor run up from the fan, obscured by the blade in this picture)
  • AC power cord (bottom)
  • 5V power supply (black rectangle in bottom left - 5V side not yet connected in this picture)
  • Relay board (top right)
  • NodeMCU board soldered to protoboard (bottom right - not yet connected to power supply or rotary switch)
Originally the capacitor was in the top right, but I needed to move it somewhere to make space.

Starter capacitor

This fan also had a mechanical timer switch in the top left. You could turn this, and it would supply power for (say) 30 minutes, and then disconnect the power.

Clockwork timer switch

I figured given this will be run by my home automation system I didn't need a clockwork timer any more, so maybe I could remove it, and move the capacitor there.

Out with the dremel tool. You know you're committed once you start chopping up appliances that were previously fully functional!


With the timer gone, now there was plenty of space to move the capacitor there. Fortunately the capacitor had a long-ish cable.

I needed to figure out how the existing wiring harness connected, plus I knew I would need to get AC power from somewhere. It was time to investigate what was behind these insulation bundles.


Removing the cable tie and the insulation revealed some crimp connectors.


Here brown is active and blue is neutral. I need to patch some wires in here to take AC power for my 5V power supply, so I'm going to need to take those connectors off.

I had a look in my tool box to see if I had any to replace them with, but I don't. Generally I don't trust crimp connectors, and so I solder them anyway. I added my wires to get an AC feed for my power supply, soldered the joins together, added heat shrink, and then put them back in their insulation bundle.

Then the other ends of those wires I added go to the AC in terminals of the 5V power supply.


Again covered with heat shrink, as I don't want any live wires hanging around. Make sure you don't solder to the wrong side of the power supply!

Here is the power supply back inside the fan.


It is loose for the moment, but I will hot glue it into the corner later.


Here you can see how the back of the rotary switch was connected. The connector on the bottom is the input (AC active), and the top 3 connectors are for the 3 different speeds. I tested which colour is connected for which speed so that I know how to wire up the relay outputs later.

The active wire previously connected first to the clockwork timer, and then to the rotary speed switch. With the timer removed I just joined the wires up in its place and put heat shrink over the join.


Now instead of the rotary speed switch, the active wire needs to go to the relay board to be switched on to each of the motor windings.


Here the active wire connects to the common terminal of the first relay, and then to the common terminals of each of the other relays.

The wires from the rotary switch to the motor were not quite long enough, so I needed to extend them, and then cover the join with heat shrink.


I had to buy a hair dryer for the heat shrink. I keep the hair dryer in the bathroom, but I should keep it in the tool cupboard, because I only ever use it for heat shrink.

Now to connect the motor wires to the relays.


Below the relays you can see the opt-isolators, diodes (to protect from back-current) and indicator LEDs.

The black wire goes to the oscillator motor, and then red for high speed, white for medium speed, and blue for low speed.

At this point all my AC wires are connected and insulated. (OK only mostly insulated. More on that later.)

Now it's time to connect up the low voltage logic wiring. I attached the NodeMCU board to some proto board. Although not necessary, I find this useful in terms of soldering.


Here you see red and black on the right to connect to +3.3V/0V for the relay board, and 4 wires for each of the logic level inputs to the board. (One each for oscillate, low, medium and high.)

Now to connect the other ends of the wires to the terminals on the relay board.


The relay board has screw terminals. The high voltage side was fine, but I kept having problems with the low voltage wires falling out. I ended up tinning the ends of the wires with solder, and this helped them stay in the screw terminals more securely.

I don't have the 5V power supply or the speed switch connected up yet, but it's probably worth doing a test to see that everything connects, and that I can still control the relays from inside Home Assistant. Prior to this I only tested the design on a breadboard.


While all my connectors are insulated, the underside of the relay board has exposed connectors from the through-hole components. Although I'm not connecting the AC here, I don't want any short circuits, so I improvised with some paper. (For the finished product I have some electrical insulation tape covering the under side of the relay board, with a layer of insulating foam covering that.)

At power on I get a power light on the relay board. So far so good.

The WiFi connect sequence for my code does a slow flash of the onboard LED while it connects to WiFi, and then quick flash while it logs in to MQTT. Once connected OK the LED goes off. All goes according to plan.

Now to test from Home Assistant. Power on, low power, and the low power relay clicks on! A test of the speed and oscillate combinations shows that the relays are working as expected!

Now to complete the wiring, I soldered wires to the 5V out of the power supply, and connected them to Vin and Ground on the MCU. Note that the NodeMCU board has an on-board voltage regulator, so a supply of more than 3.3V is OK for the Vin pins.

This is how the rotary switch looks.


The red wire goes to +3.3V, which connects to the terminal for high speed. Then a 1k resistor between high and medium, 1k between medium and low. There is actually another 1k resistor between the low terminal and the black wire, but it is hidden inside the heat shrink. I needed the voltage for low to be different to the voltage for off, so I didn't want low to connect directly to 0V. The orange wire connects to the "rotor" of the switch, which connects to the analog pin on the MCU.

Thus the resistors act as a voltage divider. The voltage on high speed is close to 3.3V, with less for medium, and less for low. I checked what reading the ESP8266 reads for each setting so that the code can determine where you positioned the switch, and if you changed it. Note that the ESP8266 itself wants a voltage between 0 and 1V for the analog pin, but the NodeMCU board lets you supply a voltage between 0 and 3.3V. This is handy, as the supply voltage is 3.3V.

You know what? I think I'm ready. Screw it all back together, for a test.

Be careful with AC wiring! We stood clear, turned on the power, and prepared for the release of magic smoke. With the smoke retained, I went to Home Assistant to try to get some airflow.


Thanks heaps to my assistant, and to the maker community at my workplace.

1 comment:

Eb said...

Things I might have done differently:
* Used a more powerful fan. This one works OK, but to be honest, it wasn't a very good fan to begin with. I bought a duplicate set of parts initially, so I can make the same mods to another fan in the future.
* Some kind of status LED on the outside of the case. I know that this kind of sketch is fairly reliable, but if it wasn't working, it would be good to have a blinkenlight to know why.
* Added OTA update. I have to open the case to make code changes.