A Hall sensor exploits the Lorentz force: when a current-carrying semiconductor is placed in a magnetic field, charge carriers are deflected to one side of the material, creating a measurable transverse voltage (the Hall voltage). This voltage is strictly proportional to the magnetic flux density passing perpendicularly through the silicon die. In modern integrated circuits, this microvolt-level Hall voltage is immediately amplified and temperature-compensated on-chip before it ever reaches the output pin.
It is critical to separate the two main families of these sensors before wiring them to a microcontroller. Digital Hall switches (like the A3144) feature an internal Schmitt trigger and output a simple 0V or VCC logic level when a magnetic threshold is crossed—ideal for RPM counting or limit switches. Analog linear Hall sensors (like the SS49E or DRV5055) output a continuous voltage that scales proportionally with the magnetic field strength, allowing you to measure exact distance, fluid level, or current. This guide focuses entirely on interfacing analog linear sensors with the ESP32, as they require precise mathematical scaling and careful ADC management.
Selecting the Right Hall Sensor for Embedded Projects
Not all Hall sensors are created equal. Choosing the wrong part number for a 3.3V microcontroller like the ESP32 will result in clipped readings or destroyed silicon. Below is a data-dense comparison of the most common sensors found in maker labs and industrial prototypes in 2026.
| Part Number | Type | Supply Range (VCC) | Sensitivity / Threshold | Output Stage | Approx. Price (1pc) |
|---|---|---|---|---|---|
| SS49E (Honeywell) | Analog Linear | 2.7V to 6.5V | 1.4 mV/Gauss (at 5V) | Ratiometric Analog | $0.85 |
| DRV5055 (TI) | Analog Linear | 2.5V to 5.5V | 13.3 mV/mT (A2 variant) | Absolute Analog | $1.20 |
| A3144 (Allegro) | Digital Switch | 4.5V to 24V | 3.5 mT (Turn-on) | Open-Drain Digital | $0.25 |
| MLX90393 (Melexis) | 3-Axis Digital | 2.2V to 3.6V | 0.157 µT/LSB (16-bit) | I2C / SPI Digital | $4.50 |
Wiring and Pinout for Analog Linear Sensors
For this build, we will use the ubiquitous SS49E paired with an ESP32 DevKit V1. The SS49E comes in a standard TO-92 package. When looking at the flat face of the sensor with the leads pointing down, the pins from left to right are VCC, GND, and OUT.
| SS49E Pin | Function | ESP32 Connection | Notes & Constraints |
|---|---|---|---|
| 1 (Left) | VCC (Supply) | 3V3 Pin | Must be clean 3.3V. Do not use 5V, or the output will exceed the ESP32's 3.3V ADC maximum and risk damaging the GPIO. |
| 2 (Middle) | GND | GND Pin | Keep the ground return path short to avoid motor-induced ground bounce. |
| 3 (Right) | OUT (Signal) | GPIO 34 (ADC1_CH6) | Use an ADC1 pin. ADC2 pins conflict with the ESP32's WiFi radio and will drop readings when transmitting. |
According to the Espressif ESP32 ADC documentation, the internal 12-bit ADC is notoriously non-linear at the extreme ends of its range. Readings below 0.1V and above 3.1V are highly inaccurate. Because the SS49E outputs a quiescent (zero-gauss) voltage of exactly VCC/2 (1.65V when powered by 3.3V), the signal is perfectly centered in the ESP32's linear 'sweet spot', provided your magnetic field doesn't force the output past the 3.1V ceiling.
Output Signal Math: Raw ADC to MilliTesla
The raw output of an analog Hall sensor is a voltage. To turn this into a physical unit like Gauss or milliTesla (mT), we must apply the sensor's sensitivity and quiescent offset. The Texas Instruments Hall Effect primer outlines the standard transfer function for linear sensors:
V_out = V_quiescent + (Sensitivity × B)
Rearranging to solve for the magnetic flux density (B):
B = (V_out - V_quiescent) / Sensitivity
The Ratiometric Catch: The SS49E datasheet specifies a nominal sensitivity of 1.4 mV/Gauss (or 14 mV/mT) at 5.0V. Because we are powering it at 3.3V, the sensitivity scales down proportionally:
Sensitivity_3.3V = 14 mV/mT × (3.3V / 5.0V) = 9.24 mV/mT (or 0.00924 V/mT).
Here is the complete, copy-pasteable ESP32 Arduino code to sample the sensor, apply the math, and filter out high-frequency EMI using a simple exponential moving average (EMA).
const int HALL_PIN = 34; // ADC1_CH6
const float V_REF = 3.3; // ESP32 ADC reference voltage
const float ADC_MAX = 4095.0; // 12-bit resolution
const float V_QUIESCENT = 1.65; // VCC / 2
const float SENSITIVITY = 0.00924; // Volts per mT (scaled for 3.3V)
const float EMA_ALPHA = 0.1; // Filter weight (lower = smoother/slower)
float filteredB = 0.0;
void setup() {
Serial.begin(115200);
analogReadResolution(12);
// Prime the filter with an initial reading
int raw = analogRead(HALL_PIN);
float vOut = (raw / ADC_MAX) * V_REF;
filteredB = (vOut - V_QUIESCENT) / SENSITIVITY;
}
void loop() {
int raw = analogRead(HALL_PIN);
float vOut = (raw / ADC_MAX) * V_REF;
// Calculate magnetic field in milliTesla
float currentB = (vOut - V_QUIESCENT) / SENSITIVITY;
// Apply Exponential Moving Average to kill PWM/EMI noise
filteredB = (EMA_ALPHA * currentB) + ((1.0 - EMA_ALPHA) * filteredB);
Serial.print("Raw ADC: ");
Serial.print(raw);
Serial.print(" | Voltage: ");
Serial.print(vOut, 3);
Serial.print(" V | Field: ");
Serial.print(filteredB, 2);
Serial.println(" mT");
delay(50); // 20Hz sample rate
}
Calibration, Interference, and Edge Cases
Getting the math right is only half the battle. In real-world bench and jobsite environments, Hall sensors are highly susceptible to environmental factors that will ruin your readings if ignored.
1. Temperature Drift and Zero-Gauss Calibration
The silicon in a Hall sensor exhibits temperature-dependent offset drift. The SS49E has a typical offset drift of 0.06%/°C. If your sensor sits near a hot BLDC motor or a power resistor, the V_quiescent will shift away from 1.65V, causing a false 'ghost' magnetic reading. The fix: Implement a software tare function. On boot (or via a pushbutton), measure the sensor output with no magnets present, average 100 samples, and store that value as your dynamic V_QUIESCENT instead of hardcoding 1.65V.
2. Electromagnetic Interference (EMI) from Motors
If you are using this sensor to measure current on a motor driver or track a magnet on a spinning rotor, the high dV/dt switching of MOSFETs will capacitively couple noise into the high-impedance analog output trace.
- Hardware fix: Place a 10nF to 100nF ceramic capacitor directly between the OUT and GND pins of the sensor, as close to the TO-92 package as physically possible.
- Software fix: Use the EMA filter provided in the code above, or oversample the ADC 16 times and bit-shift right by 2 to achieve a cleaner 14-bit effective resolution.
3. Mechanical Stress (The Piezoresistive Effect)
This is the most common beginner mistake. The silicon die inside the TO-92 package is subject to the piezoresistive effect—meaning physical bending stress on the epoxy package alters the electrical resistance of the Hall element, shifting the zero-gauss offset. If you bend the leads of the SS49E flush against the plastic body to fit it into a tight 3D-printed enclosure, you will permanently offset your baseline. Always bend the leads at least 2mm below the package body, or better yet, use a surface-mount (SOT-23) variant like the DRV5055 if space is constrained.






