Go Down

Topic: Magnetic Sensor (Read 7462 times) previous topic - next topic


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()

void loop()


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 - http://www.arduino.cc/playground/Code/HallEffect
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)


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.......


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 ;)


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!

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131