Language: EN

medir-campos-magneticos-arduino-hall-49e

Measuring Magnetic Fields with Arduino and 49E Linear Hall Sensor

What is a Hall sensor?

A Hall sensor is a device that allows us to measure magnetic fields.

Hall sensors are widely used. For example, in the automotive industry, they are used for functions as diverse as the activation of seat belts or the measurement of the camshaft position. They are also used to measure fluid speeds, metal detection, induction factors, among many other applications.

An important advantage of Hall sensors is that they measure at a distance, without the need for physical contact. Although their range is limited (typically a few centimeters), this means that they present almost no mechanical wear. Additionally, they are immune to noise and dust. This makes them reliable and durable sensors.

In general, we find two types of Hall sensors:

  • Analog. They generate an output proportional to the intensity of the magnetic field. Used to measure the intensity of a magnetic field.
  • Digital. Provide a high value in the presence of a magnetic field, and a low value in the absence of one. Therefore, they are used to detect the existence of magnetic fields. They are further divided into,
  • Switch, they are activated when the pole is approached, and deactivated when the pole is removed
  • Latch, they are activated when one pole is approached, and maintain their value until the opposite pole is approached

In this post, we will use a 49E analog Hall sensor. We can use this sensor to detect the presence of an object, to which we have previously attached a small magnet, or to manufacture tachometers (revolution counters) simply by attaching a small neodymium magnet to the shaft.

Price

49E Hall sensors are really cheap. We can find 10 A49E devices for €0.90 from international sellers on eBay or AliExpress.

arduino-sensor-hall-49e-componente

How does a Hall sensor work?

Its operating principle is the Hall effect, named after its discoverer Edwin Herbery Hall, in 1849.

By passing an electric current through a semiconductor in the presence of a magnetic field, the electrons are deflected by the magnetic field, resulting in a voltage perpendicular to the current and the magnetic field.

efecto-hall

By measuring this voltage caused by the Hall effect, we can build magnetic field sensors and meters.

The family of 49E Hall sensors incorporate the electronics necessary to provide a linear voltage response in the range of -100 to 100 mT. The circuits are designed to minimize signal noise, so external filtering is not necessary.

arduino-sensor-hall-49e-funcionamiento

The operating temperature range is -40 to 85ºC, and it has little influence on the measurement. The typical sensitivity at 25ºC is 18 mV/mT.

arduino-sensor-hall-49e-curva

Interpolating in the previous graph, we obtain the following expression for the voltage response to the magnetic flux measured by the 49E Hall sensor,

Or equivalently, by reversing the equation, we arrive at the equation necessary to obtain the magnetic flux density from the sensor response,

Assembly diagram

The electrical diagram we need is as follows.

arduino-sensor-hall-49e-esquema

So the connection diagram with Arduino would be as follows.

arduino-sensor-hall-49e-montaje

The diagram and resistor values shown correspond to the 49E sensor. Other Hall sensors require different assembly diagrams. Check their corresponding datasheet if your component is different.

Code example

To be able to calculate the magnetic field from the measurement, first we measure the voltage using an analog input of Arduino. Then we convert the voltage into magnetic flux density using the formula we interpolated earlier.

const int pinHall = A0;

void setup() {
  pinMode(pinHall, INPUT);
  Serial.begin(9600);
}

void loop() {

  //average of 10 measurements to filter noise
  long measure = 0;
  for(int i = 0; i < 10; i++){
      int value = 
      measure += analogRead(pinHall);
  }
  measure /= 10;
  
  //calculation of voltage in mV
  float outputV = measure * 5000.0 / 1023;
  Serial.print("Output Voltage = ");
  Serial.print(outputV);
  Serial.print(" mV   ");
  
  //interpolation to magnetic flux density
  float magneticFlux =  outputV * 53.33 - 133.3;
  Serial.print("Magnetic Flux Density = ");
  Serial.print(magneticFlux);
  Serial.print(" mT");
  
  delay(2000);
}

We learn to measure magnetic fields with Arduino and the 49E Linear Hall Sensor

Download the code

All the code from this post is available for download on Github. github-full