Interfacing Hall Effect Sensor with Arduino

Sensors have always been a vital component in any Project. These are the ones which convert the real real-time environmental data into digital/variable data so that it can be processed by electronics. There are many different types of sensors available in the market and you can select one based on your requirements. In this project we will learn how to use a Hall sensor a.k.a Hall effect sensor with Arduino. This sensor is capable of detecting a magnet and also the pole of the magnet.

Interfacing Hall Effect Sensor with Arduino

Why detect a magnet?, You may ask. Well there are a lot of applications which practically use Hall Effect sensor and we might have never noticed them. One common application of this sensor is to measure speed in bicycles or any rotating machines. This sensor is also used in BLDC motors to sense the position of Rotor Magnets and trigger the Stator coils accordingly. The applications are endless, so let’s learn how to Interface Hall effect sensor Arduino to add up another tool in our arsenal. Here are some projects with Hall sensor:

In this tutorial we will use interrupts function of Arduino to detect the magnet near Hall sensor and glow a LED. Most of the time Hall sensor will be used only with Interrupts because of their applications in which high reading and executing speed is required, hence let us also use interrupts in our tutorial.

Materials Required:

  1. Hall Effect Sensor (any digital verison)
  2. Arduino (Any version)
  3. 10k ohm and 1K ohm Resistor
  4. LED
  5. Connecting Wires

Hall Effect Sensors:

Before we dive into the connections there are few important things that you should know about Hall Effect sensors. There are actually, two different types of Hall sensors one is Digital Hall sensor and the other is Analog Hall sensor. The digital Hall sensor can only detect if a magnet is present or not (0 or 1) but an analog hall sensor’s output varies based on the magnetic field around the magnet that is it can detect how strong or how far the magnet is. In this project will aim only at the digital Hall sensors for they are the most commonly used ones.

Interfacing Hall Effect Sensor with Arduino schematic

As the name suggests the Hall Effect sensor works with the principle of “Hall effect”. According to this law “when a conductor or semiconductor with current flowing in one direction was introduced perpendicular to a magnetic field a voltage could be measured at right angles to the current path”. Using this technique, the hall sensor will be able to detect the presence of magnet around it. Enough of theory let’s get into hardware.

Circuit Diagram and Explanation:

The complete circuit diagram for interfacing Hall sensor with Arduino can be found below.

As you can see, the hall effect sensor arduino circuit diagram is pretty simple. But, the place where we commonly make mistakes is at figuring out the pin numbers of hall sensors. Place the readings facing you and the first pin on your left is the Vcc and then Signal and Ground respectively.

We are going to use Interrupts as told earlier, hence the output pin of Hall sensor is connected to the Pin 2 of the Arduino. The Pin is connected to a LED which will be turned ON when a magnet is detected. I have simply made the connections on a breadboard and it looked somewhat like this below once completed.

Hall Effect Sensor Arduino Code:

The complete Arduino code is just few lines and it can be found at the bottom of this page which can be directly uploaded to your Arduino Board. If you want to know how the program works read further.

We have one input, which is the sensor and one output which is a LED. The sensor has to be connected as an interrupt input. So inside our setup function, we initialize these pins and also make the Pin 2 to work as an interrupt. Here pin 2 is called Hall_sensor and pin 3 is called LED.

void setup() {
  pinMode(LED, OUTPUT); //LED is a output pin
  pinMode(Hall_sensor, INPUT_PULLUP); //Hall sensor is input pin
  attachInterrupt(digitalPinToInterrupt(Hall_sensor), toggle, CHANGE); //Pin two is interrupt pin which will call toggle function
}

When there is a interrupt detected, the toggle function will be called as mentioned in the above line. There are many interrupt parameters like Toggle, Change, Rise, Fall etc. but in this tutorial we are detecting the change of output from Hall sensor.

Read more: Interfacing Hall Effect Sensor with Arduino


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top