A Hall effect sensor works by passing a bias current through a thin semiconductor strip; when a magnetic field is applied perpendicular to the current, the Lorentz force deflects charge carriers, creating a measurable transverse voltage (the Hall voltage) proportional to the magnetic flux density. In practical microcontroller terms, it translates invisible magnetic fields into a readable analog voltage or a clean digital HIGH/LOW pulse, allowing your Arduino or ESP32 to measure position, speed, or current without physical contact.

The Physics: How the Hall Effect Actually Works

Discovered by Edwin Hall in 1879, the effect relies on the behavior of charge carriers (electrons or holes) moving through a p-type or n-type semiconductor wafer. When you apply a constant bias current across the wafer, the carriers move in a straight line. However, introducing a magnetic field perpendicular to this current flow exerts a Lorentz force on the moving charges, pushing them toward one edge of the semiconductor strip.

As carriers pile up on that edge, they create an electric field that opposes further deflection. Equilibrium is reached almost instantly, and the resulting potential difference across the transverse axis is the Hall voltage. Because this raw voltage is typically in the microvolt range, modern integrated circuit (IC) Hall sensors include on-chip differential amplifiers, voltage regulators, and temperature compensation circuitry to output a robust, usable signal.

Analog vs. Digital: Don't Conflate the Outputs

The most common mistake beginners make is buying a 'Hall sensor' without checking if it is linear (analog) or a switch (digital). They are fundamentally different tools.

Analog (Linear) Sensors: Devices like the Allegro A1302 or TI DRV5053 output a continuous voltage that scales linearly with the magnetic flux density (measured in Gauss or milliTesla). With no magnetic field present, the output sits at a quiescent voltage (usually exactly half of VCC). As a north pole approaches, the voltage rises; as a south pole approaches, it falls. These are used for measuring distance, joystick position, or current sensing.

Digital (Switch/Latch) Sensors: Devices like the Melexis US5881 or TI DRV5012 output a binary signal. They contain an internal Schmitt trigger with built-in hysteresis. The output pin (usually open-drain) pulls LOW only when the magnetic field exceeds a specific threshold (e.g., 50 Gauss) and releases HIGH only when it drops below a lower threshold (e.g., 30 Gauss). These are used for RPM counting, limit switches, and BLDC motor commutation.

Wiring and Pinout Specifications

Most through-hole Hall ICs share a standard 3-pin SIP (Single In-line Package) footprint. Always verify the datasheet, as reversing VCC and GND will instantly destroy the internal silicon die.

Part Number Type Supply Range (VCC) Output Type Quiescent / Threshold
Allegro A1302 Analog 4.5V to 6.0V Ratiometric Voltage VCC / 2 (approx 2.5V)
TI DRV5053 Analog 2.5V to 5.5V Absolute Voltage 0.5V (Z1 variant)
Melexis US5881 Digital Switch 2.2V to 24V Open-Drain (needs pull-up) B_op: 50G / B_rp: 30G
TI DRV5012 Digital Latch 1.65V to 5.5V Push-Pull B_op: 30G / B_rp: -30G
Bench Tip: If you are using a 5V analog sensor (like the A1302) with a 3.3V ESP32, do not feed the sensor's output directly into the ESP32's GPIO. The quiescent voltage is 2.5V, but a strong magnet can push the output to 4.5V, which will fry the ESP32's ADC pin. Use a simple voltage divider (e.g., 10kΩ and 20kΩ) to scale the 0-5V output down to 0-3.3V.

Converting Raw ADC Readings to Gauss (The Math)

To get actionable physical units from an analog sensor, you must map the raw ADC integer back to voltage, and then apply the sensor's sensitivity factor. Let's use the ubiquitous Allegro A1302 (1.3 mV/G sensitivity variant) connected to a 5V Arduino Uno (10-bit ADC, 0-1023 range).

The Math:

  1. Raw to Voltage: $V_{out} = (ADC_{raw} / 1023.0) \times 5.0$
  2. Find the Delta: $\Delta V = V_{out} - V_{quiescent}$ (where $V_{quiescent} = 2.5V$)
  3. Voltage to Gauss: $B (Gauss) = \Delta V / 0.0013$ (since sensitivity is 1.3 mV/G, or 0.0013 V/G)

Here is the complete, copy-pasteable C++ implementation with calibration offset handling:

