Wednesday, January 12, 2022

POWER controlled RGB leds for indoor cycling

 Following up on the SMART'ER fan project, I decided to add some lights.

On several occasions, I got fixated by the single LED in the fan, indicating the HR zone, so I though it would be cool to add some RGB LEDs to the pain cave setup (like a Tacx Neo).

This is how it looks like :

Pretty awesome, no??

I now just need to decide on the placement, for now I like the floor lightning, but it can be set anywhere. I am also considering the space within the KICKR climb triangle.

But basically, imagination is the limit here.

What would you need to build one for yourself ? 

Pretty simple ! 

Following on the FAN project, you need the same controller (or another one of them), and same procedure to install things on the PC to program it.

https://randomnerdtutorials.com/installing-the-esp32-board-in-arduino-ide-windows-instructions/


https://www.aliexpress.com/item/32826540261.html

or preferably the M5Stack one ( slightly more expensive).

https://shop.m5stack.com/products/atom-lite-esp32-development-kit

Then you also need and RGB led strip that uses the ws2812b chip.

(Cheapest and most used).

https://pt.aliexpress.com/item/32682015405.html

You can get any size you want, if it is going on the floor, I recommend the IP67 waterproof one, so sweat is not an issue.


Then you need a 5V source ( power bank, phone charger, whatever), wiring is simple.


Connect 5V to ESP32 and to LED strip power pins.

Connect one GPIO from the ESP32 to the "Data" input of the LED Strip.

(Take note of the GPIO pin number, you are going to need to put that in the code, as well as the number of LEDS in your strip).

and ... DONE !!!


(In the future I might consider connection this to the same controller that is on the FAN, as the ESP32 can connect to multiple bluetooth devices at the same time, but as ESP32 devices are cheap, this way you can put this wherever you like, even on the ceiling or using a ws2812b mirror ball. )


Things to note : You need a powermeter, or power source for this. (You can adjust the code for any other parameter, speed, cadence, heart-rate, but the code is setup for power)

The KICKR'18 and newer support 3 Bluetooth connections at the same time, so no issues there.

You can connect it to the LEDs and to the training app you use. 


Some new powermeters also support 3 connections, otherwise, you will need to use ANT+ to connect to your PC, as BTLE will be taken by the leds.

Or, if you have a powermeter on your bike, connect the LEDs to that, and the trainer to the PC/App.


In the code, I am making sure the connection is to a specific device address, that is because I also have a STRYD pod, and the leds were connecting to it instead of the KICKR, as it also has the power capability.

You need to find the address for your powermeter, you can do a bluetooth search with your phone (or open the wahoo fitness app and search for it, and copy paste to the code).

Another option, is to remove that part of the code and the POWER LED will connect to any available cycling power device.


Details are in the readme file.

https://github.com/pauloserra81/powerleds


Smart Fan for indoor cycling

If you cycle indoors, whether you like ZWIFT, RGT, Rouvy, or The Sufferfest / Wahoo SYSTM you know one of the most important thing is ventilation!

You do need one or more big fans, preferably with a remote.

As in the winter, in a cold pain cave, you need to warm up before turning on the fan, otherwise it is not very pleasant.

I use a big cheap generic box store fan, that has plenty of cooling power, but no remote. So I was warming up in a hoodie with the fan on, before taking it off when warm enough.

There was also the question about the fan speed, it has 3 available speeds. Which one to choose ? 

Depending on the workout and what interval it could be too much or too little, so that was the motivation for getting some smartness into the fan.


A bit of online searching, and I found my new friend, a device called ESP32 ! It is a single chip microprocessor that has built in Bluetooth and WiFi.

So basically, you can build stuff and control them wirelessly. It also has lots of GPIO (general purpose) pins for you to connect whatever.

It has everything you need to program it (just connect to a PC with an USB cable), the software to compile the code and program it is FREE, and it has libraries and examples for lots of stuff.

Additionally it is VERY cheap.


To get things setup so you can program it, here is a link to one of the nicest tutorials out there.

https://randomnerdtutorials.com/installing-the-esp32-board-in-arduino-ide-windows-instructions/


One you get that going, lets go over the electrical part.

The generic fan has 3 speeds, so 3 buttons on it, each connect the power supply to a different wire.

What we need are some relays to perform the power connections, based on the controller signals

I got a 4 channel solid state relay board for arduino (5V controllable) on Aliexpress.

(Just take note if your board is HIGH or LOW enable, mine is HIGH enable, if you get a LOW one you need to update the code).

That's all the schematic you need.

Wire one GPIO for each of the fan speeds to the relay board (take note of the GPIO number).

Get a 5V supply (I used an old mobile phone charger), replace the fan switches with the relays, and bob's your uncle.

Here's the fan during testing.


Here it is with the box closed, and the ESP32 left out, as it could not fit.

It is for the better, as it should help BT reception to have the antenna out.


I then found a nicer/smaller ESP32 module, which is the M5Stack ATOM.

https://shop.m5stack.com/products/atom-lite-esp32-development-kit

This has a much nicer look to it, and has an RGB led, so I set that according to the HR zone you are in.

(Like in the above youtube video).

It also has a button you can use. I set it up so that you can toggle between bluetooth control and manual speed, in case you want to use the fan as a "normal" fan with a fixed speed.


This should be all you need to build one for yourself : 

Relay board:

https://www.aliexpress.com/item/4000115910334.html

ESP32:

https://www.aliexpress.com/item/32826540261.html

or preferably the M5Stack one ( slightly more expensive).

https://shop.m5stack.com/products/atom-lite-esp32-development-kit


Source code for this :

https://github.com/pauloserra81/smartbtlefan/tree/main


Check the README file, on what you need to adjust to your case.

If you have any questions on this, or found a bug in the code and know how to fix it, let me know !