I am an avid bicyclist and an avid tinkerer. I figured that one way to make it through the indoor riding season was to combine the two areas.
I figured to start easy and just interface and old Cateye bicycle computer sensor with an Arduino. Unfortunately, so far it hasn't been anything but easy.
The Cateye sensor consists of two switches and two magnets. The switches are mounted on the rear chainstay and one magnet is mounted to a spoke and the other to a pedal. My plan was to hook it up the switches to pins 2 & 3 and then setup a simple interrupt routine to count revolutions.
Problem #1 - Connecting the switches (Solved). :) I cut the cable to the two switches and had a devil of a time connecting anything to it so I could connect it to the Arduino. I couldn't solder it and ended up having to crimp pins to the end of it.
Problem #2 - Extending the cables from the sensor (Solved). :) I wanted to extend the sensor leads so that I could work with the Arduino on my bench while the bike was in the stand. With my initial setup both interrupts would trigger when either switch closed. I fixed this by putting 10K ohm resistors between the 5v from the Arduino and the common pin and then 10K resistors between the two switch leads and ground.
Here is what is giving me the headache: :(
Problem #3 - Everything works with the bike in the bike stand but not on the rollers. I setup the Arduino to print out the interrupt counter for the wheel and pedals every five seconds. In the stand you get a nice consistent set of number. Start riding on the rollers and you will jump from 150 rpm to 600 rpm between samples.
My current line of troubleshooting is that it has something to do with static electricity being generated between the bicycle tires and the rollers but so far I haven't been able to solve the problem.
If anyone has any ideas I would love to hear them.
Connect the bike frame to the arduino ground and to an actual ground connection (copper gas or water pipe, earth pin on a wall socket) ?
I fixed this by putting 10K ohm resistors between the 5v from the Arduino and the common pin and then 10K resistors between the two switch leads and ground.
Maybe you fixed it, maybe you didn't: your description is a little ambiguous, but it sounds like a bad arrangement that's biasing your inputs to 2.5V.
Depending on how you have the "common" pin wired, you should have the inputs tied either to ground or Vcc, with a stronger pullup/pulldown (more on the order of 1K, rather than 10K). That should give you better noise immunity.
One switch needs to go between the arduino's ground and one interrupt pin and the second between the other interrupt pin and arduino ground. You need to use the internal pullup resistors or external 10k resistors from each interrupt pin to +v. This way the interrupt pin is either solidly connected to +v or 0.
Static electricity will not be a problem but you will get multiple interrupts when the switch bounces. You can ignore them in software(don't count a second interrupt within 10ms) or add some hardware.
Thanks for all the feedback. I got things working.
It doesn't appear to matter if I use 10K or 1K resistors. What does matter is that I have resistor between the Ardunio pin, the switch leg and ground and another one between the common switch leg and +5v. If I don't both interrupts fire when either switch closes.
As for all the other problems they appear to have been static.
My breakthrough was that I found out that things worked fine as long as I was holding on to the wall which I do to get up to speed where I can balance the bike. I could ride all day as long as I had one hand on the wall.
It tried a bunch of things to ground the bike, myself and the rollers but nothing worked. Finally I put the whole setup on a rubber exercise mat and this solved the problem. I no longer get strange readings or Arduino lockups.
Googling information on Bicycle Rollers did come up with a fair amount of talk about static.
Thanks again for all the pointers.