Hall effect switch - reverse operation?

Hi

I have several ‘home made’ boards I have put together from strip board (which includes arduino nano) for a project involving train detection on a model railway. So far I have experimented with light sensors and reed switches. Both work ok, but each with their own downsides.

Since I started off with light sensors, the board inputs (with the help of spring terminals) for these sensors are:
*A0 pulled to ground with a 10k resistor (plus one leg of the LDR)
*5v (plus the other leg of the LDR)

…thus creating a voltage divider, pulling to ground when the LDR goes dark. This way, I can have the setup routine on the arduino determine which inputs actually have sensors connected so them so that the main body of the code reacts accordingly.

With a tweak of the code I decided the reed switches across the same terminals was more reliable. The trouble is they are SO fragile - I found three broken within hours of installing.

What I have decided to do is experiment with the momentary Hall effect sensors. I haven’t ordered any yet, as I have a question to ask bout them first.

All the circuit examples I have found for Hall effect switches involves pulling a sensor pin to ground. I’m wanting to to perform little or no modification to my existing boards to accommodate the hall sensors, but my input pins are already pulled to ground due to the current voltage divider arrangement.

MAIN QUESTION:

Can a hall sensor be wired to send out 5v when it senses a magnet, instead of pulling to ground? Is this just a matter of wiring, a different type maybe or just simply not possible without modifying my boards?

add a transistor?

Try a smaller fixed magnet that would trigger it continuously, so when your moving one comes, it overpowers the smaller one.

You can get hall effect sensors that only trip on one side of the magnet. That would allow you to flip the magnet to reverse your logic.

Chagrin:
You can get hall effect sensors that only trip on one side of the magnet. That would allow you to flip the magnet to reverse your logic.

Let me give you a hint!

If you turn the sensor over, it will trip on the other side of the magnet!

From what I've read, I was under the impression a Hall sensor is only sensitive to a magnet on its branded side? The 'pull down magnet' idea is an interesting one. Could this result in a lesser response rate though? I'll have to get hold of one and experiment.

I'll have to have a think about your transistor suggestion robtillaart. I could ask you straight out but I will TRY & work it out myself!

Dan

danielmc1:
From what I’ve read, I was under the impression a Hall sensor is only sensitive to a magnet on its branded side?

The sensor equivalent of a magnetic monopole, eh? (I was absolutely waiting for that one. :grinning: :grinning: )

No, this specification is merely to tell you which pole of the magnet to use. Obviously, if you use the other side of the sensor, you must then use the opposite pole of the magnet.

I see. So if this method was used, a latching hall sensor would be used, is that right?

You can find analog types, which output a varying voltage based on proximity to a magnet, or "schmitt trigger" types that have a full on or off output. There are some that require two magnets, one to turn it on and a second, flipped, to turn it off which I believe would be referred to as a latching type. And then there are some that work with only one side of the magnet (N or S) and some that will work with either. Very important to carefully read the part's datasheet.

danielmc1:
MAIN QUESTION:

Can a hall sensor be wired to send out 5v when it senses a magnet, instead of pulling to ground? Is this just a matter of wiring, a different type maybe or just simply not possible without modifying my boards?

With a pair of cutters cut one wire to the 10k grounding resistor. Use the internal pull-up on the pin and reverse all your previous logic. You will also need to run a ground lead to the Hall effect.

Good suggestion, although if the inputs are always pulled low, my code can’t detect which inputs have a sensor connected to them on startup.

How about this:

If the sensor pin is already pulled to ground with a 10k resistor, how about if I also pulled it to 5v with a weak 330 ohm resistor at the same time? Am I right in thinking the pin would then be pulled very near to 5v by default and pulled to ground with the hall sensor? (Effectively just putting the 330 ohm between the + and output legs of the hall sensor). Or is this an “electronic no-no”?? I suppose it would simply be a very weak voltage divider… ?

danielmc1:
Good suggestion, although if the inputs are always pulled low, my code can’t detect which inputs have a sensor connected to them on startup.

The pin will be pulled high by using the internal pull-up resistor.
There is no need for a grounding resistor. Just cut it out of the circuit.
The Hall effect will pull it low when a magnet is detected.
You set the code to use the pins that have sensors on them.
Change all your current digitalReads from HIGH to LOW and vice versa.
Or post your code (using code tags </>) and I’ll change it for you.

