The Physics: How Hall Effect Sensors Detect Magnetic Fields
When a current-carrying semiconductor is placed in a magnetic field, the Lorentz force deflects the moving charge carriers to one side of the material. This charge accumulation creates a transverse voltage difference perpendicular to both the current flow and the magnetic field, known as the Hall voltage. Because the raw Hall voltage in silicon is typically in the microvolt range, modern integrated Hall effect sensors include on-die amplifiers, voltage regulators, and temperature compensation circuits to output a usable signal.
The magnitude and polarity of this output voltage scale linearly with the magnetic flux density (measured in Gauss or milliTesla) passing through the die. By measuring this output, a microcontroller can determine not just the presence of a magnet, but its exact distance, polarity, and rotational angle. For a deeper dive into the underlying semiconductor physics, All About Circuits provides an excellent breakdown of Hall Effect magnetic field measurement.
Sensor Selection: Digital Switches vs. Linear Analog vs. 3D
The most common mistake makers make is buying a digital Hall switch when they need an analog linear sensor, or vice versa. Digital sensors (like the ubiquitous A3144) only output a HIGH or LOW logic level when a magnetic threshold is crossed, making them perfect for RPM counting or limit switches. Linear sensors (like the SS49E or DRV5055) output a continuous voltage proportional to the magnetic field strength, which is required for joystick positioning, current sensing, or proximity measurement.
| Part Number | Type | Supply Range (VCC) | Output / Sensitivity | Typical Price (2026) |
|---|---|---|---|---|
| A3144 | Digital Switch | 4.5V - 24.0V | Open-Drain LOW (NPN) | $0.12 |
| SS49E | Linear Analog | 2.7V - 6.5V | 1.4 mV/Gauss (Ratiometric) | $0.45 |
| DRV5055 | Linear Analog | 2.5V - 5.5V | 50 mV/mT (High Sensitivity) | $0.68 |
| MLX90393 | 3D I2C Digital | 2.2V - 3.6V | 16-bit I2C (X, Y, Z axes) | $2.85 |
If you are interfacing with a 3.3V microcontroller like the ESP32 or Raspberry Pi Pico, avoid the A3144 unless you use a level shifter or pull-up resistor to 3.3V. The DRV5055 and SS49E are excellent choices for 3.3V and 5V analog systems. For complex spatial tracking, the MLX90393 communicates via I2C and eliminates ADC noise entirely. Consult the Texas Instruments Hall Effect Sensors overview for detailed application notes on their DRV series.
Wiring Pinouts and Microcontroller Integration
Almost all through-hole and SMD Hall sensors follow a standard 3-pin footprint. When looking at the flat face of the sensor with the pins pointing down, the pinout from left to right is typically VCC, GND, and OUT. Always verify this against the specific datasheet, as some surface-mount packages reverse the order.
| Pin | Function | ESP32 Connection | Arduino Uno Connection |
|---|---|---|---|
| 1 (Left) | VCC (Supply) | 3V3 or 5V pin | 5V pin |
| 2 (Middle) | GND (Ground) | GND | GND |
| 3 (Right) | OUT (Signal) | GPIO 34 (ADC1) | A0 (Analog In) |
If you are using a digital sensor like the A3144, the output pin is open-drain. It can pull the line to GND, but it cannot drive it HIGH. You must add a pull-up resistor (typically 4.7kΩ to 10kΩ) between the OUT pin and your microcontroller's logic VCC (3.3V or 5V), or enable the microcontroller's internal pull-up resistor in code.
The Math: Converting Raw ADC to MilliTesla (mT)
An analog linear Hall sensor outputs a voltage that shifts above or below a quiescent (zero-field) baseline. For a ratiometric sensor like the SS49E powered at 5.0V, the quiescent voltage ($V_q$) is exactly half the supply voltage (2.5V). When a South pole approaches, the voltage rises; when a North pole approaches, it falls.
The physical magnetic flux density ($B$) in milliTesla is calculated using the sensor's sensitivity ($S$). The SS49E has a typical sensitivity of 1.4 mV/Gauss, which converts to 14 mV/mT (since 1 mT = 10 Gauss).
The Raw-to-Unit Formula:
$B (mT) = \frac{V_{out} - V_q}{S}$
Worked Numeric Example:
- Supply Voltage ($V_{CC}$): 5.0V
- Quiescent Voltage ($V_q$): 2.5V (2500 mV)
- Measured Output ($V_{out}$): 3.2V (3200 mV)
- Sensitivity ($S$): 14 mV/mT
- Calculation: $(3200 - 2500) / 14 = 700 / 14 = \mathbf{50 mT}$
When using an ESP32, do not use the raw 12-bit `analogRead()` values directly for physics calculations. The ESP32's ADC is notoriously non-linear at the extreme ends of its range. Instead, use the `analogReadMilliVolts()` function, which applies the factory-stored eFuse calibration data to return a highly accurate millivolt reading. According to the Espressif ADC Oneshot Driver Documentation, this function significantly reduces unit-to-unit variance.
// ESP32 Arduino Core: Linear Hall Sensor (SS49E) Reading
const int HALL_PIN = 34;
const float VCC_MV = 5000.0; // Measure your actual 5V rail with a multimeter!
const float SENSITIVITY = 14.0; // mV per mT for SS49E
void setup() {
Serial.begin(115200);
analogReadResolution(12);
}
void loop() {
// Get calibrated voltage in millivolts
int v_out_mv = analogReadMilliVolts(HALL_PIN);
// Calculate quiescent voltage (half of VCC)
float v_q_mv = VCC_MV / 2.0;
// Convert to milliTesla
float magnetic_field_mT = (v_out_mv - v_q_mv) / SENSITIVITY;
Serial.print("Field: ");
Serial.print(magnetic_field_mT);
Serial.println(" mT");
delay(100);
}
Defeating Interference, Calibration, and Temperature Drift
Hall sensors are incredibly useful, but they are highly susceptible to environmental noise. If your readings are jittery or drifting, you are likely encountering one of three common interference sources.
1. Stray Magnetic Fields from Motors and Transformers
Stepper motors, brushless DC motors, and AC transformers leak significant magnetic flux. If your Hall sensor is mounted within 3-5 cm of a stepper motor, the sensor will read the motor's rotor magnets even when your target magnet is absent. Fix: Increase the physical distance, use a mu-metal shield, or implement a software baseline offset that subtracts the ambient stray field when the system is idle.
2. Electromagnetic Interference (EMI) from Switching Regulators
Buck and boost converters switch at frequencies between 50 kHz and 2 MHz. The high di/dt (change in current over time) loops on your PCB generate localized magnetic fields that the Hall sensor will interpret as a physical magnet. Fix: Route high-current switching loops as tightly as possible, keep the Hall sensor at least 2 cm away from the inductor, and add a 100 nF ceramic decoupling capacitor directly across the sensor's VCC and GND pins.
3. Temperature Drift and Calibration
While modern ICs have internal temperature compensation, the quiescent voltage ($V_q$) can still drift by a few millivolts across a wide temperature range (e.g., an outdoor enclosure going from 5°C to 45°C). Because 14 mV equals 1 mT on the SS49E, a 7 mV thermal drift introduces a 0.5 mT error. Fix: For precision applications, implement a 'tare' function in your code. Read the sensor at startup (with no target magnet present) and store that value as your dynamic $V_q$ offset. For extreme precision, upgrade to a digital I2C sensor like the MLX90393, which performs temperature compensation in the digital domain before transmitting the data.






