I just started playing around arduino for a project I'm working on. Basically the ultimate goal is to read the RPM of a bike wheel into a computer and feed it into a custom Java program.
Currently I'm planning on using a reed relay and a magnet on the wheel like a traditional bike computer, however when I was testing the circuit last night the interrupt was being triggered twice for each time I passed the magnet by the relay. Circuit wise I have a 100 Ohm resistor connected to digital port 2 which then connects to the relay which connects into the +5 VDC terminal. I also have a 10k Ohm pull down resistor which connects between the 100 resistor and relay to ground. Code wise I basically just have:
How is the magnet oriented on the wheel? Is it possible that the reed relay gets pulled in by the pole at one end of the magnet, drops out as it passes the center and pulled in again at the other end?
Right now I just have the thing mounted on a breadboard and waving one of those cheap ceramic round magnets from radio shack across the coil area on the relay. Even if I just bring the magnet in and hold it there I get the double blip. So might be an issue with the relay.
I don't know if some sort of debouncer would work in all conditions (how fast is the bike going to go - how big is the wheel, etc...) in terms of the debouncing taking too long and missing an actual pass of the magnet.
Perhaps a hall sensor or IR reflector setup is better suited for this than a relay...
Yeah I was thinking of moving to a hall sensor myself, I figure rough ball park numbers at 1 MPH one revolution happens every 3-4 sec and at 50 MPH there are about 10 revolutions per second so the pulse width range is quite large. I'll see what I can cannibalize later for a hall sensor.
If you expect at most 10 pulses per second, then you should measure how long the reed switch actually bounces.
If I would be you I would setup an endless loop to poll the read switch. On each state change I would compute the time difference to the previous state change and sent it through the serial interface to the computer. Then start triggering the switch with some magnet and see how long it bounces.
If the bounce time stays below 100ms then I would debounce it as follows:
Everytime the reed switch triggers, ignore all subsequent pulses for 100ms.
If it should bounce >100 ms --> bad luck. It would still be possible though. But implementing a suitable filter occurs harder than switching to a reasonable sensor.
Just an idea here: why not just use some inductor and read it with the ADC? ADC can sample at about 10 kHz. So you could read the voltage peaks created by the passing magnet. Obviously you should not look at absolute values but at the relative peaks in order to become resistant against distance deviations.