A linear hall-effect sensor outputs a ratiometric voltage proportional to magnetic flux density. To read it on an ESP32 or Arduino, you wire VCC to a stable supply (typically 3.3V or 5V), GND to ground, and the OUT pin to an ADC channel. You then apply a scaling formula to convert the raw 10-bit or 12-bit ADC reading into milliTesla (mT). This guide covers the exact wiring, the raw-to-unit math, and the calibration steps required to get reliable magnetic field measurements on the workbench.

The Hall-Effect Sensing Principle

When a current-carrying semiconductor is placed in a magnetic field perpendicular to the current flow, the Lorentz force deflects the charge carriers to one side of the material. This charge accumulation creates a measurable transverse voltage difference known as the Hall voltage. The magnitude of this voltage is directly proportional to the strength of the magnetic flux density passing through the material.

In modern integrated hall-effect sensors, this microvolt-level Hall voltage is amplified by an on-chip operational amplifier and temperature-compensated before reaching the output pin. The result is a robust, low-impedance signal that scales linearly with the magnetic field, allowing microcontrollers to easily measure everything from motor RPM to joystick displacement without physical contact.

Sensor Variants and Specification Matrix

The most common mistake when ordering these components is conflating linear (analog) sensors with digital (switch/latch) sensors. A digital hall sensor (like the US1881) only outputs a high or low logic signal when a magnetic threshold is crossed—useful for RPM counting but useless for measuring field strength. For proportional measurement, you must select a linear analog device.

Table 1: Common Hall-Effect Sensor Specifications
Part Number Architecture Supply Range (V) Output Type Quiescent Output Sensitivity
Allegro A1302 Linear Analog 4.5 - 6.0 Ratiometric Voltage VCC / 2 (2.5V at 5V) 1.3 mV/G (13 mV/mT)
Honeywell SS49E Linear Analog 2.7 - 6.5 Ratiometric Voltage VCC / 2 1.4 mV/G (at 5V VCC)
TI DRV5053 Linear Analog 2.5 - 38 Absolute Voltage 0.1V to 1.8V (varies) Specific to variant (e.g., 70 mV/mT)
Melexis US1881 Digital Latch 3.5 - 24 Open-Drain Digital Pull-up dependent N/A (Threshold: ±3mT)

Note that the SS49E and A1302 are ratiometric. This means their quiescent (zero-field) output voltage and their sensitivity scale proportionally with the supply voltage. The TI DRV5053, conversely, provides an absolute voltage output that remains fixed regardless of minor VCC ripples, which is advantageous in noisy automotive environments but requires a highly stable ADC reference voltage for accurate reading.

Wiring and Pinout for Microcontrollers

Below is the standard wiring matrix for interfacing a linear ratiometric sensor (like the SS49E) to both 5V and 3.3V microcontroller ecosystems. Because the ESP32 operates at 3.3V logic and its ADC maxes out at ~3.1V to 3.3V depending on attenuation, we power the SS49E directly from the 3.3V rail to avoid overvoltage on the GPIO pin.

Table 2: Wiring Pinout and Supply Mapping
Sensor Pin ESP32 DevKit Pin Arduino Uno Pin Implementation Notes
VCC (Pin 1) 3V3 5V SS49E supports 2.7V-6.5V. Use 3.3V for ESP32 to match ADC range.
GND (Pin 2) GND GND Must share a common ground plane with the microcontroller.
OUT (Pin 3) GPIO 34 (ADC1_CH6) A0 Add a 100nF ceramic decoupling capacitor from OUT to GND.
Bench Tip: The Decoupling Capacitor is Mandatory

Hall-effect sensors are highly susceptible to high-frequency noise on the supply rail, which couples directly into the output amplifier. Always place a 100nF (0.1µF) ceramic capacitor as physically close to the sensor's VCC and GND pins as possible. If you are running long wires (>15cm) to the sensor, add a 10µF electrolytic capacitor in parallel at the sensor base.

Output Signal Math: Raw ADC to MilliTesla (mT)

Converting the raw ADC integer into a physical magnetic flux density unit requires accounting for the ADC resolution, the reference voltage, and the sensor's ratiometric sensitivity. Let us calculate the exact math for an SS49E powered at 3.3V read by an ESP32 12-bit ADC.

