Magnetic Sensor

Hey Everybody,

Im pretty new to the arduino, and I was looking for any insight into using a hall sensor to simply detect a magnet with the arduino. I would also like to visualize any output with an LCD, 7 segment display, or LED. Any help with coding and circuitry would be greatly appreciated!

Welcome! A hall sensor is not hard to use. Take a look at this one:

You should try to break down your project into pieces such as understanding the hall sensor, understanding an LCD, and then putting them together.

sample code:
void setup()
{
Serial.begin(19200);
pinMode(2,INPUT);
digitalWrite(2,HIGH);
}

void loop()
{
Serial.println(digitalRead(2));
delay(200);
}

Thanks! Ill definitely get started

How would I connect the arduino with the sensor?

Take the output of the sensor and connect it to one of the pins. Make sure the sensor's ground is connected to the arduino's ground as well.

check - Arduino Playground - Hall Effect

Observe the type of sensor that you use. One type of sensors only switch from High to Low when magnet's polarity is swapped and you may want the other type, where it goes from High to Low when the magnet is removed. But it doesn't responds to the opposite magnetic pole.

I've been using an allegro 1302eua hall effect sensor as part of a rover we're building in our school. It's not the latching sort, so it returns a voltage proportionate to the magnetic strength it's detecting. Baseline output is 1/2 supply (2500mV on a 5V supply) and a N pole increases the voltage and a S pole decreases it.

I borrowed a pretty rubbish magnet from the physics department and the sensor picked it up from a good 70mm away.

The supplier I used in the UK sells them for about £1.35 plus postage.

Just for reference there are many types of hall sensors:-

  1. Liner sensors - give an output proportional to the field, used in current detectors and such.

  2. Switch - outputs zero or one.
    a) In the presence of a specific magnetic field direction- non latching unipolar.
    b) In the presence of any magnetic field - non latching bipolar.
    c) Reflecting the last field seen - latching.

In addition, if you got the old non-ic sensor, just to Hall probe, you need to flow current through the sensor and monitor voltage across it. The voltage could get negative and gets very big if you move your magnet too fast. This type of sensor is not very fit for arduinos. The ones we talk about are mostly 3-pin TO-92(?! right?) ones.

Personally I'm a fan of old fashioned reed switches, cheap and simple.......

pluggy:
Personally I'm a fan of old fashioned reed switches, cheap and simple.......

Definitely vote for Reed switches, no power is needed to drive the sensor and it can pass a moderate amount of current to power a device. On the other hand, Hall sensors can be made more sensitive with internal gains and much smaller packages.

However, some reed switches tend to have some amount of contact bounce you have to deal with.

A capacitor and resistor takes care of the contact bounce :wink:

Thanks everybody for the help! But I havent gotten anything to work yet...Im still confused as to how exactly I need to set everything up...I have a breadboard, resistors, wiring my arduino and my sensor...am I missing something? If anyone had a diagram for a simple magnetic sensor, it would help greatly!

Post what you have so far, software and schematic and we will have a look. Also say what you observe and what you hope to observe, along with the component part numbers you are using.

Thanks for the help everyone! Got the sensor working very well...went with the A1302 hall sensor and can use it to sense my magnet a good half foot away!

Good for you! Do you have a project in mind that will require a Hall effect sensor?

Personally I'm a fan of old fashioned reed switches, cheap and simple.......

If a reed switch gets permanently magnetised it jams closed - hall effect sensors have no moving parts, are smaller and less breakable. Reed switches also affect the field they sense whereas hall devices don't.

@liudr:

Im using it for my biomedical project to locate a magnet inside the body for orthopedic purposes...works very well so far!