Author Topic: Advice please. Piggybacking on a switch signal.  (Read 630 times)

0 Members and 1 Guest are viewing this topic.

Offline mc349iiiTopic starter

  • Contributor
  • Posts: 11
  • Country: gb
Advice please. Piggybacking on a switch signal.
« on: May 21, 2023, 09:50:06 am »
I want to build a simple project for my exercise bike.   I'd like show a LED speed graph for the speed indicator using WS2812B addressable LEDS which I've used before.   

However I'd like to keep the existing bike computer running and unaware that I'm doing anything and keep it functioning as normal.

The bike computer seems to measure the cycle speed by using a reed switch and magnet and it delivers one pulse per rotation of the crank, so the signal rate isn't going to be that high  5 or 6Hz at maximum.    The bike is sending 3V down to the switch, unsurprising since it runs on 2AAA batteries.

So I'm thinking it should be an easy matter to tap into that switch wire and connect it to a microcontroller, and a I have a few 8Mhz Arduino Pro Minis sitting unused so that should easy enough.    But I'm wondering how best way to monitor the switch in a way that's hopefully invisible to the bike computer.

My first thought would be to connect the signal wire to the gate of a mosfet (with a resistor in series)  since mosfets take very little current to turn on.  Then use the mosfet to switch a pin on the microcontroller which I can then monitor and count the pulses in a particular time period,  convert that to a speed, scale it and animate my LEDs accordingly.

Do people think that will work?   Is there a better way?

Any advice is welcome.

p.s. I also have a few Pi Picos sitting around unused, but that seems overkill for this simple task?


 

Offline IDEngineer

  • Super Contributor
  • ***
  • Posts: 1941
  • Country: us
Re: Advice please. Piggybacking on a switch signal.
« Reply #1 on: May 21, 2023, 12:33:23 pm »
Check the spec sheet for your MCU. I bet the input current to its digital input pins is very low, and unlikely to make a difference to the existing circuitry and you can just connect directly. If it has Schmitt Trigger inputs (many do), favor one of those for improved noise rejection.

It would be good to put a scope on the sensor to see how clean its output is, in case you need to do some conditioning of your own.
 

Offline mc349iiiTopic starter

  • Contributor
  • Posts: 11
  • Country: gb
Re: Advice please. Piggybacking on a switch signal.
« Reply #2 on: May 22, 2023, 09:42:28 am »
Hooking it up directly did work and was very easy and the original computer didn't seem to notice. So thanks for that advice. I did have to connect the grounds together to get it work.

But having done that I've decided that I don't like the once per revolution pulse anyway, doesn't give much resolution for my speed display (update rate) and it takes a few seconds to get an accurate speed indication.

So am going to try and use an optical sensor and stick some reflective tape on the flywheel at regular intervals and detect that whizzing by instead.  Luckily the flywheel is black,  so some white tape should be easy to "see".

That should mean my LEDs can much more accurately reflect the instantaneous speed. 
 

Offline dietert1

  • Super Contributor
  • ***
  • Posts: 2391
  • Country: br
    • CADT Homepage
Re: Advice please. Piggybacking on a switch signal.
« Reply #3 on: May 22, 2023, 10:41:23 am »
To get precision at low repetition rate others measure the time span between pulses instead of pulse frequency. Then frequency is determined as the mathematical inverse of the time span. This way you get a new result on each pulse. Probably that is how the bike computer is doing it, too.
An arduino should be able to do this to 4 or 5 digits.
Of course if the bike is really slow, it can still take several seconds until the next pulse arrives..

Regards, Dieter
« Last Edit: May 22, 2023, 10:45:57 am by dietert1 »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf