This project was to use an ePaper display to display weather information in my lounge room. Really it was an experiment to see what you could do with ePaper, because the ePaper module was an impulse buy while looking around Waveshare's web site.
After connecting up the display to the driver, I powered it on to see the test mode. That seemed to work OK so I tried some code to display the current time.
You cannot really see from the photo, but the display is very thin. Thinner than LCD.
I had thought about designing and 3D printing a case for the display, but that's a bit above my Blender/OpenSCAD skill level. There are a couple of cool cases for similar boards on Thingiverse though.
In the end I repurposed a 6x4" photo frame. I cut a mask out of paper (just as a test), and it kind of looks OK.
The final version of the code has the time and date in the top left; the weather conditions in the centre left; the network status on the bottom left; and then the indoor and outdoor temperature on the right. You can see the source code (along with details on how it gets the temperature updates) at GitHub: https://github.com/eb3nezer/mqtt_epaper
So of course now I have a photo frame with a micro-controller hanging out the back. I had a look around to see if anyone had designed a suitable case, but didn't see anything, so I ended up designing one myself.
I went through a few prototypes:
This is the final model:
The screw holes allow it to be mounted onto the stand of the photo frame:
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.
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.
A word of warning: If you proceed with making this project yourself, you run the risk of electrocuting yourself and dying. Fan motors use high voltages inside. More than enough to give you a serious shock.
See my previous post on what I'm trying to do, and why I chose this kind of fan.
My prototype circuit uses a NodeMCU ESP8266 board, and a 4-way 3.3V relay board to control the fans. The relay board should be able to safely switch the AC voltage your fan uses. (240V in my case.)
The MCU connects to the 3.3V relay board. The inputs for each of the relays connect to one of the digital data pins on the MCU. When the MCU sets that pin to high, the relay turns on. When the MCU sets that pin to low, the relay turns off. The relays will act in place of the original switch on the fan. Instead of sending power to the appropriate motor winding by turning the knob on the fan, the MCU will turn on the relay that connects to that motor winding.
My fan also has a switch for a little motor that makes the louvres on the front of the fan rotate, so I use the 4th relay to turn this motor on or off.
The fan is designed to work with my home automation system. I use Home Assistant, which includes an MQTT message bus. The code will connect to my MQTT bus and listen for updates, changing the relays as appropriate. Home Assistant provides a fan component that can send messages on MQTT to appropriate topics depending on the features of your fan. My code is written to support a fan that has 3 speeds ("high", "medium" and "low"), that can turn on and off (obviously), and that can turn the "oscillate" motor on and off.
My fan uses a 4-way rotary switch. (One of those settings is off, where it doesn't connect to anything.) My circuit diagram above shows 3 switches. How this actually connects will depend on what kind of switch your fan has, but you could mock up something on a breadboard to prototype.
Some fans have push buttons, where pushing one button in pops out any other button that was previously pushed in. In this case there are generally 4 buttons, where 3 of them connect to the 3 motor windings and the 4th button connects to nothing (for off).
The theory seems sound, so I ordered some parts.
These things are cheap and commonly available, but for the sake of illustration I have used Ali Express links.
The final version used a through hole prototype board
Hookup wire
Heat shrink
I wired this up on a breadboard to test. Note that in this picture the speed control switch wasn't connected, so no 1k resistors.
The relay board needs +3.3V and ground from the MCU. I then connected the input lines on the relay board to digital output pins on the MCU. (If you were using an MCU based on a 5V system, like an Arduino, you could use a relay board that needed 5V, which are also readily available.)
Note that although the ESP8266 module runs on 3.3V, the NodeMCU board has an onboard voltage regulator. You can power the board from up to 12V pretty safely. I used a 5V power supply, knowing that this would work fine.
While prototyping I just powered the board from the micro-USB connector connected to the PC.
Check out the README.md in the code to see what configuration changes you might need to make, depending on how you wire up your circuit. It also describes how the code will set up as a WiFi access point initially to let you complete the rest of the configuration via your web browser.
This is designed to work with Home Assistant, and so you need to add the fan component to Home Assistant. The configuration looks like:
Note that the topics you configure in Home Assistant should match the topics you set in the web UI for the fan's access point.
Once installed in Home Assistant the control looks like this;
If you don't include the oscillation topics, then Home Assistant won't give you a control to turn oscillate on/off.
Time to test. Power on turns on the "high" relay. Change the speed to medium turns off the "high" relay, and turns on the "medium" relay. Turn on the Oscillate switch, and the oscillate relay turns on. Power off turns off all relays.
My quest (spoiler: ultimately successful) to smart-ify a pedestal or box fan.
Spoiler: The finished product
Overview
I have a Xiaomi smart socket that could turn my fan on or off at the wall, and to be honest that's quite useful, but I wanted more. I wanted to be able to control the speed remotely as well. Fans are not that complicated right? It should be easy enough to modify the internals of a fan to support this.
My list of requirements:
The solution must work with a fan that is domestically available, and ideally not too expensive.
I need to be able to turn it on and off remotely, as well as control the speed remotely.
Ideally the existing controls on the fan should also work, so it can be controlled manually or remotely.
The first phase of this project was to find out how the speeds of these fans are normally controlled, and how they might be controlled by a micro-controller.
Pulse Width Modulation (PWM) for DC
For a fan that uses a DC motor, PWM might be a good solution. I'm planning on some kind of ESP8266 module as the MCU, and a circuit using the ESP8266's PWM output to switch a suitable MOSFET should work nicely. (I have used this approach for LED lighting in the past.)
While I'm sure they do exist, I looked around for a cheap fan with a DC motor, but didn't find one. I suspect this is partly because fans with 3-speed AC motors are cheap, very common, and they do the job.
If I were to find one, I would still like to build this kind of control. Your maximum speed is when your PWM is at 100% duty cycle. You'd need to do some testing to find out what your minimum duty cycle is for the fan you have. Below a certain minimum and you won't have enough torque to get it started.
PWM for AC
Dimmer circuits often use PWM, but you can't just vary the duty cycle at the 3kHz that your MCU supports. You need to vary it in phase with the AC (50 or 60 Hz). It is possible to get triacs that can switch higher AC voltages (240V for me).
I did explore this option a bit, but there were a few show stoppers for me:
Motors that have windings that suit this kind of control are not commonly used in cheap desktop cooling fans. (Common in ceiling fans though.)
In order to vary the duty cycle in phase, you need a circuit to detect when the voltage crosses zero, so you know when to turn your triac on and off. This is not such a complex circuit, but there's a high voltage side to this circuit, so a bit of extra care is involved. The former point was more of a problem really.
An AC motor with distinct windings
These kinds of motors are very common. The fan has a concrete number of speeds (generally 3). Each speed has its own winding inside the motor. The switch (or knob) selects which winding to supply power to.
What if I swap out the speed switch for a set of relays (controlled by the MCU)? The relays would switch power to the windings. Then if I wire up the original switch as a voltage divider, I can get the MCU to detect the switch position by measuring the voltage. Thus the MCU can change the speed if someone moves the switch.