1. Determine the Sensor Parameters at 3.3V

  • ADC Resolution: 12-bit (0 to 4095)
  • ADC Reference Voltage: 3.3V
  • Quiescent Output (0 mT): VCC / 2 = 1.65V
  • Sensitivity Scaling: The datasheet states 1.4 mV/G at 5.0V. Because it is ratiometric, at 3.3V the sensitivity is: 1.4 * (3.3 / 5.0) = 0.924 mV/G.
  • Unit Conversion: 1 Gauss (G) = 0.1 milliTesla (mT). Therefore, 0.924 mV/G = 9.24 mV/mT (or 0.00924 V/mT).

2. The Conversion Formula

First, convert the raw ADC reading to voltage:

Voltage = (ADC_Raw / 4095.0) * 3.3

Next, find the voltage delta from the quiescent zero-point:

Delta_V = Voltage - 1.65

Finally, divide by the sensitivity to get milliTesla:

B_mT = Delta_V / 0.00924

3. ESP32 C++ Implementation

// ESP32 Arduino Core Implementation
const int hallPin = 34;
const float vRef = 3.3;
const int adcMax = 4095;
const float quiescentV = 1.65;
const float sensitivity_V_mT = 0.00924; // 9.24 mV/mT converted to V/mT

float readMagneticField_mT() {
  // Read ADC and apply simple oversampling to reduce noise
  long sum = 0;
  for(int i = 0; i < 16; i++) {
    sum += analogRead(hallPin);
  }
  float adcAvg = sum / 16.0;
  
  // Convert to Voltage
  float voltage = (adcAvg / adcMax) * vRef;
  
  // Convert to milliTesla
  float deltaV = voltage - quiescentV;
  float bField_mT = deltaV / sensitivity_V_mT;
  
  return bField_mT;
}

Note on ESP32 ADC Non-Linearity: The ESP32 ADC is notoriously non-linear near the 0V and 3.3V rails. Fortunately, a ratiometric hall sensor sits at 1.65V in a zero-field state, which is exactly in the most linear sweet spot of the ESP32's ADC curve. This makes ratiometric sensors vastly superior to absolute sensors for 3.3V ESP32 deployments.

Calibration and Common Interference Sources

Even with perfect math, real-world physics will introduce errors if you do not calibrate the system and mitigate interference. Ratiometric sensors assume the quiescent voltage is exactly VCC/2, but manufacturing tolerances can shift this by ±10mV. Furthermore, the Hall effect itself is temperature-dependent, and while internal circuitry compensates for silicon drift, package stress can alter the baseline.

Software Calibration Routine

Never hardcode 1.65 as your zero-point in production firmware. Instead, implement a startup calibration sequence:

  1. Power on the system and wait 500ms for the sensor amplifier to stabilize.
  2. Ensure no external magnets are within 10cm of the sensor.
  3. Take 1,000 ADC samples and average them to establish the Zero_Offset_Raw.
  4. Store this offset in Non-Volatile Storage (NVS) or EEPROM so it persists across reboots.
  5. Subtract Zero_Offset_Raw from all subsequent readings before applying the voltage scaling.

Interference Sources and Mitigation

Table 3: Interference Sources and Hardware Fixes
Interference Type Symptom in Data Hardware / Layout Mitigation
AC Mains EMI (50/60Hz) Sinusoidal ripple on the baseline reading. Use twisted-pair wire for the sensor leads. Implement a software moving-average or low-pass IIR filter.
Mechanical Package Stress Zero-offset shifts when the PCB is bent or screwed down tightly. Mount the sensor on a rigid PCB. Avoid placing it near board mounting holes where screw torque induces piezo-resistive strain in the silicon.
Thermal Hysteresis Readings drift as the board heats up and fail to return to baseline when cooled. Keep the sensor away from onboard voltage regulators and power MOSFETs. Allow a 3-minute thermal soak time before executing the zero-offset calibration.
Ferromagnetic Proximity Reduced sensitivity or skewed directional response. Ensure no steel screws, iron-core inductors, or ground planes are directly beneath the sensor die. Keep a 5mm clearance from ferrous metals.

By combining the correct ratiometric power supply topology, a hardware decoupling capacitor, and a software-driven zero-offset calibration, you can reliably extract sub-milliTesla resolution from a $1.50 SS49E sensor using the ESP32's built-in ADC. For deeper architectural insights into magnetic sensing topologies, refer to the Espressif ADC Oneshot Driver Documentation to optimize your sampling window and attenuation settings.