Internet Connected Fan for Zwift

4,498

18

2

Published

Introduction: Internet Connected Fan for Zwift

I made a fan that's connected to the internet for use with Zwift, a virtual bike racing game / training system. When u go faster in Zwift, the fan turns faster to simulate outside riding conditions. ;) I had some good fun building this, hope u enjoy building this yourself.

! use these instructions at your own risk, your working with deadly currents, so be careful !

The Zwiftfan was crowned 'Hack of the Month' in the GCN-showand featured on the Zwift Insider blog.

Step 1: Parts & Tools

First you need a fan. I had a fan lying around with 3 different speeds, so that's what i used. If you have one with 2 or 4 speeds you can simply adjust the code that's controlling the fan. But it has to be a fan with buttons. I found this one Amazon. And because i'm Dutch, here is a link to a fan on bol.com that would work. It's going to cost you about $30,-

Then we need a device to connect the fan to the internet and something to control it with. I used a Photon from Particle. The make easy to program IoT devices. The Photon cost $19,- We also need a Relay Shield to control the fan. I used an older model, so it looks a little different, but the new model should work just fine with. Cost $30,- You also need an DC adapter to power the relay shield, thats another $8,-

You also need a computer to run some scripts while using the fan. Because I just Zwift on my macbook, this is what I used building this, so these instructions are for use with a Mac. But if you are good friends with your Windows machine I think it should be possible to get it to work on such a device as well. And if your really nifty you could probably make the script run on a server (or in the cloud), if you do so, please let me now.

Finally, we need some tie-raps, short pieces of wire for high currents, screwdriver(s) en a pair of wirecutters.

Step 2: Hacking the Fan

Open the fan (remove the plug first ;) and be sure to write down the colors of the wires associated with the different speeds (1, 2 & 3) before u begin the next step. Note that there is also a wire connected to the button housing not connected to one of the buttons. This is the wire feeding the power (common). Remove the buttons from the housing and disconnect all the wires.

Notice that each relay has 3 connections to use. NO, NC and COMM. NO stands for Normally Open, NC means Normally Closed en COMM for Common. We want to connect the fan to the NO so nothing happens until we want it to. Connect the wire for speed 1 to the NO on relay 1, the wire for speed 2 to relay 2, and wire 3 on relay 3.

Then connect the common wire to COMM on relay 1 and make a connection from COMM on relay 1 to COMM on relay 2 with a short piece of wire (suitable for 220v) and also from COMM on relay 2 to COMM on relay 3.

I connected the relay shield to the base of the fan with some tie-raps for demo purposes. Best would be to build a housing, because of exposed contacts with 220v on them! Please be careful, especially with kids around!

Step 3: Put the Code on the Photon

Assemble the Photon onto the Relayshield, and power the Relayshield with an adapter (giving between 7v en 20v). The specs can be found here.

After you powered the Relayshield the Photon will come to life and you can connect it to your wifi network. With the Photon device comes a complete set of instructions on how to do this.

Then the Photon needs to run some code to be able to control the relay shield. You can download the latest version of this file, and the other files you need for this project from Github.

Take the code from photon_code_zwiftfan.ino and load it on your Photon. This code makes it possible tot control the relays via the internet. It is not necessary to edit this code.

If needed, there is a great community to help you out if you get stuck!

UPDATE: Sebastian Linz made a better version of the code controlling the fan, u can find his version and manual over here: https://github.com/sebastianlinz/FanControl

Step 4: Install Libraries on Your Mac

We are going to use some libraries to get the data from Zwift, analyses it, and send commands to the Photon to trigger the right relays. We need to install these libraries on our Mac.

  1. Open a Terminal (cmd + spacebar and type Terminal is one way of doing this)
  2. Copy paste each of the next lines into the terminal and hit enter (one by one)
npm install --save zwift-mobile-api
npm install node
npm install request

You could see some warnings (WARN) when installing, but that should be no problem. As long as you don not see errors (ERR!). You have now installed the latest versions of the libraries needed onto your mac.

Credits: this project would not be possible without the great open source (!) Zwift API library from Ogadai

Step 5: Edit the Javascript File

Adding your credentials

Now comes a tricky part. We need to adjust the script that get's the data from Zwift and activates the Photon to make sure it works with your credentials, both for Zwift and the Photon.

  1. have your Zwift credentials (username and password) handy
  2. find your Zwift ID using this online tool made by Christian Wiedmann or alternatifly via this method.
  3. find your Photon Device ID & accessToken

If you have all this, download the javascript file "zwiftfan.js" and open it in a text editor like the free cotEditor. In the image attached you can see what lines to edit and what credentials to enter.

Adjusting Settings

If you want your fan to react on different metrics like your heart rate or power output you can change the mode from 1 (= speed) to 2 (= power) or 3 (= heart rate). You can also change the values at witch the fan switches from speed 1 to 2 or 3 for the different modes.

Saving the script

Once you put in all the credentials, save the document with the same filename in a folder on our mac you can easily remember, like "zwiftfan"

special thanks to roekoe for help writing and debugging the javascript code

Step 6: A Launch Script

You can activate the program by navigating in your Terminal to the folder where you saved it and then type

node zwiftfan.js

and press enter.

But that's not very conveniënt if you are on your bike and forgot to launch the program. And also, sometimes the program will crash (don't no why, if anybody does, please let me know) and the script below will make the program relaunch automagicly. So i made a shell script you can double click.

Navigate to the folder where you saved all the files and rightclick on "start_zwiftfan.sh" in your Finder to get options. Select 'Open with' and 'other'.

At the bottom of the next screen check the box with 'Always open with this program' and choose 'All programs' in the dropdown just above that check-box. Then click the 'Open' button.

One more thing tricky thing;

  • Open your Terminal (CMD + spacebar and type Terminal + ENTER)
  • type;
cd [name of your directory]

press enter and then type

chmod 700 launch_zwiftfan.sh

and enter again.

You now have made a file you can double-click to start our javascript program with the Terminal. Or launch with one click if you put it in your dock. If Zwift is running the Terminal will print the current speed in Zwift every second. If Zwift is not active the script will return errors.

ps. sorry, the screenshots are in Dutch, but i think you will manage. ;) Otherwise you just have to learn Dutch, but don't worry, Dutch is easy! Just say "stroopwafels" and smile.

Step 7: Some Final Words

I hope it all worked in the end. If you have used this tutorial I would love to hear from you and maybe a picture? And if you have any improvements to the project or these instructions, feel free to send me an e-mail at just@justvervaart.nl

Happy Zwifting!

Share

    Recommendations

    • Clocks Contest

      Clocks Contest
    • Creative Misuse Contest

      Creative Misuse Contest
    • Water Contest

      Water Contest

    2 Discussions

    That's a fun idea to link the two :)