A Simple Guide to Using a Hall Effect Sensor With Arduino

By Arvind Sanjeev


Have you ever wanted to make a project that involved contact-less sensing? For example: to detect a door closing, to count the number of revolutions of a wheel, or make a speedometer? Then this Arduino Hall Effect sensor tutorial is for you!

This project uses a Hall Effect sensor to detect the presence of a magnet. Whenever a magnet moves past this sensor, it can detect it. This sensor can be used to do a lot of different things. For instance, if we need to detect a door closing; then we simply have to attach a magnet to the door and a hall sensor to the frame of the door. Whenever the door closes, the magnet is placed near the hall effect sensor and we are able to detect that the door has been closed.

Similarly, this same principle can be used to make a speedometer for a bike or any other vehicle. If a magnet is attached to the wheel and a Hall Effect sensor is placed somewhere in the frame of the bike, the time taken for the wheel to complete one revolution can be measured, and with a bit more math, we can detect the bike’s movement speed!

Required Materials


  1. Arduino or an Arduino clone board (freeduino), or make your own custom Arduino board with this tutorial.
  2. Hall effect sensor 44E or  US5881 or US1881.
  3. A small magnet.
  4. 10K resistor.
  5. 9V Battery and connector.
  6. Connecting wires and breadboard.


Arduino IDE

How Does it Work?

The Hall Effect sensor works on the principle of the Hall Effect, which states that whenever a magnetic field is applied in a direction perpendicular to the flow of electric current in a conductor, a potential difference is induced. This voltage can be used to detect whether the sensor is in the proximity of a magnet or not. The Arduino can detect this voltage change through its interrupt pin and determine whether the magnet is near the sensor or not. The basic working of the Arduino Hall Effect sensor is shown in the picture below.


Arduino Hall Effect sensor working


There are many types of Hall Effect sensors, and certain types are better for certain applications. For applications where the speed of detection is not crucial, ordinary Hall Effect sensors like 44E can be used. However, for applications that involve high-speed detection, like in the case of speedometers, high-frequency Hall Effect sensors like US5881 or US1881 should be used. There are two main types of Hall Effect sensors:

  1. Latching Hall Effect sensors.
  2. Non-latching Hall Effect sensors.

The US1881 is a latching Hall Effect sensor. The sensor gives out an output HIGH (5V) voltage whenever the north pole of a magnet is brought close to it. Even when the magnet is removed, the sensor still outputs a HIGH voltage and does not go LOW (0V) until the south pole of the magnet is brought close to it. These sensors that latch on to a particular state are called latched Hall Effect sensors.

The US5881 is a non-latching Hall Effect sensor. The sensor gives an output HIGH voltage whenever the north pole of a magnet is brought close to it, and switches LOW whenever the magnet is removed. I personally prefer non-latching Hall Effect sensors like the US5881 for my projects.

Hall effect sensors have three pins: VCC(5V), GND, and Vout(Signal). The pinout of a Hall Effect sensor is as shown below:


Arduino Hall sensor pin out DIY Hacking

Arduino Hall Effect sensor pinout

Making the Connections for the Arduino Hall Effect Sensor

Interfacing the Hall Effect sensor with Arduino is really simple. The VCC of the sensor is connected to Arduino’s 5V power pin. The GND of the sensor is connected to the GND pin on the Arduino. The Vout or Signal pin of the Hall Effect sensor is connected to the Arduino’s interrupt pin (digital pin 2). Furthermore, a 10K resistor is connected between the VCC and Vout pins of the Hall Effect sensor. This is done to pull the output of the Hall Effect sensor to 5V. The connections are done as shown below (the side with the printed number is facing towards you in the diagram):


Uploading the Code and Testing the Arduino Hall Effect Sensor

After you finish hooking up the Hall Effect sensor to your Arduino, you need to upload the code to the board and test it. The Arduino Hall Effect Sensor code can be used to detect a magnet and count the number of times it detects it. This is a very simple Arduino code which utilizes the interrupt pin 0 (digital pin 2) of the Arduino.

