If you are building a brushless motor controller, a DIY current meter, or a simple magnetic door alarm, you will inevitably encounter magnetic field sensing. But beyond the basic definition, what does a hall sensor do in a practical embedded system? It acts as a solid-state transducer, converting invisible magnetic flux lines into precise electrical signals that your microcontroller can read. However, treating all hall sensors as identical is a common mistake that leads to noisy data, blown logic pins, and failed projects.
The Hall Effect: Sensing Principle and Output Types
When a current-carrying semiconductor wafer inside the IC is placed in a magnetic field perpendicular to the current flow, the Lorentz force deflects the moving charge carriers. This deflection creates a measurable transverse voltage difference across the material, known as the Hall voltage. The magnitude of this voltage is directly proportional to the magnetic flux density (measured in Gauss or Tesla) passing through the sensor package, allowing the IC to quantify the strength and polarity of the magnetic field.
In practice, the sensor's internal circuitry dictates how that raw Hall voltage is delivered to your microcontroller. Linear (analog) sensors, like the ubiquitous SS49E or Texas Instruments DRV5053, output a continuous, ratiometric voltage proportional to the field strength, making them ideal for measuring distance, fluid levels, or DC current. Switch (digital) sensors, like the A3144, contain an internal Schmitt trigger and an open-drain transistor; they output a clean HIGH/LOW logic signal only when the field crosses a specific threshold, which is perfect for RPM counting, limit switches, and tachometers.
Hardware Specifications and Wiring Pinouts
Selecting the right IC requires matching the sensor's output type, supply voltage, and sensitivity to your microcontroller's logic levels and ADC capabilities. Below is a data-dense specification table for the four most common hall effect modules found in maker kits and industrial prototypes.
| IC Model | Output Type | Supply Range (VCC) | Quiescent Current | Sensitivity / Threshold | Best Use Case |
|---|---|---|---|---|---|
| SS49E | Analog Linear | 2.7V - 6.5V | ~6 mA | 1.4 mV/Gauss (at 5V) | Proximity, current sensing |
| DRV5053 | Analog Ratiometric | 2.5V - 5.5V | ~3.6 mA | 100 mV/mT (Variant dependent) | High-precision position |
| A3144 | Digital Unipolar Switch | 4.5V - 24V | ~5 mA | Operate: 300G / Release: 250G | RPM tach, speed limits |
| OH49E | Analog Linear | 3.0V - 6.5V | ~5 mA | 1.35 mV/Gauss (at 5V) | Budget linear replacement |
Standard 3-Pin Wiring Table
Most breakout boards standardize on a 3-pin header. When wiring to a 3.3V microcontroller like the ESP32 or Raspberry Pi Pico, pay strict attention to the VCC limits.
| Pin Label | Connection (Analog Module) | Connection (Digital A3144 Module) |
|---|---|---|
| VCC | 3.3V or 5V (Check IC datasheet) | 5V (A3144 requires min 4.5V) |
| GND | Microcontroller GND | Microcontroller GND |
| OUT / DO | ADC Pin (e.g., ESP32 GPIO 34) | GPIO Pin (Requires 10k pull-up if bare IC) |
Output Signal Math: Converting Raw ADC to Gauss
Reading an analog hall sensor is not as simple as calling analogRead(). You must map the raw ADC integer back to a physical voltage, and then apply the sensor's sensitivity curve to calculate the magnetic field in Gauss. Let's use the SS49E powered at 3.3V and read by an ESP32 (12-bit ADC, 0-4095 range) as our worked example.
The SS49E is ratiometric. At a nominal 5.0V supply, its null voltage (0 Gauss) is 2.5V, and its sensitivity is 1.4 mV/Gauss. When we drop the supply to 3.3V to match the ESP32's logic levels, the parameters scale linearly:
- Null Voltage ($V_{null}$): $3.3V / 2 = 1.65V$
- Sensitivity ($S$): $1.4 \text{ mV/G} \times (3.3 / 5.0) = 0.924 \text{ mV/G}$ (or $0.000924 \text{ V/G}$)
The Conversion Formula
First, convert the raw ADC reading to voltage:
$V_{out} = \text{ADC}_{raw} \times \left( \frac{3.3}{4095} \right)$
Next, calculate the magnetic field ($B$) in Gauss:
$B = \frac{V_{out} - V_{null}}{S}$
ESP32 C++ Implementation
Here is the exact, copy-pasteable code to implement this math. Notice that we use an oversampling loop to mitigate the ESP32's inherent ADC noise.
const int hallPin = 34; // ADC1_CH6, safe to use with WiFi
const float Vcc = 3.3;
const int adcMax = 4095;
const float V_null = Vcc / 2.0; // 1.65V
const float sensitivity = 0.000924; // Volts per Gauss at 3.3V
void setup() {
Serial.begin(115200);
analogReadResolution(12);
pinMode(hallPin, INPUT);
}
void loop() {
// Oversample 16 times to smooth out ESP32 ADC jitter
long sum = 0;
for(int i = 0; i < 16; i++) {
sum += analogRead(hallPin);
}
int adcRaw = sum / 16;
// Convert to Voltage
float vOut = adcRaw * (Vcc / adcMax);
// Convert to Gauss
float gauss = (vOut - V_null) / sensitivity;
Serial.print("Raw ADC: "); Serial.print(adcRaw);
Serial.print(" | Voltage: "); Serial.print(vOut, 3);
Serial.print("V | Field: "); Serial.print(gauss, 1);
Serial.println(" Gauss");
delay(250);
}
Calibration, Interference, and Real-World Gotchas
Even with perfect math, real-world physics will corrupt your readings if you ignore environmental factors. Hall effect ICs are notoriously susceptible to specific interference sources that rarely show up in basic tutorials.
Common Interference Sources
- Temperature Drift: The Hall element's sensitivity and offset voltage drift significantly with temperature. A bare SS49E can drift by 0.1% per °C. If your sensor is mounted near a hot voltage regulator or a motor, your zero-point will shift. Fix: Use ICs with integrated temperature compensation (like the DRV505x family) for precision work.
- Ferromagnetic Distortion: Mounting a linear hall sensor on a steel chassis, or even too close to the nickel-plating on some breadboards, will concentrate ambient magnetic flux lines and skew your baseline. Always mount precision sensors on FR4 (fiberglass) or plastic.
- AC Mains EMI: If you are using an analog hall sensor to measure AC current via a split-core transformer, the 50/60Hz electromagnetic interference from nearby wiring can induce millivolt-level noise on the sensor's output traces. Keep analog signal traces short and use a 100nF ceramic bypass capacitor directly across the VCC and GND pins of the sensor.
Calibration and the ESP32 ADC Non-Linearity
If you are using an ESP32, you must account for its ADC non-linearity. The ESP32's ADC is highly non-linear near 0V and 3.3V, and it suffers from a factory offset error. Because an analog hall sensor sits at mid-supply (1.65V) in a zero-field state, it naturally operates in the most linear region of the ESP32's ADC curve. However, you should still perform a software zero-offset calibration at startup.
V_null in software. This eliminates both the ESP32's ADC offset error and the specific IC's manufacturing tolerance in one step.
Understanding exactly what a hall sensor does—and more importantly, how its specific variant conditions the signal—bridges the gap between a noisy, unreliable prototype and a robust, production-ready embedded system. Always verify your supply voltage, respect the open-drain requirements of digital switches, and let oversampling handle the ADC noise.
References:
Texas Instruments DRV5053 Ratiometric Analog Hall Effect Sensor Datasheet & Product Page
SparkFun: Hall Effect Sensor Tutorial and Interfacing Guide
All About Circuits: Hall Effect Sensors (Semiconductors Vol 3, Ch 8)






