# Using Arduino as Bike Speedometer (with generator hub)

This is related to a previous topic: "Counting A/C peaks from a hub dynamo to work out bike speed" Counting A/C peaks from a hub dynamo to work out bike speed - Project Guidance - Arduino Forum

In that one, someone was thinking about the same thing, but I don't think they realized the power output of their hub.

So, these hub generators produce A/C, fixed at around 500mA, but with a variable voltage output. Voltage varies from 0 at standstill to around 20V at significant speeds. You can supposedly, if you don't have some load attached, reach voltages as high as 100V. Also, it's AC of course, so half of your signal is negative voltage.

So, I'm looking at using the hub to 1) provide a frequency signal to the Arduino to use as a speedometer and for some circuit control needs, and 2) use the power output to charge batteries. So what would I want to do to the output to convert it to something I could safely read on an Arduino pin? It seems like if I use a bridge rectifier first, put some over-voltage shunt in, and run that through an appropriate voltage divider, I can safely get a signal varying from 0 to +5 volts. But the voltage is varying with speed, so I can't just read it with a digital in. Any advice on that? Analog in with a pull-up (or down)? Digital same way?

Bigger power question - anyone familiar with load dump surges? How much power would I need to draw to avoid that power spike? Is my teeny-tiny little draw at the Arduino to read that frequency going to do it? The Arduino (nano) will always be drawing a load for its own power and to read the frequency (plus the display), but I'm planning to connect/disconnect the power to the charging circuit to reduce parasitic load on my engine (me!)

Last question, what would be a reasonable way to track the frequency? Interrupt with a counts/second counter?

some thoughts:

you can always put an opto coupler in between...

if you think the voltage can be 20V -> double it
spike's law: voltage spikes can be twice as high even if you take spike's law into account

or use a Zener to flatten it.

Check it out! Someone starting a topic an hour after me posted a library for tracking frequency FreqMeasure Library, for Measuring Frequencies in the 0.1 to 1000 Hz range, or RPM Tachometer Applications.

Wouldn't that just shift the risk of blowing out to the coupler? And that doesn't seem to help with how to pick up the frequency signal if it's varying between 0V (0 mph) and 20V (30 mph).

Yeah, that's where the 100V warning comes in.

Can anyone translate this for me?

The notes with it say: "If the input signal may have noise or could be a high frequency, adding a low pass filter is a good idea. An amplifier may be needed if the input signal is a sine wave or small AC signal which can not directly drive a TTL logic level input."

[I'm a software jockey. By now I can read schematics with simple discrete components, and ICs that have specific purposes, but these general transistors and amplifiers completely throw me :~]

I'm interpreting this schematic as:
With a 5v VCC rail and ground, run an AC input through a transistor and two inverting amplifiers to get a readable digital 5v input for a microcontroller.

Completely guessing at what this does, I'd guess that the 470k & 3.3k resistors are dropping the input voltage differential to something reasonable (with 20V in and +5v instead of ground, I get that that would be a .1V signal - that could supposedly go up to 700V or so and still drop it to a safe level). The 10uF capacitor is doing some kind of filtering. The 2N3904 is just draining the negative side of the AC to ground? (Really, no idea. Oh, wait, the datasheet says it's a "Hex inverting Schmitt trigger" and "It is capable of transforming slowly changing input signals into sharply defined, jitter-free output signals." So I'm guessing it's also turning the sine-wave input into a square wave output?)

The first 74HC14 is inverting that .1V to -.1V and amplifying it to -5V? The second inverting amplifier is turning the -5V to positive 5V? The two capacitors are just circuit protection, and the 3.3K resistor is making sure the current is low? So we're turning a potentially large AC signal into a half-wave, square wave, 0 and +5V signal? Close?

For anyone who comes by here later looking for ways to measure low frequencies, this forum post: Frequency / period counter - Libraries - Arduino Forum is also very good.

The frequencies I'm measuring are pretty low. This hub has 14 armature 'claws', so 14 pulses per revolution. For a 700 x 32c wheel/tire, that works out to a max frequency of about 150Hz. If I want to measure pedal rpm as well, that's up to 2Hz. There's no reason I can't do this kind of low frequency with polling. As they point out in that post, the highest frequency you can manage with polling is around 25KHz.

-2N3904 is acting as an Amplifier.
-10UF cap is a DC blocking cap. Blocks DC which might be present from any previous stage and prevents Dc from this stage to go to the input signal generator.
-First 74HC14 Inverter is a Schmitt trigger. Converts incoming signal wave into pulses.

-3.3K and 0.1UF cap network is a low pass filter (high frequencies are sent to ground through cap)
-Second 74HC14 is another inverter to restore signal phase.
Good luck

Awesome! Thank you!