DIY Peloton: Cadence and Resistance Sensors, Speakers - Powered by Raspberry Pi Pico

DIY Peloton project - created a smart exercise bike with cadence and resistance sensors and a built-in speaker. Powered by a Raspberry Pi Pico

DIY Peloton: Cadence and Resistance Sensors, Speakers - Powered by Raspberry Pi Pico

In the past year I've been using an exercise bike at home and really enjoy it. It's not quite a Peloton, but it also cost about $2000 less than a Peloton. I enjoy using it with the Peloton digital subscription, but it is a bummer not having the same sensor statistics, making the experience less interactive.

I decided to work on turning my dumb bike into a smart bike in order to enhance the experience. It's been an interesting journey so far and I think I've finally settled on the design, and am now focused on tuning the software. Read on for details of the build so far.

Smart bike sensor schematic

Starting with the simplified schematic, you'll notice the design includes a 2S 3.7v Li-ion battery pack. I decided to include batteries so I didn't have to have a wire leading up to the bike that might get tripped over. This is probably optional for a lot of people, depending on where you place your bike.

Supplies

Power Supply

Audio/Speakers

Microcontroller/Sensors

Tools

Enclosure

I started out by building out the enclosure. I had a metal box from some candy (peppermint bark, I think it's called?) that looked like a nice size for this, so I decided to turn it into an enclosure using aviation snips, a hole punch, and painting with black spray paint.

Here is a photo album of the enclosure build:

Enclosure build

My main takeaway from the enclosure build was planning. I decided to kind of wing it, and didn't pre-plan much about placing, sizing, etc. For my next project, I'll definitely be much more deliberate about measuring dimensions and placement of components.

Power Supply

I included an integrated Li-ion battery pack so I wouldn't have to have the bike connected to the wall all the time. I first started out using 18650 batteries but decided to switch them out for 18500 batteries mid-project. I didn't know that form-factor existed, but they are basically the same exact battery, just shorter, and with less capacity on average.

SAFETY WARNING: If you don't have a spot welder, please understand that soldering Lithium ion batteries is very dangerous and is in no way recommended, no matter how often it is done in DIY scenarios. I made sure not to apply heat to the battery terminal for longer than 3-5 seconds. If you haven't done this before and are not 100% sure you know what you're doing, do not do it.

Battery Pack/Power Supply

The integrated charger is set to provide 8.4V (for charging 2 Li-ions to max 4.2V), with a maximum current of 700 mAH, and with a Schottky diode at the positive terminal of the output to prevent the charger pcb from powering its LED from the batteries when there is no voltage applied to its input.

Sensors

Battery voltage for fuel gauge

As you might have noticed in the power supply album, a yellow lead was added at the positive terminal of the battery pack. This is used to measure the current voltage of the battery pack for a fuel gauge monitor for the controller.

If you are looking to include this in a design - keep in mind two things:

  1. Measure the unregulated voltage of your battery pack, not the voltage coming off of your convertor or regulator (which of course would always read the same value)
  2. Depending on the possible range of voltage you are looking to measure, a voltage divider circuit must be used so the voltage can be read by your microcontroller ADC pin (and not damage it due to overvoltage). For example, in my case I am measuring a possible voltage ranging from 5V up to 8.5V, and using a microcontroller with a reference voltage of 3.3V. With this in mind, I decided to go with a voltage divider circuit of approximately 6:1, with  6.8KOhm (R2) and 33KOhm (R1) resistors. I found this page helpful for learning about voltage divider circuit and calculation.

Resistance

The resistance sensor has been a tricky problem to solve in this build. At first I thought of trying to use a force-sensitive resistor to measure the force being applied on the bike's break. I found it very difficult to reliably connect an FSR using a long lead and eventually decided to move on to a different approach.

I had some Accelerometer/Gyroscope MPU-6050 PCBs and thought to stick one on the knob of the resistance break on the bike to detect resistance by measuring the position of the knob. I am still working on the software side of this, but it looks promising.

Accelerometer cable

I used a 4-pin aviation connector to create a cable for the VCC/GND/I2C SDA/I2C SCL connections. These are large and somewhat clunky connectors that I hadn't used before, but they are pretty robust, easy to solder, and have lots of pin configurations and sizes.

Cadence

This sensor worked really well on the first attempt, which was nice. It is pretty simple, an IR sensor that detects movement a short distance from the sensor by bouncing IR light off of objects. I used a 3.5mm audio jack for this sensor cable, since I had them on hand and they can carry the 3 connections required (VCC, GND, digital signal). Here it is hot-glued to the bike:

IR Sensor attached to bike for cadence measurement

In order to calculate cadence, which is the number of pedal strokes per minute, the time between 2 passes in front of the sensor (a full pedal stroke) is recorded. Then, the number of pedal strokes per minute can be determined by dividing 60,000 by the recorded value in ms.

This has provided a very accurate reading for me, especially with a good debounce threshold (I settled on 240ms). It's also nice that compared with the BLE cadence sensor I've tried, there is no issue with pairing and connection dropout.

Audio/Speakers

The speakers on this device are powered by the PAM8403 Stereo 3W Amplifier PCB. This is a great little amplifier that is widely used by hobbyists. It works really well in my experience. I was really happy with the sound quality and level.

Keep in mind when you are building an audio circuit, interference is a thing. Depending on how your circuit is built, you might experience noise in your speakers. With my build, this is minimal, really the only noise is when there is no audio input connector, I hear pulses coming from the 5V power rail which is shared between the microcontroller, sensors, and amplifier.

I was also pleasantly surprised by the speakers. They get pretty loud and sound good.

Final assembly of the controller

I decided to use a perf-board from a set to connect the components. I found the "freestyle" type of perf-board easier to work with than the breadboard style. It was interesting to learn while doing this, I'm slowly figuring out how to make efficient use of the space.

Here is my first attempt at soldering the connections on the perf-board:

First attempt at soldering the connections on the perf board

After making some design changes I had to make some jumps on the perf-board with insulated wire (this set has been extremely useful to me for these types of connections):

Underside of perfboard

Next time I work on a similar board, I will try to plan out ahead of time which connections should go on the "main layer" and which should use the insulated wires to jump.

Controller board with 5v input barrel plug

Finally, I added a female barrel plug connector to the controller board for easy connection to the power supply. I wanted to be able to access the controller once it was installed in the enclosure.

Conclusion (for now)

Testing the controller in the enclosure

I was really happy when everything was connected and powered on and functioned. Have been using it for about a week with the cadence sensor working great and enjoying the speaker. I am still in the process of calibrating the gyroscope sensor and finding the best way to calculate resistance.

This has been a really fun experience so far. Happy to hear any feedback and suggestions. Thanks for reading, here are some photos of the enclosure mounted on the bike:

DIY Raspberry Pi Pico Smart Exercise Bike

Please note that I only link products that I have bought and tested myself, and some of the links above are Amazon affiliate links, which I earn a commission from (at no additional cost to the buyer).