The Hall Sensor Working Principle

At the core of the hall sensor working principle is the Lorentz force. When an electrical current flows through a thin semiconductor material (such as Indium Antimonide or Gallium Arsenide) and a magnetic field is applied perpendicular to that current, the magnetic field exerts a force on the moving charge carriers. This force pushes electrons to one side of the semiconductor wafer, creating a measurable transverse voltage difference known as the Hall voltage. The strength of this voltage is directly proportional to the magnetic flux density passing through the material.

Because the raw Hall voltage is typically in the microvolt range, practical integrated circuits like the SS49E or A3144 embed this semiconductor element alongside a differential amplifier, a voltage regulator, and signal conditioning logic on a single silicon die. The internal amplifier boosts the microvolt signal to a usable 0.5V to 4.5V analog range, or feeds it into a Schmitt trigger to produce a clean digital logic transition, allowing these sensors to interface directly with modern 3.3V microcontrollers without external op-amps.

Analog vs. Digital: What the Output Actually Is

A common mistake in embedded projects is conflating linear (analog) and switch (digital) Hall sensors. They share the same underlying physics but output fundamentally different signals.

Rule of Thumb: If you need to measure how strong a magnetic field is or track continuous proximity, use an analog sensor. If you only need to know if a magnet is present (like a door switch or RPM counter), use a digital sensor.
  • Analog (Linear) Output: Sensors like the SS49E or A1302 output a continuous voltage. With no magnetic field present, the output sits at a quiescent 'null' voltage (typically Vcc/2). As a magnetic field increases, the voltage swings up or down proportionally. This requires an Analog-to-Digital Converter (ADC) on your microcontroller to read.
  • Digital (Switch/Latch) Output: Sensors like the A3144 output a discrete logic level. They feature an open-drain or push-pull transistor that pulls the output pin LOW when the magnetic field crosses a specific operate point (Bop). They incorporate built-in hysteresis, meaning the field must drop below a lower release point (Brp) for the pin to return HIGH, preventing mechanical chatter.

Wiring and Pinout Reference

Below is the hardware specification and wiring matrix for the most common through-hole Hall sensors used in maker projects. Note that digital open-collector outputs require a pull-up resistor to interface correctly with ESP32 GPIO pins.

Model Type Supply Range (Vcc) Output Stage ESP32 Wiring Notes
SS49E Analog Linear 2.7V - 6.5V Push-Pull (Voltage) Connect to ADC1 pins (GPIO 32-39). Do not use ADC2 if WiFi is active.
A1302 Analog Linear 3.0V - 5.5V Push-Pull (Voltage) Similar to SS49E but higher sensitivity. Requires stable 3.3V LDO.
A3144 Digital Switch 3.8V - 24V Open-Collector Requires 10kΩ pull-up to 3.3V. Note: Min Vcc is 3.8V; power Vcc with 5V, pull-up output to 3.3V.
SS41 Digital Latch 3.8V - 30V Open-Collector Turns on with South pole, off with North pole. Requires 10kΩ pull-up to 3.3V.

Raw-to-Unit Math: Converting ADC to Gauss

To turn raw ADC readings into physical units (Gauss or milliTesla), you must account for the sensor's ratiometric nature and the microcontroller's ADC resolution. The SS49E is ratiometric, meaning its null voltage and sensitivity scale linearly with the supply voltage.

Assuming we power the SS49E from the ESP32's 3.3V pin:

  1. Null Voltage: Vcc / 2 = 1.65V
  2. Sensitivity: The datasheet specifies 1.4 mV/Gauss at 5.0V. At 3.3V, sensitivity scales to: 1.4 * (3.3 / 5.0) = 0.924 mV/Gauss (or 0.000924 V/G).
  3. ESP32 ADC Scaling: With a 12-bit resolution (0-4095) and a 3.3V reference, each step represents roughly 0.8 mV.
