How Linear Hall Effect Sensors Actually Work
Unlike digital Hall switches that simply snap HIGH or LOW when a magnetic threshold is crossed, linear hall effect sensors output a continuous, ratiometric analog voltage directly proportional to the magnetic flux density (measured in Gauss or milliTesla) passing through the semiconductor die. When a magnetic field is applied perpendicular to the sensor element, the Lorentz force deflects charge carriers, generating a transverse Hall voltage. This raw micro-voltage is amplified by an internal op-amp and presented on the output pin.
The critical distinction for embedded engineers is the ratiometric nature of the output. The zero-field offset (the voltage output when no magnet is present) is typically exactly half of the supply voltage (Vcc/2). If you power the sensor at 5.0V, the zero-field output is 2.5V. If you drop the supply to 3.3V, the zero-field output drops to 1.65V. Both the offset and the sensitivity (mV per Gauss) scale linearly with the supply voltage, a quirk that dictates how we must wire and scale these sensors for modern 3.3V microcontrollers. For a deeper look at the underlying physics of the Hall effect in semiconductors, All About Circuits provides an excellent technical breakdown.
Component Selection and Datasheet Specs
Not all linear Hall sensors are created equal. While hobbyist modules are common, bare ICs offer better thermal stability and lower noise. Below is a spec-sheet comparison of the most common linear hall effect sensors used in embedded prototyping and production.
| Part Number | Type / Package | Supply Range | Sensitivity (Typ) | Zero-Field Offset | Est. Price (1pc) |
|---|---|---|---|---|---|
| Honeywell SS49E | Bare IC / SOT-89 | 2.7V to 6.5V | 1.4 mV/Gauss (at 5V) | Vcc / 2 | $0.65 |
| TI DRV5055A4 | Bare IC / SOT-23 | 2.5V to 5.5V | 30 mV/mT (at 3.3V) | Vcc / 2 | $0.45 |
| Melexis MLX90242 | Programmable / TO-92 | 3.0V to 15V | Programmable | Programmable | $1.20 |
| Generic KY-024 | PCB Module / 4-pin | 3.3V to 5.0V | Pot-adjusted | Pot-adjusted | $1.50 |
ESP32 Wiring and Pin Mapping
Wiring a 5V-rated Hall sensor to a 3.3V ESP32 is a common trap. If you power an SS49E at 5V, its output can swing up to 4.5V under a strong magnetic field. The ESP32’s ADC will saturate around 3.1V to 3.3V, meaning you will lose the top 30% of your measurement range and risk back-feeding voltage into the GPIO pin through internal ESD diodes. Always power linear Hall sensors at 3.3V when interfacing with an ESP32.
| SS49E Pin | Function | ESP32 DevKit Connection | Notes |
|---|---|---|---|
| Pin 1 (Left) | Vcc (Supply) | 3V3 | Keep supply clean; add 100nF decoupling cap at pins. |
| Pin 2 (Middle) | GND | GND | Share a common star-ground with the ESP32. |
| Pin 3 (Right) | Vout (Analog) | GPIO 34 (ADC1_CH6) | Must use ADC1. ADC2 is disabled when WiFi is active. |
Notice the explicit use of GPIO 34. The ESP32 has two internal ADCs. ADC2 shares hardware resources with the WiFi radio; as soon as you call WiFi.begin(), ADC2 pins become unusable for analog reads. Always route analog sensor outputs to ADC1 pins (GPIO 32, 33, 34, 35, 36, 39) for embedded IoT applications. Consult the Espressif ESP32 ADC API documentation for the full pin matrix and attenuation settings.
Converting ADC Raw Values to Gauss or MilliTesla
The raw 12-bit integer (0-4095) returned by analogRead() is useless on its own. We must convert it to a voltage, subtract the zero-field offset, and divide by the sensitivity. Because the ESP32 ADC is notoriously non-linear at the extremes of its range, use the analogReadMilliVolts() function (available in ESP32 Arduino Core v2.0.0+), which applies factory eFuse calibration data to return a highly accurate millivolt reading.
The Raw-to-Unit Math
Let’s calculate the constants for a Honeywell SS49E powered at exactly 3.3V:
- Zero-Field Offset (V_offset): 3.3V / 2 = 1.65V (1650 mV).
- Sensitivity Scaling: The datasheet specifies 1.4 mV/Gauss at 5.0V. Because the sensor is ratiometric, at 3.3V the sensitivity is:
1.4 * (3.3 / 5.0) = 0.924 mV/Gauss.
The formula to find the magnetic field (B) in Gauss is:
B (Gauss) = (V_out_mV - 1650) / 0.924
Note: 1 milliTesla (mT) = 10 Gauss. To get mT, divide the final result by 10.
Complete ESP32 Arduino Code
const int hallPin = 34; // ADC1 pin
const float vcc = 3300.0; // 3.3V supply in millivolts
const float offset_mv = vcc / 2.0; // 1650 mV
const float sensitivity = 1.4 * (vcc / 5000.0); // 0.924 mV/Gauss
void setup() {
Serial.begin(115200);
analogReadResolution(12); // Ensure 12-bit resolution (0-4095)
analogSetPinAttenuation(hallPin, ADC_11db); // Full range ~0-3.1V
}
void loop() {
// Read calibrated voltage directly in millivolts
int v_out_mv = analogReadMilliVolts(hallPin);
// Apply math to get Gauss
float gauss = (v_out_mv - offset_mv) / sensitivity;
// Convert to milliTesla (1 mT = 10 Gauss)
float milliTesla = gauss / 10.0;
Serial.printf("V: %d mV | Field: %+.2f Gauss | %+.3f mT\n",
v_out_mv, gauss, milliTesla);
delay(100); // 10Hz sample rate
}
Calibration, Drift, and Magnetic Interference
Getting the math right is only half the battle. Linear hall effect sensors are highly susceptible to environmental noise, and failing to account for interference will result in jittery, unusable data on your workbench.
1. Software Zero-Calibration
Never hardcode the 1650 mV offset in a production deployment. Resistor tolerances in the ESP32’s voltage divider and slight variations in the 3.3V LDO regulator mean your actual Vcc might be 3.28V or 3.32V. Implement a startup calibration routine: power the system on with no magnets nearby, take 100 ADC readings, average them, and store that value as your dynamic offset_mv in RAM or EEPROM.
2. Common Interference Sources
Hall sensors measure all magnetic fields, not just the permanent magnet you are trying to track. Common bench and jobsite interference sources include:
- AC Mains Wiring: 50/60Hz alternating current in nearby wall wiring or power strips induces a 50/60Hz ripple on the sensor output. Fix this with a software low-pass filter (e.g., a simple exponential moving average) or a hardware RC low-pass filter (1kΩ resistor + 100nF capacitor) on the analog output pin.
- Brushed DC Motors and Solenoids: PWM motor controllers generate massive high-frequency magnetic switching noise. Keep linear Hall sensors at least 5cm away from motor housings and route sensor signal wires perpendicular to motor power wires.
- Ferrous Metals: Mounting your sensor on a steel chassis or breadboard will distort the magnetic field lines (flux shunting), reducing the effective sensitivity and introducing hysteresis. Always mount Hall sensors on non-magnetic materials like FR4 fiberglass, plastic, or aluminum.
3. Temperature Drift
The internal semiconductor and op-amp drift with temperature. For the SS49E, the zero-field offset drifts at roughly -0.05% per °C. In a 40°C ambient temperature swing (e.g., an automotive or outdoor enclosure), your zero-point will shift by about 15-20 mV, translating to a false reading of ~20 Gauss. If you are building a high-precision gaussmeter, you must add a thermistor to the PCB and apply a temperature compensation matrix in your firmware to subtract the thermal drift.






