If you need to measure continuous physical position, fluid level, or pedal travel without mechanical contact, you need a linear sensor. Specifically, a linear Hall effect sensor outputs a continuous analog voltage proportional to magnetic flux density, unlike digital Hall switches that only snap HIGH or LOW at a fixed threshold. But connecting one to an ESP32 or Arduino isn't as simple as wiring a potentiometer; you must account for ratiometric scaling, ADC non-linearity, and magnetic interference. This guide gives you the exact wiring, the raw-to-unit math, and a concrete part recommendation to get your position tracking working on the first try.

The Sensing Principle: How Linear Hall Sensors Work

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 measurable transverse voltage—the Hall voltage—which is strictly proportional to the magnetic flux density (measured in Gauss or milliTesla) passing perpendicularly through the die. Unlike digital Hall switches that use an internal Schmitt trigger to snap to a binary HIGH or LOW at a specific threshold, a linear sensor amplifies this raw Hall voltage and outputs it as a continuous analog signal.

Modern linear Hall ICs incorporate spinning-current chopper stabilization and ratiometric output stages. The chopper circuit eliminates the native offset voltage drift inherent in the silicon, while the ratiometric design ensures that the output voltage scales proportionally with the supply voltage. This means if your 3.3V rail sags to 3.2V, both the sensor's quiescent baseline and its sensitivity shift together, preserving the accuracy of your physical measurement without requiring complex software compensation.

Wiring, Supply Range, and Raw-to-Unit Math

The most common mistake hobbyists make with linear sensors is powering them with 5V and feeding the output directly into an ESP32 GPIO pin. The ESP32's ADC pins are strictly limited to 3.3V; a 5V sensor outputting 4.5V under a strong magnetic field will permanently damage the microcontroller's input circuitry. Always power your linear sensor from the ESP32's 3.3V rail.

Wiring and Pinout Table

Sensor Pin Function ESP32 Connection Notes & Constraints
VCC Power Supply 3V3 Pin Acceptable range: 2.5V to 5.5V. Use 3.3V for ESP32 safety.
GND Ground GND Pin Keep ground return path short to avoid switching noise.
VOUT Analog Output GPIO 34 (ADC1_CH6) Use ADC1 pins (e.g., 32-36). Avoid ADC2 if using WiFi.

The Raw-to-Unit Math (Voltage to milliTesla)

Because the sensor is ratiometric, its quiescent (zero-magnetic-field) output is exactly half of the supply voltage. At a 3.3V supply, $V_{Q} = 1650\text{ mV}$. The output scales based on the sensor's sensitivity ($S$), typically measured in mV/mT. For the TI DRV5055A1, $S = 13\text{ mV/mT}$.

The Formula:
$B\text{ (mT)} = \frac{V_{OUT} - V_{Q}}{S}$

Worked Example:
You move a neodymium magnet near the sensor. Your multimeter reads $1845\text{ mV}$ at the VOUT pin.
1. Calculate the delta: $1845\text{ mV} - 1650\text{ mV} = 195\text{ mV}$.
2. Divide by sensitivity: $195\text{ mV} / 13\text{ mV/mT} = 15\text{ mT}$.
The magnetic flux density at the sensor face is exactly 15 milliTesla.

Callout Tip: Polarity Matters
Hall sensors detect magnetic polarity. A North pole facing the branded side of the IC will drive the voltage above the quiescent baseline (positive mT). A South pole will drive it below the baseline (negative mT). If your readings are inverted, flip your magnet.

Calibration, Scaling, and Interference Sources

While the math above is theoretically perfect, real-world embedded environments introduce three major interference sources that require calibration and hardware mitigation.

  1. ESP32 ADC Non-Linearity: The ESP32's raw 12-bit ADC (0-4095) is notoriously non-linear, particularly near the 0V and 3.3V rails, and suffers from significant chip-to-chip variance. Fix: Never use raw analogRead() for physical measurements. Always use analogReadMilliVolts(), which leverages the ESP32's internal eFuse calibration data to return a highly accurate millivolt reading.
  2. Electromagnetic Interference (EMI): Linear sensors have high-gain internal op-amps that act as antennas for high-frequency noise from nearby switching buck converters or PWM motor drivers. Fix: Place a 100nF (0.1µF) ceramic bypass capacitor directly across the VCC and GND pins of the sensor, as close to the IC body as physically possible. Route analog traces away from motor power lines.
  3. Mechanical Gap Variation: Magnetic field strength follows an inverse-cube law relative to distance from a dipole magnet. A mechanical vibration that changes the air gap between the magnet and sensor by just 1mm can cause a massive swing in output voltage. Fix: Use a rigid mechanical housing, or switch to a diametrically magnetized cylinder magnet rotating on an axis rather than a magnet moving linearly in and out.

