Software apps and online services
I'm a bike enthusiast, but the weather in the winter and job timetable are hard and finally, I took the decision to buy a smart trainer. In this way, I can train for cold and windy days or when I arrive late and it is dark.
Everything is fine and I love my brand-new Tacx Neo smart trainer while playing in Zwift and other virtual worlds. But one thing that I've noted biking indoors is that you sweat a lot. Therefore, absolutely you need a good fan cooler.
Perfect, you can power on the fan when you start your training, but the bad news is until 10 minutes pass you are a bit cold and don't need so much air in the front of your face. So, you must power on the fan at the 10 minutes using a remote (my fan hasn't one) or getting off of your bike and go to turn on it (it isn't a good idea if you are starting a race).
It can be better if you can control it with your voice and/or the speed of the fan follows bike speed. In other words, I'd like the fan to increase its velocity when I go fast, for instance, in downhills, and it stops or it goes slow, when I stop or I go slow. Such as in outdoors, more o less.
In this post I'm going to show how I've made a smart fun cooler with these features:
- It can be controlled by your voice using a mobile or Google Home / Alexa: power on/off and increase/decrease speed
- Automatic mode, where the fan speed follows bike speed using the information is sending by one Tacx Neo smart trainer (of course you need one for this mode)
Below, you can see an overview of the solution:
The hard part of this story has been to find like adjust the speed of a conventional AC fan. For example, one of the following picture.
Yes, I'd like have got a DC fan such as these:
The advantages of fans with a DC motor are you can easily change the velocity and they are quieter. But, they are more expensive than conventional induction driven fans, too. Sadly I haven't one of them and I've had to find out how to adjust the speed of conventional one.
Of course, the typical AC fan can brings some buttons to change its speed. So, one possibility can be open the fan and replace them with relays, so you can control the fan speed connecting and disconnecting remotely these "buttons". But, I'd like to have a solution where don't be necessary open/broke the fan.Speed control
After some looking for in the web, I found some options that are summarized very well in the post: How does a fan speed regulator work?
TL; DR — There are three parameters that you can modify to change the speed of a fan: frequency of supply, number of poles inside motor and voltage or intensity.
The two first are complex to change: frequency arrive fix to the home, and frequency changers are expensive, and to change the number of poles is necessary to change the winding connections of the fan, and this isn't very practical without modify internal fan design.
The most popular solution is voltage control, and we can find different approaches:
- Resistive control: the main drawback is the power dissipation in the resistor and the heat generated.
- Capacitor control: it is becoming popular now a days, and it is very similar to resistive control but less bulky and energy efficient. This is a good alternative to the electronic regulator used in this post, and I'd like to test it in deep when I receive my SonOff IFan02 device. You can be inside details of this device in Tasmota's wiki and here you can see the 2 capacitors and relays.
- Electronic regulator: this is another popular controller, and there are different techniques with this approach. They are described very well in the PhD thesis PWM AC chopper control of single-phase induction motor for variable-speed fan application. You can download and read the full text, a very recommended paper if you are interested in this subject.
Below, I summarize the two main techniques using an electronic regulator approach:
A) Phase Control
This utilizes power electronic devices such as Diac and Triac (they are essentially semiconductor switches). They chops the supply voltage waveform and reduces the effective voltage. Its like turning on/off the circuit at regular intervals (100/120 times in a second). These controllers are called AC full wave regulators. They are energy efficient as losses are negligible. The speed can be reduced by changing how much time the waveform is turned on and off. Fan at lower speeds consumes lesser energy.
The problem with electronic regulators the harmonics created due to the switching. This is because the output waveform is not pure sine wave. In other controllers they are reducing the amplitude of the wave, but here it is abruptly turning on and off the circuit to lower effective RMS voltage. This causes humming sound from the fan. (This situation is similar to the humming when fan is supplied from a square wave inverter where the waveform is square wave instead of sine wave). We wont notice the turning on/off because its done at high switching speeds but can be heard as hum. They may cause electromagnetic interference which is an inherent problem to many power electronic devices. They are compact devices but prone to failure due to voltage surges.
B) PWM control
The PWM control technique simply chops the supply voltage at high frequencies as shown below in figure.
In this post, I'm going to test the following approaches:
- Electronic regulator -Phase Control: using a AC 50/60Hz 220V / 110/V PSM dimmer module.
- Electronic regulator - PWM Control: using a PWM AC Light Dimmer Module 50Hz 60Hz. (PENDING)
- Capacitor Control: using a SonOff iFan02 device. (PENDING)
You can see bellow a simple schematic to connect the dimmer module to the ESP32 micro-controller board.
Here you can download the code to set the ESP32 to control the fan. You must fill in your WiFi SSID and password field at the first of the file, so micro-controller connect a your WiFi network.
The code includes the PubSubClient Arduino library to send/receive MQTT messages. By default, it's configured to use the free HiveMQ Enterprise's MQTT broker and the "smartfan/456787654" topic. You should change it to don't interfere with other users.
You can send message to ESP32 board using a WebSocket MQTT client. Following, I describe main commands:
- Stop fan if you send "stop" (without quotation marks) or a "0" speed number.
- Dimmer 5 to 50% the sinusoidal wave if you send a number between 1 and 10.
I recommend you that test it with several speed values (0, 1, 2... 10). In this way, you can find a good correlation between dimmer wave and fan speed.
Below picture shows an example of using the MQTT client to send command to the ESP32 board.
Pending to receive a PWM AC Light Dimmer Module 50Hz 60Hz.Capacitor module
Pending to receive a SonOff iFan02 module.Voice control
Now that we've controlled the speed of the fan, we can use the voice to start/stop and set the speed range.
To do that I've used IFTTT and a webhook using AWS cloud. So it was easy to connect to Google Assistant / Google Home or Amazon Alexa / Echo dot, to control the device.
Of course, you can develop an Alexa skill too, but using IFTTT is very easy, is useful to and enough for prototyping.
First, we need to configure some applet in IFTTT platform. For instance, we can start configuring an applet to set fan speed using Google Assistant:
1. Configure Google Asssistant trigger with "say a phrase with a number" option and filling a configure value, for instance: "Fan to #"
2. Configure a webhook to call to the API deployed (more details bellow) in AWS to send MQTT command.
Here is the code, using serverless framework, to deploy the API and Lambda in AWS platform. Why do we need it? We need an external API to IFTTT to send MQTT message because webhook only call to the web server and it can't offer a MQTT plugin/action.Automatic mode
Before, we've worked the manual mode, where using MQTT client or voice command we can adjust the speed of the fan. But, it can be smarter if the fan speed if automatic changed in function of the smart trainer's bike speed.
To get this, we can connect by BLE to the smart trainer (I'm using Tacx Neo) to get the speed. The good news are we can reuse the ESP32 board, because of it include Bluetooth Low Energy capabilities too.
Well, Tack Neo publishes Cycling Speed and Cadence service that offers this fields:
- Cumulative Wheel Revolutions
- Last Wheel Event Time
- Cumulative Crank Revolutions
- Last Crank Event Time
To calculate the speed is necessary only the first two fields and set a size for the wheels. I've used the Polar Cycling Speed & Cadence code to avoid me to do calculations and to get the speed in function of the values that the smart trainer notifies.
The final code can downloaded from here.