Hall effect sensor: everything you need to know for your projects with Arduino

sensor Hall effect

You may be looking for a device that allows you to detect nearby magnetic fields, or to use it as a non-contact switch, for applications that need water protection, etc. In that case, you can use the Hall effect sensors of which I will show you everything you need to know to integrate it with your future Arduino projects. In fact, if you are going to use them together with neodymium magnets, the applications you can get out of them are many.

The connection of this type of device is very simple, as you can see. Moreover, they are very cheap electronic components and you can easily find them in many specialized shops or on the Internet. If you want to know more, you can read on…

The Hall effect

Hall effect diagram

Its name comes from the first discoverer, the American physicist Edwin Herbert Hall. The Hall effect is the physical phenomenon that occurs when an electric field appears by separation of the electric charges inside a conductor through which a magnetic field circulates. This electric field (Hall field) will have a component perpendicular to the movement of the charges and to the perpendicular component of the applied magnetic field. Thus, among other things, the presence of magnetic fields can be detected.

In other words, when a current flows through a conductor or semiconductor and there is a magnetic field nearby, it is verified that a magnetic force appears in the load carriers that regroups them inside the material. That is, the charge carriers will be deflected and grouped on one side of the conductor/semiconductor. As you can imagine, this causes a variation of electric potential in this conductor/semiconductor, producing that electric field perpendicular to the magnetic field.

What is a Hall Effect Sensor?

sensor Hall effect

Therefore, once you know how the Hall Effect works, you can talk about the components or Hall Effect sensors that are able to take advantage of this phenomenon for some practical application. For example, they can be used to make measurements of a magnetic field.

These elements are widely used in many electronic projects and frequently used devices. For example, in vehicles you can find them in some security systems, to measure the position of the camshaft in the engine, to measure fluid speeds, detect metals, and a long etc.

The good thing about this type of Hall effect sensor, unlike others, is that it does not need contact. That is to say, they can do such tasks from a distance, besides being totally immune to electronic noise, dust, etc, so they are quite durable and reliable in their measurements. However, their range is limited, as they need to be at a certain distance from the generated field in order to capture it.


  • Analog: these are very basic devices, with a pin or output that will deliver a signal proportional to the intensity of the magnetic field they are capturing. That is, they are similar to the temperature sensor, the voltage sensor, and other sensors that we have detailed in this blog.
  • Digital ones: in the case of digital ones, they are much more basic than the analog ones. Since they do not deliver an output proportional to the field, but give a high voltage value if there is a magnetic field and low if there is no magnetic field. That is, they cannot be used to measure magnetic fields like the analog ones, simply to detect their presence. Moreover, these digitals can be divided into two additional subcategories:
    • Latch: those of this type are activated when approaching one and maintain their value at the output until the opposite pole is approached.
    • Switch: in these others, the output will not be maintained, they are deactivated when the pole is removed. It is not necessary to approach the opposite pole for the output to change…

I advise you to use are the best for these Hall effect sensors to work well.

If you are looking for an analog type sensor, a good option may be the Hall 49E sensor. With it you can detect the presence of magnetic fields, and also measure them. For example, you can measure nearby magnetic fields, make a tachometer using a magnet to measure the revolutions per minute of an axle or speed, detect when a door is opened or closed with a magnet, etc. You can find this sensor in several stores for a few cents, or for something more if you want to mount it on a PCB with everything you need in a module ready to use with Arduino:

On the other hand, if you are looking for a digital type, then you can buy the Hall sensor A3144, which is also a switch type, that is, it will not be necessary to change the pole. This way you can detect the presence of a metallic object, or if a magnetic field exists or not, and even create an RPM counter as the previous case. This one is also easy to find, and it is as cheap or more than the previous one, both loose and in module:

In the case of analog, you must consult the datasheet of the model you have purchased. By example, in the 49E you will find a graph of how the magnetic field can be measured and it will help you create the formula that you then have to implement in the Arduino source code to calculate the density of the detected magnetic flux (mT). In the case of the 49E it would be: B=53.33V-133.3, due to the magnetic range and the voltage it can deliver at its output .

What is common for digital and analog is the number of pins (pinout), in both cases it is 3. If you put the Hall sensor with its face facing you, that is, with the face where it has the inscriptions towards you, then the left pin will be 1, the central pin will be 2 and the right pin will be 3:

  1. On both the 49E and A3144 it is the 5V power pin.
  2. the control unit is connected in both cases to GND or ground.
  3. in both cases it is the output, that is, the one that measures or detects the magnetic field generating a voltage through it. Remember that in the digital one it will take only two values, high or low, while in the analog one you can apply the previous formula to know how this field is detected…

Integration of the Hall effect sensor with Arduino


wiring diagram of the Hall effect sensor with Arduino

Once you have seen how it works and what you need to know about this Hall Effect sensor, with the pinout described, you should already know how it ‘connects’ to your Arduino board. In this case, it will be connected like this:

  • You already know that pin 1 must be connected to Arduino’s 5V output voltage so that it can be powered, both in the case of digital and analog.
  • The center pin or 2, you have to connect it to GND or ground of your Arduino board.
  • In the case of pin 3, it varies depending on whether it is for analog or digital:
    • Analog: connect pin 3 of the Hall sensor directly to one of the analog inputs of your Arduino board.
    • Digital: you must bridge pin 1 and pin 3 with a pull-up resistor, say 10K, for the circuit to work properly with the A3144. Other models may require different resistance values… Once you take that into account, you can connect pin 3 to a digital input on your Arduino board.

It doesn’t matter the number of the input of the board you have connected it to, just remember the number and then correctly create the source code to make your project work. In this case, there will also be differences between if you have chosen the analog or the digital one:

The simple code for the analog is:

const int pinHall = A0;
void setup() {
  pinMode(pinHall, INPUT);
void loop() {
  //Filter for noise with 10 measures
  long measure = 0;
  for(int i = 0; i < 10; i++){
      int value =
      measure += analogRead(pinHall);
  measure /= 10;
  //Calculate the voltage in mV given by the Hall sensor output
  float outputV = measure * 5000.0 / 1023;
  Serial.print("Output voltage = ");
  Serial.print(" mV ");
  // Magnetic field density interpolation (formula)
  float magneticFlux = outputV * 53.33 - 133.3;
  Serial.print("The magnetic flux density of the field is = ");
  Serial.print(" mT");

const int HALLPin = 2;
const int LEDPin = 13;
// Pin 13 in the diagram of our example does not paint anything, but a LED could be added to that pin to light up if it detects a magnetic field
void setup() {
  pinMode(LEDPin, OUTPUT);
  pinMode(HALLPin, INPUT);
void loop() {
    digitalWrite(LEDPin, HIGH);
    digitalWrite(LEDPin, LOW);

I hope you found this guide helpful…

Leave a Comment