I have a hall sensor rigged up - pretty simple. One of these:
Setup: 1 pin to the 5v. Middle pin to ground. Other pin the analog pin on my micro.
Sketch: Analog pin to input mode, analogRead the pin value, Serial the value out, wait 500 millis, repeat.
Results: the values I'm getting fluctuate between 0 and 20 when I'm not doing anything at all. When I hold a rare earth magnet a 1/4" away, the values go up to maybe 40. If I back that off to an inch away, the values just fluctuate like I'm doing nothing. By contrast, if I just grip the jumper leading to the input, I get a value of 500. Yes, I've turned the magnet about and tried it.
I feel like sticking such a powerful magnet so close to a hall sensor should give me something more. Am I doing something wrong? Or are these just that weak and I was expecting too much?
Well, OK, scratch that last bit from me...I had it on a GPIO without a pull-up. When I put it on a pull up, I get a good read of ones/zeroes.
But, the root problem is still that I don't get a read much further than 1/2 to 1 inch away. Is that normal? Do I just need a larger hall switch/sensor or larger magnet?
You might with a linear device - especially if you put some soft iron, or better still permalloy or mumetal in front or behind or both to intensify the field. Mild steel might do - but does partially magnetise easily.
Permeability of air = 1.
At low magnetising forces ( < 0.1 Tesla) Iron/ steel about 2000. Permalloy/mumetal up to 20-100,000.
A linear Hall sensor is an instrument sensor to measure magnetic fields with. It's not limited to ON/OFF and will detect fields farther away than the security switch. They cost less than $1 too.
You are trying to measure a distance or position? If you had a long magnet that moves alongside a linear Hall that would tell you where along the magnet the sensor is, would that do? Because if you put a magnet on an iron nail, the nail will be magnetic.