Modding my Rowing Machine with an Arduino – Part 2 – Reading the Speed Sensor
Tags: arduino, iot, beginners
Published: 2019-05-21 20:59:07

---
title: Modding my Rowing Machine with an Arduino – Part 2 – Reading the Speed Sensor
published: true
tags: arduino,IoT,beginners
canonical_url: https://alistairevans.co.uk/2019/05/21/modding-my-rowing-machine-with-an-arduino-part-2-reading-the-speed-sensor/
---

If you didn’t catch my [previous post on setting up an Arduino](https://dev.to/alistairjevans/modding-my-rowing-machine-with-an-arduino-part-1-arduino-basics-21c5), then to catch you up, I’ve got a rowing machine, and I am trying to replace the basic LCD display on it with my own; to do this I need to read the sensor data it collects and process it myself.

![](https://alistairevans.files.wordpress.com/2019/05/20190511_120716.jpg?w=267&h=267)<figcaption>This is my ‘competition’ right now</figcaption>

Just so everyone is aware, this post could also be titled, “How I struggled with basic electronics” or “How you shouldn’t make assumptions when reverse engineering something”.

When I started this little project, I looked at the existing board that provides the LCD display for the rowing machine, and saw the two connectors. One for speed (which goes to the fan wheel at the front) and one for count (which goes to a sensor under the seat).

![](https://alistairevans.files.wordpress.com/2019/05/20190511_120730.jpg?w=232&h=232)<figcaption>The connectors on the back of the PCB.</figcaption>

I made the _assumption_ that because speed is an analog value, then the incoming data should be analog as well. This turned out to not be true, but first I’ll show you the wiring/code that told me it was not true.

### Wiring

The connector for the speed sensor is actually a 3.5mm mono female jack:

![](https://alistairevans.files.wordpress.com/2019/05/20190519_112132.jpg?w=249&h=249)<figcaption>The jack on the right is the speed sensor, the one in the middle goes to the seat movement sensor.</figcaption>

So, I got a cheap 3.5mm cable, cut the end off it, then wired it to a junction.

![](https://alistairevans.files.wordpress.com/2019/05/20190519_122024.jpg?w=280&h=280)<figcaption>The wired mono jack.</figcaption>

I was momentarily confused by the fact there were 3 cables rather than 2 for a mono connector, but it turned out that the yellow wire was wired straight to the red, so I just ignored that one.

### Reading an Analog Value

I thought that the speed sensor might be some sort of variable resistor, so that as the speed increased, the voltage allowed through the connection would increase.

So to start with, I connected the 5V line on the Arduino to the red wire on the junction, and the black wire (GND) to the A0 analog input pin on the Arduino:

![](https://alistairevans.files.wordpress.com/2019/05/20190519_130731.jpg?w=280&h=280)<figcaption>Wiring to the analog input pin.</figcaption>

Then, I wrote some code to read the analog value (in volts) and write it to the Serial connector:

{% gist https://gist.github.com/alistairjevans/062d1334ec052a93004c7fd9d62602f8 %}

Before you connect the sensor, you just get analog ‘noise’ because there’s nothing connected to the A0 pin:

![](https://alistairevans.files.wordpress.com/2019/05/analogfloating.gif?w=489&h=243)<figcaption>Voltage data from a floating analog input</figcaption>

Once I connected the 3.5mm jack to the rowing machine’s speed sensor I got:

![](https://alistairevans.files.wordpress.com/2019/05/image-11.png?w=380&h=278)

So that already tells me that the circuit is complete, and I’m seeing the 5V from the Arduino coming back.

When I pull on the rowing machine, my numbers change, but only very slightly (and not really in a way that relates to the speed):

![](https://alistairevans.files.wordpress.com/2019/05/analogpull.gif?w=423&h=210)<figcaption>Not much change in the voltage…</figcaption>

I was definitely expecting more change in values from this; and as soon as the wheel of the rower starts to slow down, the number goes back to 5V.

What’s going on here? It doesn’t so much look like the voltage is changing with speed, it’s more like something is slightly interfering with a stable voltage reading…given the nature of the analog value sampling, it stands to reason that a **switch** rapidly changing from on to off and back might look like this…

## Using a switch to read speed

So how can you use a switch to read speed? Well, I suspect there is a **magnetic reed switch** inside the wheel of the rowing machine, with a magnet attached to one of the blades of the fan inside the wheel.

Each time the magnet passes the switch, it will cause the circuit to break temporarily. The faster the blades spin, the more often the circuit will break.

To detect this, I need to change my approach a bit, and rather than read analog values, I need to read a digital value.

In order to get this working I had to sort out some basic electronics; I used the guide found [here](https://circuitdigest.com/microcontroller-projects/arduino-reed-switch-interfacing), which gave me the circuit I needed to make it work. It’s not too complicated to wire up, here’s the final diagram:

![](https://alistairevans.files.wordpress.com/2019/05/image-12.png?w=1100)<figcaption>Circuit Diagram of the switch reader</figcaption>

It looks much less neat than that on the breadboard, but here it is:

[![](https://alistairevans.files.wordpress.com/2019/05/20190521_201846.jpg?w=265&h=265)](https://alistairevans.files.wordpress.com/2019/05/20190521_201846.jpg)<figcaption>The circuit to detect the state of the switch.</figcaption>

Then, I added the following code, to sample the digital input and watch for transitions.

{% gist https://gist.github.com/alistairjevans/60e68aba3ffcfc7936e018bb30fb3704 %}

Now, when I plug this into the rowing machine and I give it a good couple of pulls, I get some meaningful speed readings out that correlate with how hard I pull it!

![](https://alistairevans.files.wordpress.com/2019/05/speedresults.gif?w=596&h=366)<figcaption>Pulling on the rower gives me increases in speed!</figcaption>

Next post will cover getting the data off the Arduino; connecting up the WiFi on my board and sending an HTTP request with my speed data!