# Reed Switch Spedometer Problem

Hello! I am trying to make a reed switch spedometer for my bike. I was planning to use an RTC, a reed switch, and a LCD display to show the speed and the time, but I've had a couple problems.

Problem 1: The reed switch.
The reed switch does not constantly stay in a closed state in the presence of a magnetic field. If I hold my stack of magnets right in the middle of the switch, the switch opens, so if the magnets go by the switch, instead of going LOW - HIGH - LOW, the switch goes LOW-HIGH-LOW-HIGH-LOW. Is this because I've used more than one magnet? Or is this just how reed switches are?

Problem 2: The code
My code that was used wasn't finished or extensive. I used a PulseIN(reedpin, HIGH) to measure the time from when the magnet passes the switch to when it activates it again. That could measure the time it takes to make one rotation of the bike wheel. However, because of the reed switch, there will be two pulses. So, I made an if statement that if the pulse was too small, another PulseIn would be taken, and that would be the correct one.

Does that make sense? Can anyone help me with this reed switch pulse reading?
Thanks!

Reed realys need debouncing. They also act differently reagarding how You apply the magnetic field. Do some research about the basics of reeds.

You may want to consider replacing the reed switch with a Hall effect sensor. Since the Hall effect sensor is solid state it will not wear out and Hall sensors do not bounce so that simplifies things. And they are less affected by shock and vibration.

Reed relays need debouncing.

Mercury wetted ones don't...

tyster02:
Problem 1: The reed switch.
The reed switch does not constantly stay in a closed state in the presence of a magnetic field. If I hold my stack of magnets right in the middle of the switch, the switch opens, so if the magnets go by the switch, instead of going LOW - HIGH - LOW, the switch goes LOW-HIGH-LOW-HIGH-LOW. Is this because I've used more than one magnet? Or is this just how reed switches are?

I don't know as it is a long time since I have played with reed switches but this is something you can experiment with. A reed switch works because the ends become opposite poles of a magnet so the contacts are attracted to each other. The magnet should be roughly the same length as the reed. I would think that you would get the behaviour you describe if the magnet is much longer than the reed, so that when the two are centrally aligned nether pole of the magnet is close to either end of the reed. Also, you could try rotating the reed and magnet 90 degrees so they are aligned to the direction of the spokes rather than the direction of rotation.

I agree with the advice to change the sensor from a reed switch to a Hall sensor. I would also change the software approach from using pulseIn() to one where you looked for a state change in the sensor, either using polling or interrupts.

PerryBebbington:
Mercury wetted ones don't...

But are they readily available, as mercury is one of the RoHS directive banned substances.

PerryBebbington:
Mercury wetted ones don't...

In many countrys Mercury is illegal and banned since quite some time.

...the switch goes LOW-HIGH-LOW-HIGH-LOW. Is this because I've used more than one magnet?...

Are you using 2 magnets? If so, this seems normal to me /¯¯¯_/¯¯¯___

tyster02:
If I hold my stack of magnets right in the middle of the switch, the switch opens, so if the magnets go by the switch, instead of going LOW - HIGH - LOW, the switch goes LOW-HIGH-LOW-HIGH-LOW. Is this because I've used more than one magnet? Or is this just how reed switches are?

You mention that you use a stack of magnets. A stack behaves as though it was a single magnet, in that it has a north pole at one end of the stack, and a south pole at the other.

I think that your multiple pulses are due to the orientation of the stack as it passes the reed. You want to arrange it so that only one end of the stack goes close to the read - so that the switch only "sees" one pole (it shouldn't matter which one).

If you have the orientation of the magnet such that that both poles pass the read switch one after the other in quick succession, then you will get a double switch closure - once for the north pole, and once for the south pole.

But are they readily available, as mercury is one of the RoHS directive banned substances.

In many countries Mercury is illegal and banned since quite some time.

Oh, I'm sure they are NOT available and if they were the H&S folk would be having kittens! I was just pointing out that not all reed switches bounce. Mercury is obviously not completely banned as florescent tubes are still available.

[EDIT]
Mercury filled products are available mercury tilt switch
I could not find mercury wetted reeds.

Bit of ancient history - when I was starting in food processing / canneries many people preferred the mercury tilt switches for controlling can conveyor lines, felt the mercury switching was more reliable and took less pressure to actuate.

In some cases the mechanical switching was changed to smart proximity switches requiring no contact - been a while since I had to adjust them but some of the early Prox switches were a real pain in the rear to adjust as you were sensing moving cans and trying to detect if the can conveyor was full of cans at that point - but the cans were also moving and you were looking at the side of the can - if the cans were not tight against each other you wanted the conveyor to run to fill up the conveyor - remember sitting/standing for long periods of time tweaking and adjustment screw with what seemed like a lot of hysteresis - probably much better today

Problem 1: The reed switch.
The reed switch does not constantly stay in a closed state in the presence of a magnetic field. If I hold my stack of magnets right in the middle of the switch, the switch opens, so if the magnets go by the switch, instead of going LOW - HIGH - LOW, the switch goes LOW-HIGH-LOW-HIGH-LOW. Is this because I’ve used more than one magnet? Or is this just how reed switches are?

Since my first post on this I’ve given it some more thought, and concluded that if you pass the magnet along the length of the reed rather than past it sideways then this is expected behaviour, or something like it. When one pole of the magnet gets close to one end of the reed one end of the reed will be magnetised, possibly enough to attract it to the other. As the magnet passes it moves to the other end, at some point the magnetism reverses and the reed opens and closes. If you pass the magnet past the reed sideways this won’t happen. (This is all in my head< I have not tried it, but I suggest you do)

Reed switches began life as reed relays, sometime before 1970. I still have some that I pulled from circuit boards. The design requires a magnetic field parallel to the reeds. They were used to provide total isolation of electronic circuits.

The use of a bar magnet similar in length to the glass enclosure is best for correct operation. Movement of a magnet should be kept parallel to the reed switch. Imagine the magnetic field that surrounds the magnet. It must, as Perry wrote, induce a corresponding magnetism into the two reeds. When the tips of the two reeds have opposite magnetic polarity, they will snap together, completing the circuit.

You can open the reed switch by moving the magnet away, but that distance will vary based on the strength and shape of the magnetic field. Same applies when the magnet closes the reed switch.

If you actually use a bar shaped magnet, you can open and close the reed switch by simply rotating the magnet 90 degrees.

Paul

Stop this trial and error. Why not learn about the electromagnetic fields being involved? How does the E F look around some magnets and what field does the reed relay need to react safely?
It is not woodoo to use reed relays and magnets.

Reed switches are not good for fast measurng and are not precise for timings. Better use an Hall switch to count.

Paul_KD7HB:
Reed switches began life as reed relays, sometime before 1970. I still have some that I pulled from circuit boards. The design requires a magnetic field parallel to the reeds. They were used to provide total isolation of electronic circuits.

The TXE telephone exchanges developed in the 1960s and 1970s used reed relay switching matrices, here is an example of one.

The first such exchange to go into service was a TXE2 in Ambergate in Derbyshire in 1966, so reed relays must have been developed long before 1966.