const int HALL_PIN = A0;
const float VCC = 5.0;
const float ADC_MAX = 1023.0;
const float SENSITIVITY = 0.0013; // 1.3 mV/G for A1302
const float QUIESCENT_V = 2.5;

float zeroFieldOffset = 0.0; // Calibration variable

void setup() {
  Serial.begin(115200);
  // Calibration: Read the sensor with NO magnets nearby
  float rawSum = 0;
  for(int i=0; i<50; i++) {
    rawSum += analogRead(HALL_PIN);
    delay(10);
  }
  float zeroV = (rawSum / 50.0 / ADC_MAX) * VCC;
  zeroFieldOffset = zeroV - QUIESCENT_V;
  Serial.println("Calibration complete. Zero-field offset: " + String(zeroFieldOffset));
}

void loop() {
  int rawADC = analogRead(HALL_PIN);
  float voltage = (rawADC / ADC_MAX) * VCC;
  
  // Subtract quiescent voltage AND the calibrated environmental offset
  float deltaV = voltage - QUIESCENT_V - zeroFieldOffset;
  float gauss = deltaV / SENSITIVITY;
  
  // Convert Gauss to milliTesla (1 mT = 10 Gauss)
  float mT = gauss / 10.0; 
  
  Serial.print("Raw: "); Serial.print(rawADC);
  Serial.print(" | Gauss: "); Serial.print(gauss, 1);
  Serial.print(" | mT: "); Serial.println(mT, 2);
  
  delay(100);
}

Interference, Calibration, and Edge Cases

Hall sensors are incredibly reliable, but they are not immune to environmental physics. According to All About Circuits, understanding interference is critical for precision applications.

Electromagnetic Interference (EMI): Because Hall sensors measure magnetic flux, running high-current AC traces near the sensor will induce false readings via the Biot-Savart law. Keep sensor wiring away from motor phases and use twisted-pair cables for long runs to reject common-mode noise.

Temperature Drift: The Hall coefficient is inherently temperature-dependent. While modern ICs use on-chip thermistors to compensate for this, extreme thermal gradients across the silicon die can still cause a 1-2% drift. Always allow the sensor to reach thermal equilibrium before taking baseline calibration readings.

Mechanical Stress: The piezoresistive effect means that physical bending of the sensor's leads or potting the IC in a rigid, shrinking epoxy can alter the baseline output. If you are potting a sensor for a harsh environment, use a soft, flexible silicone conformal coating rather than hard epoxy.

Frequently Asked Questions

How does a hall effect sensor work in a brushless DC (BLDC) motor?

In a BLDC motor, three digital Hall effect latches (like the DRV5012) are embedded in the stator, spaced 120 electrical degrees apart. As the rotor's permanent magnets spin past, the sensors output a 3-bit binary sequence (e.g., 101, 100, 110) that tells the motor controller exactly where the rotor is. The controller uses this data to commutate the stator coils at the exact right microsecond. I once spent three hours debugging a BLDC commutation stutter only to realize the hall sensors were mounted 2mm too far from the rotor magnets, dropping the flux density below the 30 Gauss hysteresis threshold of the switches.

How does a hall effect sensor work with an ESP32's non-linear ADC?

This is a major trap for embedded engineers. The ESP32's internal 12-bit ADC is notoriously non-linear near the 0V and 3.3V rails, and its actual usable range is roughly 0.1V to 3.1V. If you wire a 3.3V analog Hall sensor directly to an ESP32, readings near the quiescent voltage might be accurate, but strong magnetic fields pushing the output toward 3.3V will compress and distort. For precision work with an ESP32, either use the ESP-IDF ADC calibration API to apply factory-stored eFuse correction values, or bypass the internal ADC entirely and use an external I2C ADC like the ADS1115.

How does a hall effect sensor work to measure AC current?

To measure AC current without breaking the circuit, you pass the current-carrying wire through a high-permeability toroidal magnetic core (like ferrite or silicon steel). The AC current generates a proportional alternating magnetic field inside the core's air gap. A linear Hall effect sensor placed precisely in that air gap measures the flux density. Because the sensor is galvanically isolated from the high-voltage AC line, it safely outputs a low-voltage analog waveform that your microcontroller can sample to calculate RMS current. This is the exact principle used in commercial clamp meters and PCB-mount current transducers like the Allegro ACS712.