If you need to measure the exact strength or proximity of a magnetic field—not just detect its presence—a linear output hall effect sensor is the right tool. Unlike digital hall switches that snap high or low, linear sensors output a continuous analog voltage proportional to the magnetic flux density. This guide gives you the exact wiring, the raw-to-Gauss conversion math, and the specific part numbers you need to interface one reliably with an ESP32 or Arduino.
How a Linear Output Hall Effect Sensor Works
At the silicon level, these sensors rely on the Lorentz force. When a constant bias current flows through a thin semiconductor element, an applied magnetic field deflects the moving charge carriers to one side of the material. This charge accumulation creates a tiny transverse voltage known as the Hall voltage.
Because the raw Hall voltage is only in the microvolt range, a linear output hall effect sensor integrates an on-chip amplifier to boost this signal into a usable, ratiometric analog voltage. The output scales linearly with the magnetic flux density (measured in Gauss or milliTesla) across the sensor's specified range, allowing your microcontroller's ADC to calculate exact field strength or physical displacement.
Pinout, Wiring, and Power Supply Requirements
The most common packaging for through-hole linear hall sensors is the 3-pin TO-92 (flat side facing you, leads pointing down). Surface mount variants use SOT-23. The pinout is standardized across most major manufacturers.
| Pin | Function | ESP32 Connection | Supply Range & Notes |
|---|---|---|---|
| 1 | VCC | 3.3V Pin | 2.7V to 5.5V (DRV5053) or 4.5V to 6.0V (SS49E) |
| 2 | GND | GND | Common ground with microcontroller |
| 3 | OUT | GPIO 34 (ADC1) | Analog ratiometric output (Do NOT use ADC2 with WiFi) |
Linear hall sensors are ratiometric. This means their quiescent (zero-Gauss) output voltage and sensitivity scale directly with VCC. If you power the sensor from a noisy 5V USB line but read it with the ESP32's 3.3V ADC, your readings will drift wildly and risk clipping. Always power the sensor from the exact same voltage reference your ADC uses. For the ESP32, use a 3.3V-compatible sensor like the TI DRV5053 powered directly from the 3.3V pin.
The Math: Converting Raw ADC Readings to MilliTesla
The analog output of a linear hall sensor follows a simple linear equation:
V_out = V_Q + (S × B)
- V_out: The measured output voltage.
- V_Q: The quiescent voltage (zero-Gauss offset), typically exactly
VCC / 2. - S: The sensor's sensitivity, provided in the datasheet (e.g., mV/mT).
- B: The magnetic flux density in milliTesla (mT). Note: 1 mT = 10 Gauss.
Worked Numeric Example
Let's use the Texas Instruments DRV5053A1. We power it at 3.3V. According to the TI Hall Effect datasheet, the A1 variant has a sensitivity (S) of 31.25 mV/mT.
- Find V_Q: 3.3V / 2 = 1.65V (1650 mV).
- Read the ADC: The ESP32's
analogReadMilliVolts()function returns 2150 mV. - Calculate Delta V: 2150 mV - 1650 mV = 500 mV.
- Solve for B: 500 mV / 31.25 mV/mT = 16 mT (or 160 Gauss).
Here is the exact ESP32 Arduino code to perform this calculation. Note that we use analogReadMilliVolts() instead of raw analogRead() to bypass the ESP32's notoriously non-linear raw ADC mapping, leveraging the factory eFuse calibration data.
// ESP32 Linear Hall Sensor (DRV5053A1) Interface
const int HALL_PIN = 34; // ADC1 channel, safe for WiFi use
const float VCC_MV = 3300.0;
const float SENSITIVITY_MV_MT = 31.25; // DRV5053A1 specific
void setup() {
Serial.begin(115200);
analogReadResolution(12); // 12-bit for ESP32
}
void loop() {
// Read calibrated voltage directly in millivolts
int v_out_mv = analogReadMilliVolts(HALL_PIN);
// Calculate Quiescent Voltage (Zero-Gauss offset)
float v_q_mv = VCC_MV / 2.0;
// Calculate Delta V
float delta_v = v_out_mv - v_q_mv;
// Calculate Magnetic Flux Density (mT and Gauss)
float magnetic_field_mT = delta_v / SENSITIVITY_MV_MT;
float magnetic_field_gauss = magnetic_field_mT * 10.0;
Serial.printf('V_out: %d mV | Field: %.2f mT (%.1f Gauss)\n',
v_out_mv, magnetic_field_mT, magnetic_field_gauss);
delay(100);
}
Calibration, Drift, and Interference Sources
Bench testing linear hall sensors reveals three primary interference sources that will ruin your data if ignored:
- AC Mains EMI: 50/60Hz magnetic fields from nearby transformers, AC wiring, or switching power supplies will induce a visible sine-wave ripple on your ADC readings. Fix: Use twisted-pair wiring for the sensor leads, keep the sensor at least 2 inches away from AC mains, and add a 100nF ceramic bypass capacitor directly across the VCC and GND pins at the sensor body.
- Temperature Drift: Both the quiescent offset and the sensitivity drift with temperature (typically ±0.1% per °C). If your project operates in an unconditioned garage or outdoors, you must log the ambient temperature and apply a software compensation curve, or mount the sensor away from heat-generating components like voltage regulators.
- Mechanical Package Stress: This is the most overlooked failure mode. The piezoresistive effect in silicon means that physical stress on the IC die alters the zero-Gauss offset. If you bend the leads of a TO-92 package too close to the plastic body, or if you solder it with excessive heat, the V_Q will permanently shift away from VCC/2. Fix: Bend leads at least 2mm below the package body and use a temperature-controlled iron at 320°C for under 3 seconds per pin.
For software calibration, always read the sensor in a known zero-Gauss environment (away from magnets and large ferrous metals) on boot, and store that value as your dynamic V_Q rather than hardcoding VCC/2. For deep dive into ESP32 ADC calibration APIs, refer to the Espressif ADC Calibration documentation.
Decision Matrix: Which Linear Hall Sensor to Buy
Do not conflate linear sensors with digital switches. If you just need a limit switch or RPM counter, buy a digital sensor like the A3144. If you need proportional displacement or current sensing, use the decision tree below to pick your linear part.
| If your project requires... | Then choose this sensor family... | Specific Part Number |
|---|---|---|
| Native 3.3V operation for ESP32/STM32 without voltage dividers | TI DRV5053 Series (Low voltage, high sensitivity) | DRV5053A1 (TO-92) |
| 5V operation for Arduino Uno/Mega with high precision | Honeywell SS49E Series (Classic, low noise) | SS49E |
| Measuring very high magnetic fields (up to 150 mT) | Melexis MLX90242 (Programmable linear) | MLX90242 |
| Just a simple ON/OFF proximity trigger | Wrong sensor type. Buy a digital switch. | A3144 / DRV5012 |
For 90% of modern maker projects using 3.3V logic (ESP32, Raspberry Pi Pico, ESP8266), buy the Texas Instruments DRV5053A1. It natively supports 2.7V to 5.5V, meaning you can power it directly from the 3.3V pin. This keeps the analog output perfectly within the 0-3.3V ADC range without requiring resistor voltage dividers, which would otherwise destroy the ratiometric accuracy of the sensor. It costs roughly $0.60 in single quantities and is widely available on Mouser and DigiKey.
By matching your sensor's supply voltage to your microcontroller's ADC reference, applying the correct sensitivity constant in your code, and physically isolating the sensor from AC EMI, you will achieve stable, sub-milliTesla resolution on your workbench.