Thanks Henry_best for your help. Sorry my reply didn't make sense, I think I was tired! You mentioned the internal pull up's which of course means that would be a great solution to the problem.

The trouble is, I had originally used the internal pull ups and all worked well 'on the bench', however when the boards were placed underneath the railway and long lengths of cable fed to the inputs from the LDR's, they acted like they were floating - switching around all over the place! Turns out, there is so much interference from the digital command station for the railway that the internal pull ups are too weak. So I disabled the internals, added external 2.2k pull up's and decoupling capacitors, and all was well.

I should give a little more background to the setup:

The initial idea was that the boards could be used with either an LDR (which would mean analogread's and hence the 10k resistor to ground on the sensor pins, completing the voltage divider) or a read switch using the same connections (and now possible Hall effect switch) with a slightly different set of code with digitalread's.

Also, I wanted the boards to be able to operate with one, two or three sensors, on the same code, with the number of sensors being detected in setup (hence the sensors pulling up by default when they are connected) and sections of code running accordingly depending on the number of sensors present.

Thanks for your input Henry and apologies for my dodgy reply!

Have you considered infra-red LEDs and IR detectors acting as 'broken-beam' sensors, or won't that work with your setup? (Just a passing thought, since I just bought a bunch of both of the above.)

danielmc1:
The initial idea was that the boards could be used with either an LDR (which would mean analogread's and hence the 10k resistor to ground on the sensor pins, completing the voltage divider) or a read switch using the same connections (and now possible Hall effect switch) with a slightly different set of code with digitalread's.

Common misapprehension that you need to use analogRead for an LDR or that you would do anything other than wire the LDR to ground. This is only if you want to measure the light intensity.

If you only want to know on/off, of course you just use digitalRead (and choose a pull-up resistor or just the internal pull-up to match the threshold).

Thank you all for your replies.

Funnily enough, oldSteve, an IR emitter / reflector setup was the first thing I started to experiment with about a year ago. All worked fine until any form of artificial light was switched on & the IR sensor I was experimenting with always behaved as if it was being flooded with IR light.

I moved onto reading changes in light levels that worked in daylight or under artificial light. The only problem with this is that sunlight comes in a SIDE window in some places near the track and the trains pass OVER the light sensors :confused:

Paul__B, I've never thought about using a light sensor like that. Would it work though if my code is constantly analysing light level changes (up spikes and doesn't spikes) even as the light level gradually changes in the evening?

The usual way to do this is use a modulated LED or laser. Modulate it with 38 KHz and use one of these receivers: 1 pc ir receiver infrared radiation module 38khz tsop4838 dip-3 Sale - Banggood.com sold out-arrival notice-arrival notice
There are other models of receivers out there too. This makes it immune to ambient light.

An IR laser: 1310nm 5mW Infrared IR Laser Diode Laser Module Generator - US$6.99 sold out-arrival notice-arrival notice
Not real inexpensive at $6.99 free shipping; maybe some less expensive ones out there. An IR led will probably work just as good.

pegwatcher:
The usual way to do this is use a modulated LED or laser. Modulate it with 38 KHz and use one of these receivers: 1 pc ir receiver infrared radiation module 38khz tsop4838 dip-3 Sale - Banggood.com sold out-arrival notice-arrival notice
There are other models of receivers out there too. This makes it immune to ambient light.

That's exactly what I meant. (Your link is no good though.)
Not simple IR detectors/sensors, but demodulating ones.

Daniel, these are the 38kHz demodulating receivers that I bought, (AU$1 each):-
(Pity you're not closer - I could give you a couple. I have heaps.)
IR Receiver Module 38 kHz TSOP4838 DIP-3
You'll easily get similar ones over there on your local eBay.

As mentioned by pegwatcher, they're fairly immune to ambient light. (That's why IR remote controls work so well.)
And you could either modulate the transmitting LED with leads from the Arduino, or from a separate NE555 astable or similar oscillator, depending on your setup. It should work well.
(Not an 'IR reflector', a broken-beam, (photo-interrupter), system.)

And you could either modulate the transmitting LED with leads from the Arduino, or from a separate NE555 astable or similar oscillator, depending on your setup. It should work well.

Here is a Forum topic that discusses generating the 38KHz with interrupts so you can be doing all your other stuff without worrying about it : http://forum.arduino.cc/index.php/topic,10555.0.html
I have not tested it yet, as I misplaced my IR leds somehow.