The Physics: Hall Effect Sensor How It Works
When an electrical current flows through a semiconductor wafer (typically Indium Arsenide or Gallium Arsenide) and a magnetic field is applied perpendicular to that current, the Lorentz force deflects the moving charge carriers toward one edge of the material. This physical deflection creates a measurable transverse voltage difference across the semiconductor, known as the Hall voltage. The magnitude of this voltage is directly proportional to the strength of the perpendicular magnetic flux density passing through the device.
Because the semiconductor material is extremely thin and the internal charge carriers move at high velocities, even weak magnetic fields generate a detectable potential difference. Modern integrated Hall effect sensors amplify this microvolt-level Hall voltage internally using operational amplifiers, condition the signal, and output it in a format that microcontrollers can read directly. For a deeper look at the underlying semiconductor physics, All About Circuits provides an excellent breakdown of the Lorentz force interactions at the lattice level.
Analog vs. Digital: What the Output Actually Is
The most common mistake makers make is conflating analog (linear) and digital (switch) Hall effect sensors. They operate on the same physical principle but output entirely different signals.
Analog (Linear) Sensors
Parts like the SS49E or Texas Instruments DRV5055 output a continuous, ratiometric analog voltage. In the absence of a magnetic field, the output sits at exactly half of the supply voltage (VCC/2), known as the null voltage. As a North magnetic pole approaches, the voltage increases toward VCC; as a South pole approaches, it decreases toward GND. The output is strictly a voltage signal that requires an Analog-to-Digital Converter (ADC) to interpret.
Digital (Switch) Sensors
Parts like the A3144 (unipolar switch) or US5881 (bipolar latch) output a discrete logic level. Internally, they use a Schmitt trigger to provide hysteresis, preventing output chatter when hovering near the activation threshold. The output stage is typically an open-drain N-MOSFET. This means the sensor can only pull the output pin LOW (to GND) when a magnet is detected; it cannot drive the pin HIGH. You must provide an external or internal pull-up resistor to VCC to see a HIGH state when the magnet is absent.
Wiring Pinouts and Supply Ranges
Before wiring, verify your specific sensor's voltage tolerance. Feeding 5V into a 3.3V digital sensor will instantly destroy the internal regulator. Below is a reference table for common bench-stock Hall effect sensors.
| Part Number | Type | VCC Range | OUT Pin Behavior | Pull-Up Required? |
|---|---|---|---|---|
| SS49E | Analog Linear | 2.7V - 6.5V | Push-Pull Voltage (VCC/2 null) | No |
| DRV5055A1 | Analog Linear | 2.5V - 5.5V | Push-Pull Voltage (VCC/2 null) | No |
| A3144 | Digital Unipolar | 4.5V - 24V | Open-Drain (Active LOW) | Yes (10kΩ to VCC) |
| US5881 | Digital Bipolar Latch | 2.2V - 3.6V | Open-Drain (Active LOW) | Yes (10kΩ to VCC) |
Output Signal Math: Raw ADC to MilliTesla
To convert raw ADC readings into a physical unit like milliTesla (mT) or Gauss, you must account for the sensor's sensitivity and your microcontroller's ADC resolution. We will use the SS49E powered at 3.3V, read by an ESP32 12-bit ADC.
The Math Breakdown
- ADC Resolution: 12-bit (0 to 4095).
- Reference Voltage: 3.3V.
- Null Voltage: VCC / 2 = 1.65V.
- SS49E Sensitivity at 5V: 1.4 mV/Gauss (14 mV/mT).
- SS49E Sensitivity at 3.3V (Ratiometric): 14 mV/mT × (3.3 / 5.0) = 9.24 mV/mT (or 0.00924 V/mT).
The formula to derive the magnetic field in mT is:
- Convert raw ADC to Voltage:
V = raw * (3.3 / 4095.0) - Calculate Delta from Null:
Delta_V = V - 1.65 - Convert to mT:
mT = Delta_V / 0.00924
ESP32 Arduino C++ Implementation
#include <Arduino.h>
const int HALL_PIN = 34; // GPIO 34 (ADC1_CH6)
const int NUM_SAMPLES = 64; // Oversampling to reduce ESP32 ADC noise
const float VCC = 3.3;
const float ADC_MAX = 4095.0;
const float NULL_VOLTAGE = VCC / 2.0;
const float SENSITIVITY_V_MT = 0.00924; // 9.24 mV/mT at 3.3V
void setup() {
Serial.begin(115200);
analogReadResolution(12);
pinMode(HALL_PIN, INPUT);
}
void loop() {
long rawSum = 0;
for (int i = 0; i < NUM_SAMPLES; i++) {
rawSum += analogRead(HALL_PIN);
delayMicroseconds(100);
}
float rawAvg = rawSum / (float)NUM_SAMPLES;
float voltage = (rawAvg / ADC_MAX) * VCC;
float deltaV = voltage - NULL_VOLTAGE;
float magneticField_mT = deltaV / SENSITIVITY_V_MT;
float magneticField_Gauss = magneticField_mT * 10.0;
Serial.printf("Raw: %6.1f | V: %5.3f | mT: %6.2f | Gauss: %6.2f\n",
rawAvg, voltage, magneticField_mT, magneticField_Gauss);
delay(100);
}
Calibration and Interference Sources
The ESP32's internal ADC is notoriously non-linear and noisy, particularly near the 0V and 3.3V rails. If your readings fluctuate wildly, the Espressif ADC documentation recommends software oversampling (as shown in the code above) or using an external I2C ADC like the ADS1115 for precision work.
Beyond ADC noise, Hall sensors are susceptible to three main interference sources:
- Thermal Drift: The sensitivity of the SS49E drifts by roughly -0.06%/°C. If your ambient temperature swings by 20°C, expect a 1.2% shift in your mT reading. For high-precision tasks, use a sensor with integrated temperature compensation like the DRV5055.
- EMI from AC Mains: 50Hz or 60Hz alternating current in nearby power cables generates alternating magnetic fields. This induces a ripple on the sensor output. Keep sensor leads short and use twisted-pair wiring for the VCC and GND lines.
- Ferromagnetic Distortion: Steel breadboards, iron-core inductors, or even the metal shielding on a nearby USB cable will bend the magnetic flux lines, creating localized dead zones or artificial peaks. Keep the sensor at least 2 inches away from unshielded ferrous metals.
FAQ: Hall Effect Sensor Interfacing Questions
How does a hall effect sensor work to measure current without contact?
A Hall effect sensor measures current indirectly by detecting the magnetic field generated by the current flow, governed by Ampere's Law. When current passes through a wire, it creates a concentric magnetic field around the conductor. By placing a Hall sensor adjacent to the wire—or inside the air gap of a ferromagnetic toroidal core that wraps around the wire—the sensor reads the flux density. Because the magnetic field is directly proportional to the current, you can calculate the exact amperage using the Biot-Savart law, achieving complete galvanic isolation between the high-voltage load and your low-voltage microcontroller.
Why is my analog hall sensor output stuck at 0V or 3.3V on the ESP32?
If your analog sensor is pegged at the supply rails, you have likely exceeded the sensor's magnetic saturation limit. The SS49E has a linear range of roughly ±650 Gauss (±65 mT) when powered at 5V, and slightly less at 3.3V. If you place a strong neodymium magnet directly against the sensor face, the internal amplifier saturates and clips the output at the VCC or GND rail. Move the magnet further away to re-enter the linear transfer region. Additionally, verify you haven't accidentally wired a digital open-drain sensor (like the A3144) without a pull-up resistor, which would result in a floating or permanently low pin state.
What is the difference between a unipolar and bipolar hall effect switch?
A unipolar switch (e.g., A3144) activates only when exposed to one specific magnetic pole (usually the South pole) and deactivates when the magnet is removed. It ignores the North pole entirely. A bipolar latch (e.g., US5881) requires alternating poles to toggle states: a South pole turns the output ON, and the output remains ON even after the magnet is removed. It will only turn OFF when a North pole is applied. Bipolar latches are ideal for BLDC motor commutation and rotary encoders, while unipolar switches are better for simple proximity detection and limit switches.






