When pairing a hall effect sensor with a magnet for microcontroller projects, the physical air gap and magnet grade dictate your signal-to-noise ratio. For linear position or current sensing, use a ratiometric linear sensor like the Honeywell SS49E or TI DRV5053; for simple RPM counting or limit switching, use a digital latch like the DRV5013. The most common beginner mistake is treating these two distinct output types as interchangeable, which leads to fried ADC pins or useless digital bouncing.

The Sensing Principle: How Hall Effect Sensors Read Magnets

When a control current flows through a thin semiconductor plate and a magnetic field from your magnet passes perpendicular to it, the Lorentz force deflects the moving charge carriers to one side of the plate. This accumulation of charge creates a measurable transverse voltage difference across the material, known as the Hall voltage. The polarity of this voltage flips depending on whether the north or south pole of the magnet is facing the active silicon area.

In practical sensor modules, internal operational amplifiers boost this microvolt-level Hall voltage into a usable macro-scale signal. The strength of the output depends entirely on the magnetic flux density (measured in Gauss or milliTesla) intersecting the active area. Because magnetic field strength drops off roughly with the cube of the distance from the magnet face, maintaining a tight, consistent mechanical air gap between the sensor and the neodymium magnet is critical for repeatable readings.

Component Selection: Linear vs. Digital Hall Sensors

Before wiring anything, you must select the correct sensor topology for your application. Linear sensors output a continuous analog voltage proportional to the magnetic field strength, while digital sensors output a clean logic HIGH or LOW based on internal hysteresis thresholds.

Table 1: Hall Effect Sensor Comparison for Microcontroller Interfacing
Part Number Output Type Supply Range (V) Sensitivity / Trip Point Typical Price (2026)
Honeywell SS49E Linear (Analog) 2.7V to 6.5V 1.4 mV/Gauss (at 5V) $0.85
Allegro A1302 Linear (Analog) 4.5V to 6.0V 1.3 mV/Gauss (at 5V) $1.10
TI DRV5053 Linear (Analog) 2.5V to 38V 100 mV/mT (Unipolar) $0.65
TI DRV5013 Digital (Latch) 2.5V to 5.5V ±3 mT (Bop/Brp) $0.45

What the output actually is: A linear sensor's output is a physical voltage (typically 0.5V to 4.5V) that you must read with an Analog-to-Digital Converter (ADC). A digital sensor's output is an open-drain or push-pull logic pin that sinks to GND or pulls to VCC, meant to be read via a standard GPIO pin or hardware interrupt.

Wiring Guide and Pinout for ESP32 and Arduino

Wiring a 3-pin hall effect sensor is straightforward, but you must match the sensor's supply range to your microcontroller's logic level to avoid clipping the analog signal or failing to trigger digital thresholds.

Table 2: Standard 3-Pin Hall Sensor Wiring Matrix
Sensor Pin Function Arduino Uno (5V Logic) ESP32 DevKit (3.3V Logic)
VCC (Pin 1) Power Supply 5V Pin 3V3 Pin
GND (Pin 2) Ground Reference GND GND
OUT (Pin 3) Signal Output Analog Pin (e.g., A0) ADC Pin (e.g., GPIO 34)
Callout Tip: ESP32 ADC Pin Selection
When using an ESP32, do not use GPIO 35, 36, or 39 for high-precision analog hall sensor reads without external pull-ups, as these pins lack internal pull-up resistors and can float if the sensor output is high-impedance. GPIO 32, 33, or 34 are generally more stable for raw analog reads. Furthermore, never feed a 5V linear sensor output directly into an ESP32 GPIO; use a voltage divider (e.g., 10kΩ and 22kΩ) to scale the 0-5V signal down to 0-3.3V.

Output Signal Math: Converting Raw ADC to Gauss

Reading the raw ADC value is useless for physical measurements. You must convert the microcontroller's integer reading into a voltage, and then use the sensor's sensitivity to calculate the magnetic flux density in Gauss (1 milliTesla = 10 Gauss).

Step 1: Raw ADC to Voltage

For an Arduino Uno (10-bit ADC, 5.0V reference):
V_out = (ADC_Reading / 1023.0) * 5.0

For an ESP32 (12-bit ADC, 3.3V reference):
V_out = (ADC_Reading / 4095.0) * 3.3
Note: The ESP32 ADC is notoriously non-linear below 0.15V and above 3.15V. Keep your sensor's output voltage within the 0.2V to 3.0V window for accurate math.

Step 2: Voltage to Gauss (The Physical Unit Math)

The formula to find the magnetic field (B) is:
B (Gauss) = (V_out - V_zero) / Sensitivity

Worked Example (Honeywell SS49E on Arduino Uno at 5V):
According to the Honeywell SS49E datasheet, at a 5V supply, the zero-gauss quiescent voltage (V_zero) is exactly half of VCC (2.5V), and the sensitivity is 1.4 mV/Gauss (0.0014 V/G).

  • Your Arduino ADC reads 614.
  • Calculate Voltage: V_out = (614 / 1023.0) * 5.0 = 3.00V
  • Calculate Delta: 3.00V - 2.50V (V_zero) = +0.50V
  • Calculate Gauss: 0.50V / 0.0014 V/G = 357 Gauss

Critical 3.3V Scaling Gotcha: If you power that same SS49E at 3.3V for an ESP32, the sensitivity scales linearly with the supply voltage. The new sensitivity becomes 1.4 * (3.3 / 5.0) = 0.924 mV/G, and your new V_zero becomes 1.65V. Failing to adjust the sensitivity multiplier in your code when dropping to 3.3V will result in magnetic field readings that are off by roughly 50%.

Calibration, Interference, and Real-World Gotchas

Theoretical math assumes a perfect environment. In practice, hall effect sensors are highly susceptible to environmental noise, and proper signal conditioning is mandatory for reliable operation.

Zero-Offset Calibration

Never hardcode the V_zero value in your firmware. Manufacturing tolerances mean the quiescent output can vary by ±10mV or more between individual sensors. Instead, implement a software calibration routine: upon boot, read the ADC 50 times with the magnet removed, average the results to establish your baseline V_zero, and subtract this baseline from all subsequent live readings.

Common Interference Sources

  1. Electromagnetic Interference (EMI): If you are using the hall sensor to measure current or track a brushless DC motor, the high-frequency switching noise from the motor controller will induce voltage spikes in the sensor's output leads. Always use twisted-pair wire for the analog output and ground, and add a 0.1μF ceramic bypass capacitor directly across the sensor's VCC and GND pins.
  2. Magnetic Hysteresis in Chassis: If you mount the sensor near a steel enclosure or iron core, the steel will concentrate and distort the magnetic field lines from your magnet. The field will not collapse immediately when the magnet is removed, causing a ghost reading. Mount the sensor on a non-magnetic spacer (like nylon or ABS plastic) at least 10mm away from ferrous metals.
  3. Temperature Drift: Hall elements are inherently temperature-sensitive. The SS49E has a sensitivity temperature coefficient of roughly -0.04%/°C. If your project operates in an unconditioned garage or outdoors where temperatures swing from 10°C to 40°C, expect your Gauss readings to drift by 1-2%. For high-precision applications, use a sensor with integrated temperature compensation like the TI DRV5053, or log the temperature via an onboard thermistor and apply a software correction curve.

By selecting the correct topology, scaling your math to the actual supply voltage, and filtering out environmental EMI, you can achieve sub-millimeter position resolution or highly accurate RPM tracking using a simple hall effect sensor and a neodymium magnet.