Whenever the Hall Effect sensor detects a magnet, it outputs a HIGH (5V) voltage to its Vout pin. The interrupt pin of the Arduino which is connected to Vout, detects this rising (HIGH) voltage through the function: magnet_detect. A screenshot of the serial monitor which prints “detect” whenever a magnet is brought close to the sensor.


Arduino Hall Effect Sensor Tutorial DIY Hacking

Arduino Hall Effect Sensor serial monitor

Hooking up the Arduino Hall Effect Sensor to Your Project

In order to show the applications of this project, I have installed the sensor on my door frame. I have also attached a small magnet to my door. Thus, whenever my door closes, I can detect it. This can also be used as a burglar alarm system by hooking it up to some lights and sirens.

Furthermore, you can also use this sensor to make a speedometer for your bike. A small magnet needs to be attached to your wheel and the Hall Effect sensor can be attached to the frame of your bike. The number of rotations made by the wheel and the time taken doing it can be measured through the Hall Effect sensor. And after performing some calculations on this data, you can show the speed of your bike in Km/h or Mp/H.

Check out this video which shows the demo for the Arduino Hall Effect sensor project:







Recommended Posts
Showing 39 comments
  • Richard

    Can I use an arduino to modify the signal from a hall sensor? Here is what I am trying to achieve: My car has a speed limiter that is engaged by a signal from a small hall sensor located behind the speedometer. That signal is also responsible for the cruise control (that is why I simply dont just unplug it). So I want to split the signal, and send an altered signal to the ECU thereby never reaching the governor’s limit.

  • parkham

    In your code at http://diyhacking.com/projects/ArduinoHallEffect.ino , how can half_revolutions ever be greater > 0 ?

    I see that in the function magnet_detect you do a half_revolutions++ when an interrupt is detected. Does ++ in arduino programming mean “add one” or something?

    Or am I just missing something.


  • Valosicky

    Can I connect the hall effect sensor to android phone, that will help to send the speed parameters of the over speeding vehicle to a database if over speed is detected.If possible how can it be achieved? If not, is there any way I can send the speed parameter to a database?

    • Seth McKenna

      Yes. All that and more.

    • Phil

      “half_revolutions++” is the same as typing “half_revolutions = half_revolutions + 1”

  • Mike

    Great project, thanks for sharing.

  • Sergei BallsFallOff

    Someone send me a shlong pic

  • Gurj

    hi i looking i am new to this, but i use the code but serial monitor is printing letters with accent, can help with that? And also i looking for make sensor to detect car over the sensor can you recommend anything?

  • Anand Abraham

    Hello Arvind,

    I am using the interrupt function as described on reading the hall effect pulse change across my motor. But my pulses read 0. No update.

    My arduino is running at 12V. My interrupt pin gets 8.5V at high & 5.64V at low.

    My interrupt ISR function is as follows:

    void count()

    void setup()
    // initialize serial communication:

    Do you know what the fault may be?

    • Doom Gesling

      It is all in setup… it needs to be in loop

  • James ng

    We wish to know more about these to increase speed to our bldc motor thru personal channel. Please contact me

  • farhan

    Hi i wanted to ask is it possible to connect the output pin of the sensor to an analog pin on the arduino to see the different voltage values we would get for different magnets. thank you

  • Morai Motion

    Great idea to use the Hall sensor for a home security system. Should be fairly easy to implement anywhere someone needs that extra level of protection with your clear instructions. Bike speedometer’s a good idea too, especially with the rise in popularity of cycle stationary-stands. Obviously there are many handy uses for it. Being in the linear motion industry, we find many people also like to use Hall sensors to control the motor timing of our micro linear actuators – being that they are electronic, there are always some minor timing delays when using multiple ones together – syncing them with a Hall sensor is an effective solution.

  • IAN

    Gud day!
    Im student here in philippines looking for what sensor should be used to detect vehicle, although all can detect vehicle. Our thesis is “vehicle notifier in sharp curve road”

  • shazz

    hi i want to ask can i find faults in wire using non latching Hall sensor ?
    i need a quick response please its urgent thanks

  • Doniel

    Hello am a student trying to implement a similar project, i would like to know how to display the obtained rpm in an LCD. PLease advice, i keep trying but it fails

  • Joe Weisman

    A couple of minor tips:
    – I use hall effect sensors with just the arduino’s internal pullup resistor, and I don’t add the 10K ohm or any other resistor. Works fine so far.
    – I’ve also wired a sensor using just 3 sequential arduino pins, which might be convenient in some cases:
    – pinMode(10, OUTPUT); digitalWrite(10, HIGH); // vcc
    – pinMode(11, OUTPUT); digitalWrite(11, LOW); // ground
    – pinMode(12, INPUT_PULLUP); // signal, low when magnet is sensed

  • Tim Yinger

    Hi I’m new to all this. i just got the US5881 UA sensor, and on the data sheet it says “For proper operation, a 100nF bypass capacitor should be placed as close as possible to the device between the VDD and ground pin.” and the schematic shows both a 100nF capacitor and a 4.7 nF capacitor in the “typical 3-wire circuit”. However, there is also a schematic for a 2-wire circuit which does not use capacitors. Can you explain why you did not use capacitors in your setup? I’m counting revolutions of a small wheel (3-5″) and logging that data for analysis.
    Thank you

  • Oki E. Rinaldi

    How long is the maximum distance that can be detected by the sensor?
    I need 5 to 10 cm distance between the sensor and the magnet. Can the sensor handle it? Or, do I need A ‘bigger’ magnet?

  • Don

    I’m confused – don;t Hall Effect Sensors go low on output, not high? That pull-up resistor would make it high as of default, would it not?

  • Nik Fenning

    Hi I am new to arduino in my head I can picture what I want the code to do but dont know how to do it, I am sure its a tiny adjustment to the code but how would I get it toprint just the rpm when there is an increase ?

    Thanks in Advance


  • Gaurav

    rpm = 30*1000/(millis() – timeold)*half_revolutions;

    not getting the above statement whats the use of 30 and 1000 in above statement
    n suggest the modification to convert the code for bike speedometer in KM/Hr

  • Muhammed

    oh, I am sorry.
    You hav already put a link but I did not see.

  • Muhammed

    I am trying to do almost same thing to do university project.
    However, I am not good to use arduino codes.
    If you have this code, can you send me?


    • Arvind Sanjeev

      ITs already in the tutorial, search for the link.

  • santosh

    Please List some non Latching Hall effect Sensors

    • Arvind Sanjeev

      As said in the tutorial, US5881 is an optimal non latching hall effect sensor.

  • Daksh Gulati

    Hi there!
    I wanted to ask if a Reed Switch will be better or a Hall Effect sensor will be better for measuring speed?
    I want to use it in an ATV.

    Thank you =)

    • Arvind Sanjeev

      Personally, I have tried both. And I think the hall effect sensor: US5881 will suit your purpose best.

  • NaEun

    Hi this is NaEun again!
    Thank you for your comment.
    It really helped us a lot :)

    But we have another problem about measuring the speed.
    When we stop the bike(spd==0) the speed value comes out the former speed, not changing to 0. We used “attachinterrupt” that you wrote.
    I’m wondering if you could solve this problem.

    I’ll be looking forward to get your comments.
    Thank you.

    • Arvind Sanjeev

      You can perhaps create a code that checks if it takes a lot of time for the sensor to detect the next interrupt. That is, (if time_for_next_interrupt > long) then speed = 0, or something like that.

  • NaEun

    Hello, I’m a student from Korea and I’m studying arduino.
    I’m making a speedometer and I cannot understand about the “half_revolution” in the code you uploaded. I’m curious what’s the use of it and why use the value 20 for the ‘if’ condition.

    I’ll be glad if you can response to my question:)

    • Arvind Sanjeev

      The half_revolution basically stores the count for the total number of revolutions. It is used to calculate the rpm (total revolutions/time), and 20 is just used as a starting threshold. For calibration, etc, only after the first 20 revolutions will we get the value for rpm.

pingbacks / trackbacks

Leave a Comment

+ 73 = 80

Start typing and press Enter to search