Decision Tree: Which Linear Sensor Part Number to Buy

Not every position-tracking job requires the same component. Use this decision matrix to select the right transducer for your specific mechanical constraints. Do not default to a digital switch when you need proportional data, and do not use a slide pot where moisture or dust is present.

Application Condition Required Output Type Concrete Part Recommendation
Travel distance is > 50mm, environment is clean/dry, physical contact is acceptable. Analog Voltage (Resistive) Bourns PTB0143 (10kΩ Linear Slide Pot)
Need to detect if a door/window is simply open or closed (binary threshold). Digital (Push-Pull / Open-Drain) Allegro A3144 Digital Hall Switch
Legacy designs, low precision, basic hobby projects where temp drift is acceptable. Analog Voltage (Hall) Honeywell SS49E (Classic linear Hall)
Non-contact, continuous position tracking, high precision, wide temperature range, modern embedded systems. Analog Voltage (Ratiometric Hall) Texas Instruments DRV5055A1
Default Recommendation: For >90% of embedded non-contact position tracking tasks (throttle pedals, valve position, suspension travel), buy the Texas Instruments DRV5055A1. It offers superior temperature stability, chopper-stabilized offset reduction, and a true ratiometric output that pairs perfectly with the ESP32's 3.3V ADC architecture. If you need a wider magnetic range, step up to the DRV5055A3.

ESP32 Interfacing: Production-Ready C++ Code

The following code implements the raw-to-unit math using the ESP32's calibrated millivolt function. It includes a zero-Gauss calibration routine on boot to account for any local ambient magnetic fields (like steel brackets or nearby speakers) that might shift your baseline away from the theoretical 1650mV.

/*
 * Linear Hall Effect Sensor Interfacing for ESP32
 * Target Sensor: TI DRV5055A1 (Sensitivity: 13 mV/mT)
 * Wiring: VCC to 3V3, GND to GND, VOUT to GPIO 34
 */

const int HALL_PIN = 34;
const float SENSITIVITY_MV_MT = 13.0; // DRV5055A1 specific

float quiescentVoltage_mV = 1650.0; // Default VCC/2

void calibrateZeroGauss() {
  Serial.println("Calibrating zero-Gauss baseline... keep magnets away!");
  float sum = 0;
  int samples = 50;
  for (int i = 0; i < samples; i++) {
    sum += analogReadMilliVolts(HALL_PIN);
    delay(10);
  }
  quiescentVoltage_mV = sum / samples;
  Serial.printf("Baseline calibrated to: %.1f mV\n", quiescentVoltage_mV);
}

void setup() {
  Serial.begin(115200);
  delay(1000); // Allow serial monitor to connect
  
  // Configure ADC pin
  analogReadResolution(12); // Ensure 12-bit resolution
  pinMode(HALL_PIN, INPUT);
  
  calibrateZeroGauss();
}

void loop() {
  // Read calibrated voltage directly (bypasses raw ADC non-linearity)
  float vOut_mV = analogReadMilliVolts(HALL_PIN);
  
  // Calculate magnetic flux density in milliTesla
  float delta_mV = vOut_mV - quiescentVoltage_mV;
  float magneticField_mT = delta_mV / SENSITIVITY_MV_MT;
  
  // Optional: Convert mT to Gauss (1 mT = 10 Gauss)
  float magneticField_Gauss = magneticField_mT * 10.0;
  
  Serial.printf("Vout: %6.1f mV | Field: %5.2f mT (%6.1f Gauss)\n", 
                vOut_mV, magneticField_mT, magneticField_Gauss);
  
  delay(100); // 10Hz sample rate
}

By anchoring your math to analogReadMilliVolts() and capturing a real-world baseline on boot, you eliminate the two largest sources of error in ESP32 analog sensing. Pair this with the DRV5055A1's hardware-level temperature compensation, and your linear sensor setup will deliver bench-grade position data in the field.