The Physics: How a Hall Effect Magnetic Field Sensor Works

When an electrical current flows through a thin semiconductor material (like indium antimonide or gallium arsenide) and a magnetic field is applied perpendicular to that current, the Lorentz force deflects the moving charge carriers to one side of the material. This accumulation of charge creates a measurable transverse voltage known as the Hall voltage. The magnitude of this voltage is directly proportional to the strength of the perpendicular magnetic flux density.

Because the raw Hall voltage is typically in the microvolt range, practical integrated circuits embed this semiconductor die alongside an onboard differential amplifier and voltage regulator. The amplified output is then routed to a single pin, providing either a continuous analog voltage that scales linearly with the magnetic field, or a digital logic signal that snaps high or low when a specific magnetic threshold is crossed.

Analog vs. Digital: Understanding the Output Signal

A common mistake in embedded design is conflating the two primary output types of a hall effect magnetic field sensor. They serve entirely different use cases and require different microcontroller peripherals to read.

Linear (Analog) Output

An analog sensor outputs a continuous, ratiometric voltage. With no magnetic field present, the output sits at exactly half of the supply voltage (VCC/2). When a south pole approaches, the voltage increases toward VCC; when a north pole approaches, it decreases toward 0V. This output is read by a microcontroller's Analog-to-Digital Converter (ADC) to measure exact field strength, distance, or angular position.

Switch/Latch (Digital) Output

A digital sensor outputs a binary logic level (usually an open-drain transistor that requires an external pull-up resistor, or a push-pull output). It remains in one state until the magnetic field crosses a specific 'Operate Point' (Bop), at which it switches states. It will not revert until the field drops below a lower 'Release Point' (Brp). This built-in hysteresis prevents erratic toggling and is read via a standard digital GPIO pin or hardware interrupt for RPM counting or limit switching.

Wiring, Pinout, and Power Supply Requirements

Most through-hole and SMD hall effect sensors share a standard 3-pin footprint. Below is the wiring specification for interfacing a standard linear sensor (like the Honeywell SS49E) and a digital switch (like the Allegro A3144) to a 3.3V ESP32 DevKit.

Pin Function ESP32 Connection Supply Range & Notes
1 (VCC) Power Supply 3V3 Pin 2.7V to 6.5V. Do not exceed 6.5V or the internal regulator will overheat.
2 (GND) Ground GND Pin Common ground with the microcontroller. Keep leads short to reduce noise.
3 (OUT) Signal Output GPIO 34 (Analog) or GPIO 4 (Digital) Analog: Outputs 0.2V to 3.1V. Digital: Open-drain, requires 10kΩ pull-up to 3V3.
Bench Tip: The ESP32's ADC is notoriously non-linear near the 0V and 3.3V rails. When using an analog hall sensor on 3.3V, the quiescent output is 1.65V, and the linear range is roughly 0.2V to 3.1V. This naturally keeps your signal in the ESP32's 'sweet spot', but ensure your magnet isn't so strong that it drives the pin below 0.1V or above 3.2V, or your readings will saturate and distort.

The Math: Converting Raw ADC Readings to Gauss

To turn a raw ADC integer into a physical unit (Gauss or milliTesla), you must account for the microcontroller's ADC resolution and the sensor's ratiometric sensitivity.

The Honeywell SS49E datasheet specifies a typical sensitivity of 1.4 mV/Gauss when powered at 5.0V. Because the sensor is ratiometric, its sensitivity scales linearly with the supply voltage. If we power it from the ESP32's 3.3V rail, the adjusted sensitivity is:

Sensitivity_3V3 = 1.4 mV/G * (3.3V / 5.0V) = 0.924 mV/Gauss (or 0.000924 V/G).

The zero-point (no magnetic field) is VCC / 2, which equals 1.65V. The ESP32's 12-bit ADC yields values from 0 to 4095. The conversion formula is:

  1. Convert raw ADC to Voltage: V_out = (ADC_raw / 4095) * 3.3
  2. Subtract the zero-offset: V_delta = V_out - 1.65
  3. Divide by sensitivity: Gauss = V_delta / 0.000924

Here is the complete, copy-pasteable C++ implementation for the Arduino framework on an ESP32:

// ESP32 ADC to Gauss Conversion for SS49E Linear Hall Sensor
const int HALL_PIN = 34; // ADC1_CH6 (Safe to use with WiFi)
const float VCC = 3.3;
const float ADC_MAX = 4095.0;
const float SENSITIVITY_3V3 = 0.000924; // V/Gauss at 3.3V supply
const float ZERO_OFFSET = VCC / 2.0;

void setup() {
  Serial.begin(115200);
  analogReadResolution(12); // Set ESP32 ADC to 12-bit
  analogSetAttenuation(ADC_11db); // Allow full 0-3.3V range
}

void loop() {
  // Average 16 samples to reduce ESP32 ADC noise
  long sum = 0;
  for(int i = 0; i < 16; i++) {
    sum += analogRead(HALL_PIN);
  }
  int raw = sum / 16;
  
  float voltage = (raw / ADC_MAX) * VCC;
  float gauss = (voltage - ZERO_OFFSET) / SENSITIVITY_3V3;
  
  // 10 Gauss = 1 milliTesla (mT)
  float mT = gauss / 10.0; 
  
  Serial.printf("Raw: %04d | V: %.2f | Gauss: %6.1f | mT: %5.2f\n", raw, voltage, gauss, mT);
  delay(100);
}

Calibration, Interference, and Final Part Selection

Before deploying your code, you must address calibration and environmental interference. The theoretical VCC/2 zero-offset is rarely exact due to resistor tolerances inside the IC. Calibration step: On boot, before any magnet is near the sensor, read the analog pin 100 times, average the result, and store it as your dynamic ZERO_OFFSET variable.

Furthermore, hall sensors are susceptible to three main interference sources:

  • AC Electromagnetic Interference (EMI): Routing sensor wires parallel to 120V/240V AC mains will induce a 50/60Hz hum in the output. Use twisted-pair wiring and keep sensor leads under 2 meters.
  • Thermal Drift: Sensitivity shifts by roughly -0.1% per °C. For precision gauges, read an onboard thermistor or ESP32 internal temp sensor and apply a software compensation curve.
  • Mechanical Stress: Bending the leads of a through-hole package or applying pressure to the epoxy body induces a piezoresistive effect in the silicon die, shifting the zero-offset. Mount the sensor flat and avoid bending the pins flush against the plastic body.

Decision Path: Which Sensor Should You Buy?

Use this decision matrix to select the exact part number for your workbench. Do not default to generic 'Arduino sensor kits' which often ship unmarked, out-of-spec clones.

If your application requires... Then you need this Output Type... Concrete Part Pick (2026 Pricing)
Measuring exact field strength, fluid level, or distance to a magnet Linear Analog Honeywell SS49E (~$1.50 / ea)
Counting RPM on a motor shaft or acting as a proximity limit switch Digital Switch (Unipolar) Allegro A3144 (~$0.85 / ea)
Detecting direction (North vs South pole) or window/door open-close state Digital Latch (Bipolar) Allegro A3212 (~$0.90 / ea)

The Default Recommendation: If you are building a general-purpose magnetic field gauge, studying physics, or prototyping a custom joystick on an ESP32, buy the Honeywell SS49E. It natively supports 3.3V logic without level shifters, provides a highly linear output that maps perfectly to the ESP32's ADC sweet spot, and costs roughly $1.50 from authorized distributors like Mouser or Digi-Key. For further reading on magnetic position sensing topologies, refer to the Allegro Micro technical library.