The Sensing Principle: How Linear Hall Sensors Work
A hall effect linear position sensor relies on the Lorentz force to measure magnetic flux density. When a bias current flows through a thin semiconductor wafer inside the sensor and a perpendicular magnetic field is applied, the charge carriers are deflected to one side of the material. This deflection creates a transverse voltage difference—the Hall voltage—which is strictly proportional to the strength of the magnetic field passing through the die. Internal amplifiers condition this microvolt-level signal into a usable ratiometric analog output.
It is critical to distinguish these linear devices from digital Hall switches (like the ubiquitous A3144). While a digital switch only snaps to a binary HIGH or LOW state when a specific magnetic threshold is crossed, a linear hall effect sensor outputs a continuous voltage that tracks the exact proximity and polarity of the magnet. Common workhorse part numbers for linear sensing include the Honeywell SS49E and the Texas Instruments DRV5055, both of which provide continuous analog feedback ideal for stroke measurement, throttle position, and suspension travel tracking.
Wiring and Pinout: Interfacing the SS49E and DRV5055
Because these sensors output an analog voltage, they interface directly with the analog-to-digital converter (ADC) pins of your microcontroller. The output is ratiometric, meaning the quiescent (zero-magnet) voltage and the sensitivity scale proportionally with the supply voltage. Below is the hardware specification and wiring guide for the two most common linear sensors used in embedded projects.
| Parameter | Honeywell SS49E (TO-92) | TI DRV5055 (SOT-23 / TO-92) |
|---|---|---|
| Pin 1 (VCC) | Supply Input | Supply Input (VA) |
| Pin 2 (GND) | Ground | Ground |
| Pin 3 (OUT) | Analog Output | Analog Output |
| Supply Range | 2.7V to 6.5V | 2.5V to 38V |
| Quiescent Output (3.3V Supply) | ~1.65V (VCC / 2) | ~1.65V (VCC / 2) for bidirectional variants |
| Sensitivity (at 3.3V) | ~0.92 mV/Gauss | Depends on suffix (e.g., A1 = 21 mV/mT) |
If you are powering the SS49E at 3.3V to match the ESP32 logic levels, remember that the ESP32's native ADC is highly non-linear below 0.15V and above 3.1V. Because the SS49E quiescent voltage sits perfectly at 1.65V, you have roughly 1.45V of clean swing in either magnetic direction before hitting the ESP32's ADC dead zones. Keep your magnet gap calibrated to stay within this 0.2V to 3.0V window.
Output Signal Math: Converting Raw ADC to Millimeters
Translating the sensor's raw 12-bit ADC reading into a physical distance (millimeters) requires a two-step mathematical process. First, we convert the raw digital count back into a voltage. Second, we map that voltage to physical travel. Because magnetic field strength drops off according to an inverse-cube law relative to distance, the voltage-to-distance relationship is inherently non-linear. For short travel ranges (under 15mm), a linear approximation works; for longer throws, you must use a 2-point or polynomial calibration.
Here is the baseline linear scaling math for a short-stroke application (e.g., a 10mm brake lever travel) using an ESP32 and an SS49E powered at 3.3V:
- Raw to Voltage:
Voltage = (ADC_Raw / 4095.0) * 3.3 - Voltage to Delta:
Delta_V = Voltage - 1.65(Assuming 1.65V is the zero-position quiescent baseline). - Delta to Millimeters:
Position_mm = Delta_V * Scale_Factor
Below is the complete, copy-pasteable C++ implementation for the Arduino IDE, utilizing an exponential moving average to filter out high-frequency ADC jitter.
// Pin Definitions
const int HALL_PIN = 34; // ADC1_CH6 (GPIO 34 on ESP32)
// Calibration Constants (Determine these empirically)
const float VCC = 3.3;
const float QUIESCENT_V = 1.65;
const float MM_PER_VOLT = 8.5; // Example: 8.5mm of travel per 1V change
// Filtering
float filteredVoltage = QUIESCENT_V;
const float alpha = 0.15; // Smoothing factor (0.0 to 1.0)
void setup() {
Serial.begin(115200);
analogReadResolution(12); // Ensure 12-bit resolution (0-4095)
}
void loop() {
int rawADC = analogRead(HALL_PIN);
// Convert raw 12-bit ADC to voltage
float currentVoltage = (rawADC / 4095.0) * VCC;
// Apply Exponential Moving Average (EMA) filter
filteredVoltage = (alpha * currentVoltage) + ((1.0 - alpha) * filteredVoltage);
// Calculate physical position
float deltaV = filteredVoltage - QUIESCENT_V;
float positionMM = abs(deltaV * MM_PER_VOLT);
Serial.print("Raw: "); Serial.print(rawADC);
Serial.print(" | V: "); Serial.print(filteredVoltage, 3);
Serial.print(" | Pos: "); Serial.print(positionMM, 2); Serial.println(" mm");
delay(20); // 50Hz sampling rate
}
To find your specific MM_PER_VOLT scale factor, place your magnet at the minimum and maximum physical travel limits. Record the voltages at both points, measure the physical distance with calipers, and divide the distance by the voltage delta. For a deeper look into ESP32 ADC calibration techniques, refer to the Espressif ADC Oneshot Driver Documentation.
Interference, Noise, and Real-World Gotchas
Linear Hall sensors are notoriously susceptible to environmental noise if the hardware layout is ignored. When debugging erratic readings on the bench, check these three primary interference sources:
- Electromagnetic Interference (EMI): If your sensor is mounted near stepper motors, BLDC motors, or high-current switching relays, the alternating magnetic fields will induce massive spikes in the Hall die. Fix: Use a twisted-pair cable for the sensor leads, route them away from motor phase wires, and place a 100nF ceramic bypass capacitor directly across the VCC and GND pins as close to the sensor body as physically possible.
- Temperature Drift: The sensitivity and quiescent voltage of silicon Hall elements drift with temperature. The SS49E exhibits a quiescent voltage drift of roughly ±0.5% over a -40°C to 85°C range. Fix: For outdoor or automotive applications, implement a software auto-zero routine that recalibrates the
QUIESCENT_Vbaseline when the system is known to be at the mechanical hard-stop. - Magnetic Hysteresis and Ferrous Mounting: Mounting a Hall sensor directly to a steel chassis or using mild steel screws near the sensing face will distort the magnetic flux lines. The steel acts as a flux shunt, altering your calibration curve and introducing hysteresis (the reading differs depending on whether the magnet is approaching or retreating). Fix: Mount the sensor using non-magnetic hardware (brass, nylon, or 316 stainless steel) and keep ferrous metals at least 10mm away from the sensing axis. For more on magnetic material interactions, see the Honeywell Hall Effect Sensor Technical Guides.
Frequently Asked Questions
Can I use a digital hall effect sensor for linear position tracking?
No. Digital Hall sensors (often labeled as Hall switches or latches, like the US1881 or A3144) contain an internal Schmitt trigger. They only output a binary 0V or VCC signal when the magnetic field crosses a specific operate point (Bop) and release point (Brp). They cannot output intermediate values, making them useless for measuring continuous linear displacement. You must specifically source a 'linear' Hall sensor for position tracking.
Why is my ESP32 hall sensor reading fluctuating by 50+ ADC counts?
The ESP32's internal ADC is shared with the WiFi/Bluetooth radio and is inherently noisy, often exhibiting ±30 to ±50 counts of jitter on a stable DC voltage. Furthermore, the ESP32 ADC suffers from severe non-linearity at the extremes of its 0-3.3V range. To fix this, ensure your sensor's resting voltage is centered around 1.65V, implement the software EMA filter provided in the code above, or bypass the internal ADC entirely by using an external I2C ADC like the ADS1115, which offers 16-bit precision and hardware-level programmable gain.
How far away can the magnet be from a linear hall position sensor?
Because magnetic flux density from a dipole magnet drops off at a rate proportional to the inverse cube of the distance ($1/r^3$), the usable range is surprisingly short. For a standard 10mm x 3mm neodymium (N52) disc magnet and an SS49E sensor, you will see a highly usable, steep voltage gradient between 2mm and 12mm. Beyond 20mm, the magnetic field falls below the sensor's noise floor and Earth's ambient magnetic field begins to interfere. If you need a longer stroke, you must use a larger magnet array or a specialized flux concentrator, though this severely reduces millimeter-level resolution.






