Best way to find rotation of handlebars on a bike?

I’m looking to determine the angle of handlebars in relation to the frame of the bike. I have a working prototype using 2 gyros [MPU6050] (one on the bars and one on the frame), but would like to try something a bit more compact around where the bars and frame connect (the stem). (2 gyros have their own set of problems).

It should be a retrofittable device, and I can’t access the internals of the bike or screw any holes anywhere. It would need to be very rugged to withstand mountain trails.

Ostensibly I’m building a large rotary encoder, but I can’t quite figure out which direction to go. I’ve attached a photo of a stem for reference.

Does a magnetic rotary encoder make sense? Hall effect sensor with a series of magnets?, Reed Switch or RFID? Put a rotary encoder on the outside and a gear rack for it to trace?

I can’t think of a way to reliably determine position and direction of movement. I’m new to a lot of these mechanics but am having fun learning and exploring solutions. Thanks for the help.

How accurate does it have to be?

To the whole degree ideally. 180 degrees for the whole sweep. (So if you're starting at "0" you can rotate 90deg in either direction)

I'm thinking of a pot of sorts. Main advantage is that you don't have to find a home position when starting up.

no-tec:
It should be a retrofittable device, and I can't access the internals of the bike or screw any holes anywhere. It would need to be very rugged to withstand mountain trails.

To be easily removable/installable on just your bike or, on every bike out there?

dougp:
To be easily removable/installable on just your bike or, on every bike out there?

Every bike would be ideal, but to make the concept work just one bike is totally fine.

no-tec:
Every bike would be ideal, but to make the concept work just one bike is totally fine.

For aluminium or carbon frames, an array of analog hall sensors on a flex PCB that wraps around the head tube and a magnet glued to a piece of slotted fiberglass tube that you push into the fork steerer tube. Secure the magnet using an expanding wedge mechanism (like handlebar end plugs).

holdingpattern:
I’m curious to know why you want to know the angle.

I want to extrapolate it into controlling a servo

mikb55:
For aluminium or carbon frames, an array of analog hall sensors on a flex PCB that wraps around the head tube and a magnet glued to a piece of slotted fiberglass tube that you push into the fork steerer tube. Secure the magnet using an expanding wedge mechanism (like handlebar end plugs).

Interesting solution going into the tube. You're saying that since the head tube is already inside the body, why not use that to my advantage - hadn't thought of that. I wonder how large of a magnet would be required to work through a metal frame.

Great idea, I'm going to get some hall sensors and look into prototyping that. Thanks for the ideas!

such things usually done with optical interrupter and coded disk, but then you have the issue of how to set the home (zero point). look inside a printer.

Depends on the kind of metal... if magnetisable (iron, certain types of stainless steel, nickel) you don't stand much of a chance to make this work.

Cut a suitably sized metal gear in half and secure to the moving section via perhaps a clamp.

Then use a hall effect with a magnet secured to it's back area so the hall becomes a "tooth" detector.

As the bars are rotated it produces a series of pulses, much like a missing tooth detector.

Obviously the need would arise to "zero" at the straight ahead position each time the unit is switched on.

Gear with a module 1 or 2 gear size should suffice and I'm thinking perhaps as much as 50 teeth in the semi-circle.

Arrangement won't care if the frame is steel, stainless, carbon fibre or paper mache.

Two or more encoders to create your own ‘steering angle sensor’.
The sensors generate an in-phase offset binary code for the angular position... the real things are quite complex, but I think you could do something similar for low resolution if you can find a ‘home’ reference position.

"but would like to try something a bit more compact around where the bars and frame connect (the stem). "

I think for experimentation purposes, I would attach a simple vertical member to the frame head that goes up and makes a 90 deg. angle over the steering nut. Then attach a pot to this horizontal member with the pot stem going down on center line with the steering nut. Then attach the pot shaft to the rotating steering head/nut using something simple like velcro, hot glue or other methods.

zoomkat:
"but would like to try something a bit more compact around where the bars and frame connect (the stem). "

I think for experimentation purposes, I would attach a simple vertical member to the frame head that goes up and makes a 90 deg. angle over the steering nut. Then attach a pot to this horizontal member with the pot stem going down on center line with the steering nut. Then attach the pot shaft to the rotating steering head/nut using something simple like velcro, hot glue or other methods.

As with most things there is usually an inbuilt flaw, and in this instance it is the fact that bars can actually rotate more than the 270 degrees of a pot.
Some will rotate completely around through 360 degrees and keep going.

zoomkat:
"but would like to try something a bit more compact around where the bars and frame connect (the stem). "

I think for experimentation purposes, I would attach a simple vertical member to the frame head that goes up and makes a 90 deg. angle over the steering nut. Then attach a pot to this horizontal member with the pot stem going down on center line with the steering nut. Then attach the pot shaft to the rotating steering head/nut using something simple like velcro, hot glue or other methods.

I like the direction you've taken this, very out of the box, so I appreciate that.However I guess the ultimate goal here is to not just find the rotation but in a way that could ultimately be a one fit solution for many types of bikes, and it seems like this is bespoke and I'm having trouble seeing it designed in a more universal and compact way. Thank you for the exploration, I'm going to save this solution for sure.

bluejets:
Cut a suitably sized metal gear in half and secure to the moving section via perhaps a clamp.

Then use a hall effect with a magnet secured to it’s back area so the hall becomes a “tooth” detector.

As the bars are rotated it produces a series of pulses, much like a missing tooth detector.

Obviously the need would arise to “zero” at the straight ahead position each time the unit is switched on.

Gear with a module 1 or 2 gear size should suffice and I’m thinking perhaps as much as 50 teeth in the semi-circle.

Arrangement won’t care if the frame is steel, stainless, carbon fibre or paper mache.

Okay, I’m trying to visualize this solution. Do I have it accurately here? Is this really how the Hall Effect Sensor works? I had a similar idea to this actually, but using a pot with a gear on the end of it that would make contact with the half gear, but the less direct contact I can have the better.

Thank you for the help here!

no-tec:
Okay, I'm trying to visualize this solution. Do I have it accurately here? Is this really how the Hall Effect Sensor works? I had a similar idea to this actually, but using a pot with a gear on the end of it that would make contact with the half gear, but the less direct contact I can have the better.

Thank you for the help here!

As per your attached sketch, yes,.
However I'd be inclined to reverse the arrangement and have the segment of the gear as the "movable" part and the hall effect with it's wiring mounted to the fixed section of the frame.

The magnet should be glued to the back side of the hall effect, no gap as shown.
If memory is correct, the hall I use for ignition systems is Allegro A1120 which basically is open collector output which will switch rail to rail.

“I like the direction you’ve taken this, very out of the box, so I appreciate that.However I guess the ultimate goal here is to not just find the rotation but in a way that could ultimately be a one fit solution for many types of bikes, and it seems like this is bespoke and I’m having trouble seeing it designed in a more universal and compact way. Thank you for the exploration, I’m going to save this solution for sure.”

I’d start with something simple and possibly clunky just to validate the concept of the desired device. If that is proven, then move on to developing small and more robust sensors. Attaching an encoder disk to the rotating steering shaft might be another option. If you look on line, there are printable encoder disk people print and glue to robot wheels for measuring wheel rotation on their projects.

You might consider a magnetic-encoder-chip.