Calibration Note: The ESP32's internal ADC is notoriously non-linear near the 0V and 3.3V rails. Fortunately, the SS49E's 1.65V quiescent point sits perfectly in the ADC's most linear region. Always use ADC_11db attenuation to map the full 0-3.3V range.

Here is the complete, copy-pasteable Arduino core code for the ESP32 to read the sensor, apply multisampling to reduce noise, and output the magnetic field in Gauss:

const int hallPin = 34; // GPIO 34 (ADC1_CH6)
const float Vcc = 3.3;
const float nullVoltage = Vcc / 2.0;
const float sensitivity = 0.000924; // Volts per Gauss at 3.3V
const int sampleSize = 64; // Multisampling to smooth ESP32 ADC noise

void setup() {
  Serial.begin(115200);
  analogReadResolution(12);
  analogSetAttenuation(ADC_11db);
}

void loop() {
  long sum = 0;
  for (int i = 0; i < sampleSize; i++) {
    sum += analogRead(hallPin);
  }
  float rawAvg = sum / (float)sampleSize;
  
  // Convert raw ADC to Voltage
  float voltage = (rawAvg / 4095.0) * Vcc;
  
  // Convert Voltage to Gauss
  float gauss = (voltage - nullVoltage) / sensitivity;
  
  // Convert Gauss to milliTesla (10 Gauss = 1 mT)
  float mT = gauss / 10.0;
  
  Serial.printf("Raw: %0.1f | Voltage: %0.3fV | Field: %0.2f Gauss (%0.2f mT)\n", rawAvg, voltage, gauss, mT);
  delay(250);
}

Common Interference Sources and Mitigation

Hall sensors are highly susceptible to environmental noise. If your readings are drifting or jittering, check these three interference vectors:

  • Electromagnetic Interference (EMI): Switching power supplies (buck converters) and PWM-driven motor controllers generate high-frequency magnetic fields that the sensor will pick up. Fix: Route sensor wires as a twisted pair, and solder a 0.1µF ceramic decoupling capacitor directly across the sensor's Vcc and GND pins on the perfboard.
  • Ferromagnetic Proximity: Mounting a Hall sensor near steel screws, iron breadboard plates, or nickel-plated headers will distort the ambient magnetic field, shifting your null voltage. Fix: Use brass or nylon hardware for mounting the sensor PCB.
  • Thermal Drift: While modern ICs have internal temperature compensation, extreme thermal gradients can still cause a 0.1% to 0.5% shift in the null voltage. Fix: For precision applications, implement a software baseline calibration at startup before the PCB heats up.

Frequently Asked Questions

How does temperature affect the hall sensor working principle?

The mobility of charge carriers in the semiconductor changes with temperature, which inherently alters the Hall voltage. However, almost all modern integrated Hall sensors (like the SS49E or A1302) include an on-chip thermistor network that dynamically adjusts the gain of the internal differential amplifier to compensate for this drift. While the physics of the raw element is highly temperature-dependent, the conditioned output of the IC remains stable across the -40°C to 150°C operating range.

Why is my analog hall sensor reading fluctuating wildly on the ESP32?

This is almost always caused by the ESP32's ADC noise floor combined with a lack of hardware decoupling. The ESP32's successive approximation register (SAR) ADC can exhibit ±50 LSB of noise on single reads. To fix this, you must do two things: first, place a 0.1µF ceramic capacitor as close to the sensor's Vcc/GND pins as physically possible; second, implement software multisampling (taking 32 to 64 rapid readings and averaging them) as demonstrated in the code block above.

Can I use a digital hall sensor to measure exact magnetic field strength?

No. Digital Hall sensors like the A3144 are designed purely as switches. They contain a Schmitt trigger that outputs a binary HIGH or LOW signal based on fixed internal thresholds (Bop and Brp). They cannot tell you if the magnetic field is 50 Gauss or 500 Gauss, only that it has crossed the activation threshold. To measure exact field strength, flux density, or continuous proximity, you must use a linear analog sensor and an ADC.